1 BB_DEFAULT_TASK ?= "build"
3 # like os.path.join but doesn't treat absolute RHS specially
4 def base_path_join(a, *p):
7 if path == '' or path.endswith('/'):
13 def base_path_relative(src, dest):
14 """ Return a relative path from src to dest.
16 >>> base_path_relative("/usr/bin", "/tmp/foo/bar")
19 >>> base_path_relative("/usr/bin", "/usr/lib")
22 >>> base_path_relative("/tmp", "/tmp/foo/bar")
25 from os.path import sep, pardir, normpath, commonprefix
27 destlist = normpath(dest).split(sep)
28 srclist = normpath(src).split(sep)
30 # Find common section of the path
31 common = commonprefix([destlist, srclist])
32 commonlen = len(common)
34 # Climb back to the point where they differentiate
35 relpath = [ pardir ] * (len(srclist) - commonlen)
36 if commonlen < len(destlist):
37 # Add remaining portion
38 relpath += destlist[commonlen:]
40 return sep.join(relpath)
42 def base_path_out(path, d):
43 """ Prepare a path for display to the user. """
44 rel = base_path_relative(d.getVar("TOPDIR", 1), path)
45 if len(rel) > len(path):
50 # for MD5/SHA handling
51 def base_chk_load_parser(config_paths):
52 import ConfigParser, os, bb
53 parser = ConfigParser.ConfigParser()
54 if len(parser.read(config_paths)) < 1:
55 raise ValueError("no ini files could be found")
59 def base_chk_file(parser, pn, pv, src_uri, localpath, data):
62 # Try PN-PV-SRC_URI first and then try PN-SRC_URI
63 # we rely on the get method to create errors
64 pn_pv_src = "%s-%s-%s" % (pn,pv,src_uri)
65 pn_src = "%s-%s" % (pn,src_uri)
66 if parser.has_section(pn_pv_src):
67 md5 = parser.get(pn_pv_src, "md5")
68 sha256 = parser.get(pn_pv_src, "sha256")
69 elif parser.has_section(pn_src):
70 md5 = parser.get(pn_src, "md5")
71 sha256 = parser.get(pn_src, "sha256")
72 elif parser.has_section(src_uri):
73 md5 = parser.get(src_uri, "md5")
74 sha256 = parser.get(src_uri, "sha256")
78 # md5 and sha256 should be valid now
79 if not os.path.exists(localpath):
80 localpath = base_path_out(localpath, data)
81 bb.note("The localpath does not exist '%s'" % localpath)
82 raise Exception("The path does not exist '%s'" % localpath)
85 # call md5(sum) and shasum
87 md5pipe = os.popen('md5sum ' + localpath)
88 md5data = (md5pipe.readline().split() or [ "" ])[0]
91 raise Exception("Executing md5sum failed")
94 shapipe = os.popen('PATH=%s oe_sha256sum %s' % (bb.data.getVar('PATH', data, True), localpath))
95 shadata = (shapipe.readline().split() or [ "" ])[0]
98 raise Exception("Executing shasum failed")
100 if no_checksum == True: # we do not have conf/checksums.ini entry
102 file = open("%s/checksums.ini" % bb.data.getVar("TMPDIR", data, 1), "a")
107 raise Exception("Creating checksums.ini failed")
109 file.write("[%s]\nmd5=%s\nsha256=%s\n\n" % (src_uri, md5data, shadata))
111 if not bb.data.getVar("OE_STRICT_CHECKSUMS",data, True):
112 bb.note("This package has no entry in checksums.ini, please add one")
113 bb.note("\n[%s]\nmd5=%s\nsha256=%s" % (src_uri, md5data, shadata))
116 bb.note("Missing checksum")
119 if not md5 == md5data:
120 bb.note("The MD5Sums did not match. Wanted: '%s' and Got: '%s'" % (md5,md5data))
121 raise Exception("MD5 Sums do not match. Wanted: '%s' Got: '%s'" % (md5, md5data))
123 if not sha256 == shadata:
124 bb.note("The SHA256 Sums do not match. Wanted: '%s' Got: '%s'" % (sha256,shadata))
125 raise Exception("SHA256 Sums do not match. Wanted: '%s' Got: '%s'" % (sha256, shadata))
130 def base_dep_prepend(d):
133 # Ideally this will check a flag so we will operate properly in
134 # the case where host == build == target, for now we don't work in
137 deps = "shasum-native coreutils-native"
138 if bb.data.getVar('PN', d, True) == "shasum-native" or bb.data.getVar('PN', d, True) == "stagemanager-native":
140 if bb.data.getVar('PN', d, True) == "coreutils-native":
141 deps = "shasum-native"
143 # INHIBIT_DEFAULT_DEPS doesn't apply to the patch command. Whether or not
144 # we need that built is the responsibility of the patch function / class, not
146 if not bb.data.getVar('INHIBIT_DEFAULT_DEPS', d):
147 if (bb.data.getVar('HOST_SYS', d, 1) !=
148 bb.data.getVar('BUILD_SYS', d, 1)):
149 deps += " virtual/${TARGET_PREFIX}gcc virtual/libc "
152 def base_read_file(filename):
155 f = file( filename, "r" )
156 except IOError, reason:
157 return "" # WARNING: can't raise an error now because of the new RDEPENDS handling. This is a bit ugly. :M:
159 return f.read().strip()
162 def base_conditional(variable, checkvalue, truevalue, falsevalue, d):
164 if bb.data.getVar(variable,d,1) == checkvalue:
169 def base_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
171 if float(bb.data.getVar(variable,d,1)) <= float(checkvalue):
176 def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
178 result = bb.vercmp(bb.data.getVar(variable,d,True), checkvalue)
184 def base_contains(variable, checkvalues, truevalue, falsevalue, d):
187 if type(checkvalues).__name__ == "str":
188 checkvalues = [checkvalues]
189 for value in checkvalues:
190 if bb.data.getVar(variable,d,1).find(value) != -1:
191 matches = matches + 1
192 if matches == len(checkvalues):
196 def base_both_contain(variable1, variable2, checkvalue, d):
198 if bb.data.getVar(variable1,d,1).find(checkvalue) != -1 and bb.data.getVar(variable2,d,1).find(checkvalue) != -1:
203 DEPENDS_prepend="${@base_dep_prepend(d)} "
205 # Returns PN with various suffixes removed
206 # or PN if no matching suffix was found.
207 def base_package_name(d):
210 pn = bb.data.getVar('PN', d, 1)
211 if pn.endswith("-native"):
213 elif pn.endswith("-cross"):
215 elif pn.endswith("-initial"):
217 elif pn.endswith("-intermediate"):
219 elif pn.endswith("-sdk"):
225 def base_set_filespath(path, d):
227 bb.note("base_set_filespath usage is deprecated, %s should be fixed" % d.getVar("P", 1))
229 # The ":" ensures we have an 'empty' override
230 overrides = (bb.data.getVar("OVERRIDES", d, 1) or "") + ":"
232 for o in overrides.split(":"):
233 filespath.append(os.path.join(p, o))
234 return ":".join(filespath)
236 def oe_filter(f, str, d):
238 return " ".join(filter(lambda x: match(f, x, 0), str.split()))
240 def oe_filter_out(f, str, d):
242 return " ".join(filter(lambda x: not match(f, x, 0), str.split()))
263 echo "Usage: oedebug level \"message\""
267 test ${OEDEBUG:-0} -ge $1 && {
274 if [ x"$MAKE" = x ]; then MAKE=make; fi
275 oenote ${MAKE} ${EXTRA_OEMAKE} "$@"
276 ${MAKE} ${EXTRA_OEMAKE} "$@" || die "oe_runmake failed"
280 # Purpose: Install shared library file and
281 # create the necessary links
286 #oenote installing shared library $1 to $2
288 libname=`basename $1`
289 install -m 755 $1 $2/$libname
290 sonamelink=`${HOST_PREFIX}readelf -d $1 |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
291 solink=`echo $libname | sed -e 's/\.so\..*/.so/'`
292 ln -sf $libname $2/$sonamelink
293 ln -sf $libname $2/$solink
297 # Purpose: Install a library, in all its forms
300 # oe_libinstall libltdl ${STAGING_LIBDIR}/
301 # oe_libinstall -C src/libblah libblah ${D}/${libdir}/
308 while [ "$#" -gt 0 ]; do
324 oefatal "oe_libinstall: unknown option: $1"
336 if [ -z "$destpath" ]; then
337 oefatal "oe_libinstall: no destination path specified"
339 if echo "$destpath/" | egrep '^${STAGING_LIBDIR}/' >/dev/null
345 if [ -z "$silent" ]; then
346 echo >&2 "oe_libinstall: $*"
351 if [ -z "$dir" ]; then
357 # Sanity check that the libname.lai is unique
358 number_of_files=`(cd $dir; find . -name "$dotlai") | wc -l`
359 if [ $number_of_files -gt 1 ]; then
360 oefatal "oe_libinstall: $dotlai is not unique in $dir"
364 dir=$dir`(cd $dir;find . -name "$dotlai") | sed "s/^\.//;s/\/$dotlai\$//;q"`
370 # If such file doesn't exist, try to cut version suffix
371 if [ ! -f "$lafile" ]; then
372 libname1=`echo "$libname" | sed 's/-[0-9.]*$//'`
374 if [ -f "$lafile1" ]; then
380 if [ -f "$lafile" ]; then
382 eval `cat $lafile|grep "^library_names="`
385 library_names="$libname.so* $libname.dll.a"
388 __runcmd install -d $destpath/
390 if [ -f "$dota" -o -n "$require_static" ]; then
391 __runcmd install -m 0644 $dota $destpath/
393 if [ -f "$dotlai" -a -n "$libtool" ]; then
394 if test -n "$staging_install"
396 # stop libtool using the final directory name for libraries
398 __runcmd rm -f $destpath/$libname.la
399 __runcmd sed -e 's/^installed=yes$/installed=no/' \
400 -e '/^dependency_libs=/s,${WORKDIR}[[:alnum:]/\._+-]*/\([[:alnum:]\._+-]*\),${STAGING_LIBDIR}/\1,g' \
401 -e "/^dependency_libs=/s,\([[:space:]']\)${libdir},\1${STAGING_LIBDIR},g" \
402 $dotlai >$destpath/$libname.la
404 __runcmd install -m 0644 $dotlai $destpath/$libname.la
408 for name in $library_names; do
409 files=`eval echo $name`
411 if [ ! -e "$f" ]; then
412 if [ -n "$libtool" ]; then
413 oefatal "oe_libinstall: $dir/$f not found."
415 elif [ -L "$f" ]; then
416 __runcmd cp -P "$f" $destpath/
417 elif [ ! -L "$f" ]; then
419 __runcmd install -m 0755 $libfile $destpath/
424 if [ -z "$libfile" ]; then
425 if [ -n "$require_shared" ]; then
426 oefatal "oe_libinstall: unable to locate shared library"
428 elif [ -z "$libtool" ]; then
429 # special case hack for non-libtool .so.#.#.# links
430 baselibfile=`basename "$libfile"`
431 if (echo $baselibfile | grep -qE '^lib.*\.so\.[0-9.]*$'); then
432 sonamelink=`${HOST_PREFIX}readelf -d $libfile |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
433 solink=`echo $baselibfile | sed -e 's/\.so\..*/.so/'`
434 if [ -n "$sonamelink" -a x"$baselibfile" != x"$sonamelink" ]; then
435 __runcmd ln -sf $baselibfile $destpath/$sonamelink
437 __runcmd ln -sf $baselibfile $destpath/$solink
441 __runcmd cd "$olddir"
444 def package_stagefile(file, d):
447 if bb.data.getVar('PSTAGING_ACTIVE', d, True) == "1":
448 destfile = file.replace(bb.data.getVar("TMPDIR", d, 1), bb.data.getVar("PSTAGE_TMPDIR_STAGE", d, 1))
449 bb.mkdirhier(os.path.dirname(destfile))
450 #print "%s to %s" % (file, destfile)
451 bb.copyfile(file, destfile)
453 package_stagefile_shell() {
454 if [ "$PSTAGING_ACTIVE" = "1" ]; then
456 destfile=`echo $srcfile | sed s#${TMPDIR}#${PSTAGE_TMPDIR_STAGE}#`
457 destdir=`dirname $destfile`
459 cp -dp $srcfile $destfile
464 # Purpose: Install machine dependent files, if available
465 # If not available, check if there is a default
466 # If no default, just touch the destination
469 # oe_machinstall -m 0644 fstab ${D}/etc/fstab
471 # TODO: Check argument number?
473 filename=`basename $3`
476 for o in `echo ${OVERRIDES} | tr ':' ' '`; do
477 if [ -e $dirname/$o/$filename ]; then
478 oenote $dirname/$o/$filename present, installing to $4
479 install $1 $2 $dirname/$o/$filename $4
483 # oenote overrides specific file NOT present, trying default=$3...
485 oenote $3 present, installing to $4
488 oenote $3 NOT present, touching empty $4
494 do_listtasks[nostamp] = "1"
495 python do_listtasks() {
497 # emit variables and shell functions
498 #bb.data.emit_env(sys.__stdout__, d)
499 # emit the metadata which isnt valid shell
501 if bb.data.getVarFlag(e, 'task', d):
502 sys.__stdout__.write("%s\n" % e)
506 do_clean[dirs] = "${TOPDIR}"
507 do_clean[nostamp] = "1"
508 python base_do_clean() {
509 """clear the build and temp directories"""
510 dir = bb.data.expand("${WORKDIR}", d)
511 if dir == '//': raise bb.build.FuncFailed("wrong DATADIR")
512 bb.note("removing " + base_path_out(dir, d))
513 os.system('rm -rf ' + dir)
515 dir = "%s.*" % bb.data.expand(bb.data.getVar('STAMP', d), d)
516 bb.note("removing " + base_path_out(dir, d))
517 os.system('rm -f '+ dir)
520 #Uncomment this for bitbake 1.8.12
521 #addtask rebuild after do_${BB_DEFAULT_TASK}
523 do_rebuild[dirs] = "${TOPDIR}"
524 do_rebuild[nostamp] = "1"
525 python base_do_rebuild() {
526 """rebuild a package"""
527 from bb import __version__
529 from distutils.version import LooseVersion
531 def LooseVersion(v): print "WARNING: sanity.bbclass can't compare versions without python-distutils"; return 1
532 if (LooseVersion(__version__) < LooseVersion('1.8.11')):
533 bb.build.exec_func('do_clean', d)
534 bb.build.exec_task('do_' + bb.data.getVar('BB_DEFAULT_TASK', d, 1), d)
538 do_mrproper[dirs] = "${TOPDIR}"
539 do_mrproper[nostamp] = "1"
540 python base_do_mrproper() {
541 """clear downloaded sources, build and temp directories"""
542 dir = bb.data.expand("${DL_DIR}", d)
543 if dir == '/': bb.build.FuncFailed("wrong DATADIR")
544 bb.debug(2, "removing " + dir)
545 os.system('rm -rf ' + dir)
546 bb.build.exec_func('do_clean', d)
550 do_distclean[dirs] = "${TOPDIR}"
551 do_distclean[nostamp] = "1"
552 python base_do_distclean() {
553 """clear downloaded sources, build and temp directories"""
556 bb.build.exec_func('do_clean', d)
558 src_uri = bb.data.getVar('SRC_URI', d, 1)
562 for uri in src_uri.split():
563 if bb.decodeurl(uri)[0] == "file":
567 local = bb.data.expand(bb.fetch.localpath(uri, d), d)
568 except bb.MalformedUrl, e:
569 bb.debug(1, 'Unable to generate local path for malformed uri: %s' % e)
571 bb.note("removing %s" % base_path_out(local, d))
573 if os.path.exists(local + ".md5"):
574 os.remove(local + ".md5")
575 if os.path.exists(local):
578 bb.note("Error in removal: %s" % e)
581 SCENEFUNCS += "base_scenefunction"
583 python base_do_setscene () {
584 for f in (bb.data.getVar('SCENEFUNCS', d, 1) or '').split():
585 bb.build.exec_func(f, d)
586 if not os.path.exists(bb.data.getVar('STAMP', d, 1) + ".do_setscene"):
587 bb.build.make_stamp("do_setscene", d)
589 do_setscene[selfstamp] = "1"
590 addtask setscene before do_fetch
592 python base_scenefunction () {
593 stamp = bb.data.getVar('STAMP', d, 1) + ".needclean"
594 if os.path.exists(stamp):
595 bb.build.exec_func("do_clean", d)
600 do_fetch[dirs] = "${DL_DIR}"
601 do_fetch[depends] = "shasum-native:do_populate_staging"
602 python base_do_fetch() {
605 localdata = bb.data.createCopy(d)
606 bb.data.update_data(localdata)
608 src_uri = bb.data.getVar('SRC_URI', localdata, 1)
613 bb.fetch.init(src_uri.split(),d)
614 except bb.fetch.NoMethodError:
615 (type, value, traceback) = sys.exc_info()
616 raise bb.build.FuncFailed("No method: %s" % value)
619 bb.fetch.go(localdata)
620 except bb.fetch.MissingParameterError:
621 (type, value, traceback) = sys.exc_info()
622 raise bb.build.FuncFailed("Missing parameters: %s" % value)
623 except bb.fetch.FetchError:
624 (type, value, traceback) = sys.exc_info()
625 raise bb.build.FuncFailed("Fetch failed: %s" % value)
626 except bb.fetch.MD5SumError:
627 (type, value, traceback) = sys.exc_info()
628 raise bb.build.FuncFailed("MD5 failed: %s" % value)
630 (type, value, traceback) = sys.exc_info()
631 raise bb.build.FuncFailed("Unknown fetch Error: %s" % value)
634 # Verify the SHA and MD5 sums we have in OE and check what do
636 checksum_paths = bb.data.getVar('BBPATH', d, True).split(":")
638 # reverse the list to give precedence to directories that
639 # appear first in BBPATH
640 checksum_paths.reverse()
642 checksum_files = ["%s/conf/checksums.ini" % path for path in checksum_paths]
644 parser = base_chk_load_parser(checksum_files)
646 bb.note("No conf/checksums.ini found, not checking checksums")
649 bb.note("Creating the CheckSum parser failed")
652 pv = bb.data.getVar('PV', d, True)
653 pn = bb.data.getVar('PN', d, True)
656 for url in src_uri.split():
657 localpath = bb.data.expand(bb.fetch.localpath(url, localdata), localdata)
658 (type,host,path,_,_,_) = bb.decodeurl(url)
659 uri = "%s://%s%s" % (type,host,path)
661 if type == "http" or type == "https" or type == "ftp" or type == "ftps":
662 if not base_chk_file(parser, pn, pv,uri, localpath, d):
663 if not bb.data.getVar("OE_ALLOW_INSECURE_DOWNLOADS",d, True):
664 bb.fatal("%s-%s: %s has no entry in conf/checksums.ini, not checking URI" % (pn,pv,uri))
666 bb.note("%s-%s: %s has no entry in conf/checksums.ini, not checking URI" % (pn,pv,uri))
668 raise bb.build.FuncFailed("Checksum of '%s' failed" % uri)
671 addtask fetchall after do_fetch
672 do_fetchall[recrdeptask] = "do_fetch"
678 do_checkuri[nostamp] = "1"
679 python do_checkuri() {
682 localdata = bb.data.createCopy(d)
683 bb.data.update_data(localdata)
685 src_uri = bb.data.getVar('SRC_URI', localdata, 1)
688 bb.fetch.init(src_uri.split(),d)
689 except bb.fetch.NoMethodError:
690 (type, value, traceback) = sys.exc_info()
691 raise bb.build.FuncFailed("No method: %s" % value)
694 bb.fetch.checkstatus(localdata)
695 except bb.fetch.MissingParameterError:
696 (type, value, traceback) = sys.exc_info()
697 raise bb.build.FuncFailed("Missing parameters: %s" % value)
698 except bb.fetch.FetchError:
699 (type, value, traceback) = sys.exc_info()
700 raise bb.build.FuncFailed("Fetch failed: %s" % value)
701 except bb.fetch.MD5SumError:
702 (type, value, traceback) = sys.exc_info()
703 raise bb.build.FuncFailed("MD5 failed: %s" % value)
705 (type, value, traceback) = sys.exc_info()
706 raise bb.build.FuncFailed("Unknown fetch Error: %s" % value)
709 addtask checkuriall after do_checkuri
710 do_checkuriall[recrdeptask] = "do_checkuri"
711 do_checkuriall[nostamp] = "1"
712 base_do_checkuriall() {
716 addtask buildall after do_build
717 do_buildall[recrdeptask] = "do_build"
723 def oe_unpack_file(file, data, url = None):
726 url = "file://%s" % file
727 dots = file.split(".")
728 if dots[-1] in ['gz', 'bz2', 'Z']:
729 efile = os.path.join(bb.data.getVar('WORKDIR', data, 1),os.path.basename('.'.join(dots[0:-1])))
733 if file.endswith('.tar'):
734 cmd = 'tar x --no-same-owner -f %s' % file
735 elif file.endswith('.tgz') or file.endswith('.tar.gz') or file.endswith('.tar.Z'):
736 cmd = 'tar xz --no-same-owner -f %s' % file
737 elif file.endswith('.tbz') or file.endswith('.tbz2') or file.endswith('.tar.bz2'):
738 cmd = 'bzip2 -dc %s | tar x --no-same-owner -f -' % file
739 elif file.endswith('.gz') or file.endswith('.Z') or file.endswith('.z'):
740 cmd = 'gzip -dc %s > %s' % (file, efile)
741 elif file.endswith('.bz2'):
742 cmd = 'bzip2 -dc %s > %s' % (file, efile)
743 elif file.endswith('.zip') or file.endswith('.jar'):
745 (type, host, path, user, pswd, parm) = bb.decodeurl(url)
748 cmd = '%s %s' % (cmd, file)
749 elif os.path.isdir(file):
751 filespath = bb.data.getVar("FILESPATH", data, 1).split(":")
753 if file[0:len(fp)] == fp:
754 destdir = file[len(fp):file.rfind('/')]
755 destdir = destdir.strip('/')
758 elif not os.access("%s/%s" % (os.getcwd(), destdir), os.F_OK):
759 os.makedirs("%s/%s" % (os.getcwd(), destdir))
762 cmd = 'cp -pPR %s %s/%s/' % (file, os.getcwd(), destdir)
764 (type, host, path, user, pswd, parm) = bb.decodeurl(url)
765 if not 'patch' in parm:
766 # The "destdir" handling was specifically done for FILESPATH
767 # items. So, only do so for file:// entries.
769 destdir = bb.decodeurl(url)[1] or "."
772 bb.mkdirhier("%s/%s" % (os.getcwd(), destdir))
773 cmd = 'cp %s %s/%s/' % (file, os.getcwd(), destdir)
778 dest = os.path.join(os.getcwd(), os.path.basename(file))
779 if os.path.exists(dest):
780 if os.path.samefile(file, dest):
783 # Change to subdir before executing command
784 save_cwd = os.getcwd();
785 parm = bb.decodeurl(url)[5]
787 newdir = ("%s/%s" % (os.getcwd(), parm['subdir']))
791 cmd = "PATH=\"%s\" %s" % (bb.data.getVar('PATH', data, 1), cmd)
792 bb.note("Unpacking %s to %s/" % (base_path_out(file, data), base_path_out(os.getcwd(), data)))
799 addtask unpack after do_fetch
800 do_unpack[dirs] = "${WORKDIR}"
801 python base_do_unpack() {
804 localdata = bb.data.createCopy(d)
805 bb.data.update_data(localdata)
807 src_uri = bb.data.getVar('SRC_URI', localdata)
810 src_uri = bb.data.expand(src_uri, localdata)
811 for url in src_uri.split():
813 local = bb.data.expand(bb.fetch.localpath(url, localdata), localdata)
814 except bb.MalformedUrl, e:
815 raise bb.build.FuncFailed('Unable to generate local path for malformed uri: %s' % e)
817 raise bb.build.FuncFailed('Unable to locate local file for %s' % url)
818 local = os.path.realpath(local)
819 ret = oe_unpack_file(local, localdata, url)
821 raise bb.build.FuncFailed()
824 METADATA_SCM = "${@base_get_scm(d)}"
825 METADATA_REVISION = "${@base_get_scm_revision(d)}"
826 METADATA_BRANCH = "${@base_get_scm_branch(d)}"
831 baserepo = os.path.dirname(os.path.dirname(which(d.getVar("BBPATH", 1), "classes/base.bbclass")))
832 for (scm, scmpath) in {"svn": ".svn",
834 "monotone": "_MTN"}.iteritems():
835 if os.path.exists(os.path.join(baserepo, scmpath)):
836 return "%s %s" % (scm, baserepo)
837 return "<unknown> %s" % baserepo
839 def base_get_scm_revision(d):
840 (scm, path) = d.getVar("METADATA_SCM", 1).split()
842 if scm != "<unknown>":
843 return globals()["base_get_metadata_%s_revision" % scm](path, d)
849 def base_get_scm_branch(d):
850 (scm, path) = d.getVar("METADATA_SCM", 1).split()
852 if scm != "<unknown>":
853 return globals()["base_get_metadata_%s_branch" % scm](path, d)
859 def base_get_metadata_monotone_branch(path, d):
860 monotone_branch = "<unknown>"
862 monotone_branch = file( "%s/_MTN/options" % path ).read().strip()
863 if monotone_branch.startswith( "database" ):
864 monotone_branch_words = monotone_branch.split()
865 monotone_branch = monotone_branch_words[ monotone_branch_words.index( "branch" )+1][1:-1]
868 return monotone_branch
870 def base_get_metadata_monotone_revision(path, d):
871 monotone_revision = "<unknown>"
873 monotone_revision = file( "%s/_MTN/revision" % path ).read().strip()
874 if monotone_revision.startswith( "format_version" ):
875 monotone_revision_words = monotone_revision.split()
876 monotone_revision = monotone_revision_words[ monotone_revision_words.index( "old_revision" )+1][1:-1]
879 return monotone_revision
881 def base_get_metadata_svn_revision(path, d):
882 revision = "<unknown>"
884 revision = file( "%s/.svn/entries" % path ).readlines()[3].strip()
889 def base_get_metadata_git_branch(path, d):
891 branch = os.popen('cd %s; PATH=%s git symbolic-ref HEAD 2>/dev/null' % (path, d.getVar("PATH", 1))).read().rstrip()
894 return branch.replace("refs/heads/", "")
897 def base_get_metadata_git_revision(path, d):
899 rev = os.popen("cd %s; PATH=%s git show-ref HEAD 2>/dev/null" % (path, d.getVar("PATH", 1))).read().split(" ")[0].rstrip()
905 addhandler base_eventhandler
906 python base_eventhandler() {
907 from bb import note, error, data
908 from bb.event import Handled, NotHandled, getName
912 if name == "TaskCompleted":
913 msg = "package %s: task %s is complete." % (data.getVar("PF", e.data, 1), e.task)
914 elif name == "UnsatisfiedDep":
915 msg = "package %s: dependency %s %s" % (e.pkg, e.dep, name[:-3].lower())
919 # Only need to output when using 1.8 or lower, the UI code handles it
921 if (int(bb.__version__.split(".")[0]) <= 1 and int(bb.__version__.split(".")[1]) <= 8):
925 if name.startswith("BuildStarted"):
926 bb.data.setVar( 'BB_VERSION', bb.__version__, e.data )
927 statusvars = bb.data.getVar("BUILDCFG_VARS", e.data, 1).split()
928 statuslines = ["%-17s = \"%s\"" % (i, bb.data.getVar(i, e.data, 1) or '') for i in statusvars]
929 statusmsg = "\n%s\n%s\n" % (bb.data.getVar("BUILDCFG_HEADER", e.data, 1), "\n".join(statuslines))
932 needed_vars = bb.data.getVar("BUILDCFG_NEEDEDVARS", e.data, 1).split()
934 for v in needed_vars:
935 val = bb.data.getVar(v, e.data, 1)
936 if not val or val == 'INVALID':
939 bb.fatal('The following variable(s) were not set: %s\nPlease set them directly, or choose a MACHINE or DISTRO that sets them.' % ', '.join(pesteruser))
942 # Handle removing stamps for 'rebuild' task
944 if name.startswith("StampUpdate"):
945 for (fn, task) in e.targets:
946 #print "%s %s" % (task, fn)
947 if task == "do_rebuild":
948 dir = "%s.*" % e.stampPrefix[fn]
949 bb.note("Removing stamps: " + dir)
950 os.system('rm -f '+ dir)
951 os.system('touch ' + e.stampPrefix[fn] + '.needclean')
953 if not data in e.__dict__:
956 log = data.getVar("EVENTLOG", e.data, 1)
958 logfile = file(log, "a")
959 logfile.write("%s\n" % msg)
965 addtask configure after do_unpack do_patch
966 do_configure[dirs] = "${S} ${B}"
967 do_configure[deptask] = "do_populate_staging"
968 base_do_configure() {
972 addtask compile after do_configure
973 do_compile[dirs] = "${S} ${B}"
975 if [ -e Makefile -o -e makefile ]; then
976 oe_runmake || die "make failed"
978 oenote "nothing to compile"
986 do_populate_staging[dirs] = "${STAGING_DIR_TARGET}/${layout_bindir} ${STAGING_DIR_TARGET}/${layout_libdir} \
987 ${STAGING_DIR_TARGET}/${layout_includedir} \
988 ${STAGING_BINDIR_NATIVE} ${STAGING_LIBDIR_NATIVE} \
989 ${STAGING_INCDIR_NATIVE} \
993 # Could be compile but populate_staging and do_install shouldn't run at the same time
994 addtask populate_staging after do_install
996 python do_populate_staging () {
997 bb.build.exec_func('do_stage', d)
1000 addtask install after do_compile
1001 do_install[dirs] = "${D} ${S} ${B}"
1002 # Remove and re-create ${D} so that is it guaranteed to be empty
1003 do_install[cleandirs] = "${D}"
1013 addtask build after do_populate_staging
1015 do_build[func] = "1"
1017 # Functions that update metadata based on files outputted
1018 # during the build process.
1020 def explode_deps(s):
1032 r[-1] += ' ' + ' '.join(j)
1037 def packaged(pkg, d):
1039 return os.access(get_subpkgedata_fn(pkg, d) + '.packaged', os.R_OK)
1041 def read_pkgdatafile(fn):
1046 c = codecs.getdecoder("string_escape")
1050 if os.access(fn, os.R_OK):
1053 lines = f.readlines()
1055 r = re.compile("([^:]+):\s*(.*)")
1059 pkgdata[m.group(1)] = decode(m.group(2))
1063 def get_subpkgedata_fn(pkg, d):
1065 archs = bb.data.expand("${PACKAGE_ARCHS}", d).split(" ")
1067 pkgdata = bb.data.expand('${TMPDIR}/pkgdata/', d)
1068 targetdir = bb.data.expand('${TARGET_VENDOR}-${TARGET_OS}/runtime/', d)
1070 fn = pkgdata + arch + targetdir + pkg
1071 if os.path.exists(fn):
1073 return bb.data.expand('${PKGDATA_DIR}/runtime/%s' % pkg, d)
1075 def has_subpkgdata(pkg, d):
1077 return os.access(get_subpkgedata_fn(pkg, d), os.R_OK)
1079 def read_subpkgdata(pkg, d):
1081 return read_pkgdatafile(get_subpkgedata_fn(pkg, d))
1083 def has_pkgdata(pn, d):
1085 fn = bb.data.expand('${PKGDATA_DIR}/%s' % pn, d)
1086 return os.access(fn, os.R_OK)
1088 def read_pkgdata(pn, d):
1090 fn = bb.data.expand('${PKGDATA_DIR}/%s' % pn, d)
1091 return read_pkgdatafile(fn)
1093 python read_subpackage_metadata () {
1095 data = read_pkgdata(bb.data.getVar('PN', d, 1), d)
1097 for key in data.keys():
1098 bb.data.setVar(key, data[key], d)
1100 for pkg in bb.data.getVar('PACKAGES', d, 1).split():
1101 sdata = read_subpkgdata(pkg, d)
1102 for key in sdata.keys():
1103 bb.data.setVar(key, sdata[key], d)
1108 # Collapse FOO_pkg variables into FOO
1110 def read_subpkgdata_dict(pkg, d):
1113 subd = read_pkgdatafile(get_subpkgedata_fn(pkg, d))
1115 newvar = var.replace("_" + pkg, "")
1116 ret[newvar] = subd[var]
1119 # Make sure MACHINE isn't exported
1120 # (breaks binutils at least)
1121 MACHINE[unexport] = "1"
1123 # Make sure TARGET_ARCH isn't exported
1124 # (breaks Makefiles using implicit rules, e.g. quilt, as GNU make has this
1125 # in them, undocumented)
1126 TARGET_ARCH[unexport] = "1"
1128 # Make sure DISTRO isn't exported
1129 # (breaks sysvinit at least)
1130 DISTRO[unexport] = "1"
1133 def base_after_parse(d):
1134 import bb, os, exceptions
1136 source_mirror_fetch = bb.data.getVar('SOURCE_MIRROR_FETCH', d, 0)
1137 if not source_mirror_fetch:
1138 need_host = bb.data.getVar('COMPATIBLE_HOST', d, 1)
1141 this_host = bb.data.getVar('HOST_SYS', d, 1)
1142 if not re.match(need_host, this_host):
1143 raise bb.parse.SkipPackage("incompatible with host %s" % this_host)
1145 need_machine = bb.data.getVar('COMPATIBLE_MACHINE', d, 1)
1148 this_machine = bb.data.getVar('MACHINE', d, 1)
1149 if this_machine and not re.match(need_machine, this_machine):
1150 raise bb.parse.SkipPackage("incompatible with machine %s" % this_machine)
1152 pn = bb.data.getVar('PN', d, 1)
1154 # OBSOLETE in bitbake 1.7.4
1155 srcdate = bb.data.getVar('SRCDATE_%s' % pn, d, 1)
1157 bb.data.setVar('SRCDATE', srcdate, d)
1159 use_nls = bb.data.getVar('USE_NLS_%s' % pn, d, 1)
1161 bb.data.setVar('USE_NLS', use_nls, d)
1163 # Git packages should DEPEND on git-native
1164 srcuri = bb.data.getVar('SRC_URI', d, 1)
1165 if "git://" in srcuri:
1166 depends = bb.data.getVarFlag('do_fetch', 'depends', d) or ""
1167 depends = depends + " git-native:do_populate_staging"
1168 bb.data.setVarFlag('do_fetch', 'depends', depends, d)
1170 # 'multimachine' handling
1171 mach_arch = bb.data.getVar('MACHINE_ARCH', d, 1)
1172 pkg_arch = bb.data.getVar('PACKAGE_ARCH', d, 1)
1174 if (pkg_arch == mach_arch):
1175 # Already machine specific - nothing further to do
1179 # We always try to scan SRC_URI for urls with machine overrides
1180 # unless the package sets SRC_URI_OVERRIDES_PACKAGE_ARCH=0
1182 override = bb.data.getVar('SRC_URI_OVERRIDES_PACKAGE_ARCH', d, 1)
1185 for p in [ "${PF}", "${P}", "${PN}", "files", "" ]:
1186 path = bb.data.expand(os.path.join("${FILE_DIRNAME}", p, "${MACHINE}"), d)
1187 if os.path.isdir(path):
1190 for s in srcuri.split():
1191 if not s.startswith("file://"):
1193 local = bb.data.expand(bb.fetch.localpath(s, d), d)
1195 if local.startswith(mp):
1196 #bb.note("overriding PACKAGE_ARCH from %s to %s" % (pkg_arch, mach_arch))
1197 bb.data.setVar('PACKAGE_ARCH', "${MACHINE_ARCH}", d)
1198 bb.data.setVar('MULTIMACH_ARCH', mach_arch, d)
1201 multiarch = pkg_arch
1203 packages = bb.data.getVar('PACKAGES', d, 1).split()
1204 for pkg in packages:
1205 pkgarch = bb.data.getVar("PACKAGE_ARCH_%s" % pkg, d, 1)
1207 # We could look for != PACKAGE_ARCH here but how to choose
1208 # if multiple differences are present?
1209 # Look through PACKAGE_ARCHS for the priority order?
1210 if pkgarch and pkgarch == mach_arch:
1211 multiarch = mach_arch
1214 bb.data.setVar('MULTIMACH_ARCH', multiarch, d)
1218 from bb import __version__
1221 # Remove this for bitbake 1.8.12
1223 from distutils.version import LooseVersion
1225 def LooseVersion(v): print "WARNING: sanity.bbclass can't compare versions without python-distutils"; return 1
1226 if (LooseVersion(__version__) >= LooseVersion('1.8.11')):
1227 deps = bb.data.getVarFlag('do_rebuild', 'deps', d) or []
1228 deps.append('do_' + bb.data.getVar('BB_DEFAULT_TASK', d, 1))
1229 bb.data.setVarFlag('do_rebuild', 'deps', deps, d)
1232 def check_app_exists(app, d):
1233 from bb import which, data
1235 app = data.expand(app, d)
1236 path = data.getVar('PATH', d, 1)
1237 return len(which(path, app)) != 0
1239 def check_gcc3(data):
1240 # Primarly used by qemu to make sure we have a workable gcc-3.4.x.
1241 # Start by checking for the program name as we build it, was not
1242 # all host-provided gcc-3.4's will work.
1244 gcc3_versions = 'gcc-3.4.6 gcc-3.4.4 gcc34 gcc-3.4 gcc-3.4.7 gcc-3.3 gcc33 gcc-3.3.6 gcc-3.2 gcc32'
1246 for gcc3 in gcc3_versions.split():
1247 if check_app_exists(gcc3, data):
1255 # Configuration data from site files
1256 # Move to autotools.bbclass?
1259 EXPORT_FUNCTIONS do_setscene do_clean do_mrproper do_distclean do_fetch do_unpack do_configure do_compile do_install do_package do_populate_pkgs do_stage do_rebuild do_fetchall
1263 ${DEBIAN_MIRROR}/main http://snapshot.debian.net/archive/pool
1264 ${DEBIAN_MIRROR} ftp://ftp.de.debian.org/debian/pool
1265 ${DEBIAN_MIRROR} ftp://ftp.au.debian.org/debian/pool
1266 ${DEBIAN_MIRROR} ftp://ftp.cl.debian.org/debian/pool
1267 ${DEBIAN_MIRROR} ftp://ftp.hr.debian.org/debian/pool
1268 ${DEBIAN_MIRROR} ftp://ftp.fi.debian.org/debian/pool
1269 ${DEBIAN_MIRROR} ftp://ftp.hk.debian.org/debian/pool
1270 ${DEBIAN_MIRROR} ftp://ftp.hu.debian.org/debian/pool
1271 ${DEBIAN_MIRROR} ftp://ftp.ie.debian.org/debian/pool
1272 ${DEBIAN_MIRROR} ftp://ftp.it.debian.org/debian/pool
1273 ${DEBIAN_MIRROR} ftp://ftp.jp.debian.org/debian/pool
1274 ${DEBIAN_MIRROR} ftp://ftp.no.debian.org/debian/pool
1275 ${DEBIAN_MIRROR} ftp://ftp.pl.debian.org/debian/pool
1276 ${DEBIAN_MIRROR} ftp://ftp.ro.debian.org/debian/pool
1277 ${DEBIAN_MIRROR} ftp://ftp.si.debian.org/debian/pool
1278 ${DEBIAN_MIRROR} ftp://ftp.es.debian.org/debian/pool
1279 ${DEBIAN_MIRROR} ftp://ftp.se.debian.org/debian/pool
1280 ${DEBIAN_MIRROR} ftp://ftp.tr.debian.org/debian/pool
1281 ${GNU_MIRROR} ftp://mirrors.kernel.org/gnu
1282 ${GNU_MIRROR} ftp://ftp.matrix.com.br/pub/gnu
1283 ${GNU_MIRROR} ftp://ftp.cs.ubc.ca/mirror2/gnu
1284 ${GNU_MIRROR} ftp://sunsite.ust.hk/pub/gnu
1285 ${GNU_MIRROR} ftp://ftp.ayamura.org/pub/gnu
1286 ${KERNELORG_MIRROR} http://www.kernel.org/pub
1287 ${KERNELORG_MIRROR} ftp://ftp.us.kernel.org/pub
1288 ${KERNELORG_MIRROR} ftp://ftp.uk.kernel.org/pub
1289 ${KERNELORG_MIRROR} ftp://ftp.hk.kernel.org/pub
1290 ${KERNELORG_MIRROR} ftp://ftp.au.kernel.org/pub
1291 ${KERNELORG_MIRROR} ftp://ftp.jp.kernel.org/pub
1292 ftp://ftp.gnupg.org/gcrypt/ ftp://ftp.franken.de/pub/crypt/mirror/ftp.gnupg.org/gcrypt/
1293 ftp://ftp.gnupg.org/gcrypt/ ftp://ftp.surfnet.nl/pub/security/gnupg/
1294 ftp://ftp.gnupg.org/gcrypt/ http://gulus.USherbrooke.ca/pub/appl/GnuPG/
1295 ftp://dante.ctan.org/tex-archive ftp://ftp.fu-berlin.de/tex/CTAN
1296 ftp://dante.ctan.org/tex-archive http://sunsite.sut.ac.jp/pub/archives/ctan/
1297 ftp://dante.ctan.org/tex-archive http://ctan.unsw.edu.au/
1298 ftp://ftp.gnutls.org/pub/gnutls ftp://ftp.gnutls.org/pub/gnutls/
1299 ftp://ftp.gnutls.org/pub/gnutls ftp://ftp.gnupg.org/gcrypt/gnutls/
1300 ftp://ftp.gnutls.org/pub/gnutls http://www.mirrors.wiretapped.net/security/network-security/gnutls/
1301 ftp://ftp.gnutls.org/pub/gnutls ftp://ftp.mirrors.wiretapped.net/pub/security/network-security/gnutls/
1302 ftp://ftp.gnutls.org/pub/gnutls http://josefsson.org/gnutls/releases/
1303 http://ftp.info-zip.org/pub/infozip/src/ http://mirror.switch.ch/ftp/mirror/infozip/src/
1304 http://ftp.info-zip.org/pub/infozip/src/ ftp://sunsite.icm.edu.pl/pub/unix/archiving/info-zip/src/
1305 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.cerias.purdue.edu/pub/tools/unix/sysutils/lsof/
1306 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.tau.ac.il/pub/unix/admin/
1307 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.cert.dfn.de/pub/tools/admin/lsof/
1308 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.fu-berlin.de/pub/unix/tools/lsof/
1309 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.kaizo.org/pub/lsof/
1310 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.tu-darmstadt.de/pub/sysadmin/lsof/
1311 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.tux.org/pub/sites/vic.cc.purdue.edu/tools/unix/lsof/
1312 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://gd.tuwien.ac.at/utils/admin-tools/lsof/
1313 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://sunsite.ualberta.ca/pub/Mirror/lsof/
1314 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://the.wiretapped.net/pub/security/host-security/lsof/
1315 http://www.apache.org/dist http://archive.apache.org/dist