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 # for MD5/SHA handling
43 def base_chk_load_parser(config_paths):
44 import ConfigParser, os, bb
45 parser = ConfigParser.ConfigParser()
46 if len(parser.read(config_paths)) < 1:
47 raise ValueError("no ini files could be found")
51 def base_chk_file(parser, pn, pv, src_uri, localpath, data):
54 # Try PN-PV-SRC_URI first and then try PN-SRC_URI
55 # we rely on the get method to create errors
56 pn_pv_src = "%s-%s-%s" % (pn,pv,src_uri)
57 pn_src = "%s-%s" % (pn,src_uri)
58 if parser.has_section(pn_pv_src):
59 md5 = parser.get(pn_pv_src, "md5")
60 sha256 = parser.get(pn_pv_src, "sha256")
61 elif parser.has_section(pn_src):
62 md5 = parser.get(pn_src, "md5")
63 sha256 = parser.get(pn_src, "sha256")
64 elif parser.has_section(src_uri):
65 md5 = parser.get(src_uri, "md5")
66 sha256 = parser.get(src_uri, "sha256")
70 # md5 and sha256 should be valid now
71 if not os.path.exists(localpath):
72 bb.note("The localpath does not exist '%s'" % localpath)
73 raise Exception("The path does not exist '%s'" % localpath)
76 # call md5(sum) and shasum
78 md5pipe = os.popen('md5sum ' + localpath)
79 md5data = (md5pipe.readline().split() or [ "" ])[0]
82 raise Exception("Executing md5sum failed")
85 shapipe = os.popen('PATH=%s oe_sha256sum %s' % (bb.data.getVar('PATH', data, True), localpath))
86 shadata = (shapipe.readline().split() or [ "" ])[0]
89 raise Exception("Executing shasum failed")
91 if no_checksum == True: # we do not have conf/checksums.ini entry
93 file = open("%s/checksums.ini" % bb.data.getVar("TMPDIR", data, 1), "a")
98 raise Exception("Creating checksums.ini failed")
100 file.write("[%s]\nmd5=%s\nsha256=%s\n\n" % (src_uri, md5data, shadata))
102 if not bb.data.getVar("OE_STRICT_CHECKSUMS",data, True):
103 bb.note("This package has no entry in checksums.ini, please add one")
104 bb.note("\n[%s]\nmd5=%s\nsha256=%s" % (src_uri, md5data, shadata))
107 bb.note("Missing checksum")
110 if not md5 == md5data:
111 bb.note("The MD5Sums did not match. Wanted: '%s' and Got: '%s'" % (md5,md5data))
112 raise Exception("MD5 Sums do not match. Wanted: '%s' Got: '%s'" % (md5, md5data))
114 if not sha256 == shadata:
115 bb.note("The SHA256 Sums do not match. Wanted: '%s' Got: '%s'" % (sha256,shadata))
116 raise Exception("SHA256 Sums do not match. Wanted: '%s' Got: '%s'" % (sha256, shadata))
121 def base_dep_prepend(d):
124 # Ideally this will check a flag so we will operate properly in
125 # the case where host == build == target, for now we don't work in
128 deps = "shasum-native coreutils-native"
129 if bb.data.getVar('PN', d, True) == "shasum-native" or bb.data.getVar('PN', d, True) == "stagemanager-native":
131 if bb.data.getVar('PN', d, True) == "coreutils-native":
132 deps = "shasum-native"
134 # INHIBIT_DEFAULT_DEPS doesn't apply to the patch command. Whether or not
135 # we need that built is the responsibility of the patch function / class, not
137 if not bb.data.getVar('INHIBIT_DEFAULT_DEPS', d):
138 if (bb.data.getVar('HOST_SYS', d, 1) !=
139 bb.data.getVar('BUILD_SYS', d, 1)):
140 deps += " virtual/${TARGET_PREFIX}gcc virtual/libc "
143 def base_read_file(filename):
146 f = file( filename, "r" )
147 except IOError, reason:
148 return "" # WARNING: can't raise an error now because of the new RDEPENDS handling. This is a bit ugly. :M:
150 return f.read().strip()
153 def base_conditional(variable, checkvalue, truevalue, falsevalue, d):
155 if bb.data.getVar(variable,d,1) == checkvalue:
160 def base_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
162 if float(bb.data.getVar(variable,d,1)) <= float(checkvalue):
167 def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
169 result = bb.vercmp(bb.data.getVar(variable,d,True), checkvalue)
175 def base_contains(variable, checkvalues, truevalue, falsevalue, d):
178 if type(checkvalues).__name__ == "str":
179 checkvalues = [checkvalues]
180 for value in checkvalues:
181 if bb.data.getVar(variable,d,1).find(value) != -1:
182 matches = matches + 1
183 if matches == len(checkvalues):
187 def base_both_contain(variable1, variable2, checkvalue, d):
189 if bb.data.getVar(variable1,d,1).find(checkvalue) != -1 and bb.data.getVar(variable2,d,1).find(checkvalue) != -1:
194 DEPENDS_prepend="${@base_dep_prepend(d)} "
196 # Returns PN with various suffixes removed
197 # or PN if no matching suffix was found.
198 def base_package_name(d):
201 pn = bb.data.getVar('PN', d, 1)
202 if pn.endswith("-native"):
204 elif pn.endswith("-cross"):
206 elif pn.endswith("-initial"):
208 elif pn.endswith("-intermediate"):
213 def base_set_filespath(path, d):
215 bb.note("base_set_filespath usage is deprecated, %s should be fixed" % d.getVar("P", 1))
217 # The ":" ensures we have an 'empty' override
218 overrides = (bb.data.getVar("OVERRIDES", d, 1) or "") + ":"
220 for o in overrides.split(":"):
221 filespath.append(os.path.join(p, o))
222 return ":".join(filespath)
224 def oe_filter(f, str, d):
226 return " ".join(filter(lambda x: match(f, x, 0), str.split()))
228 def oe_filter_out(f, str, d):
230 return " ".join(filter(lambda x: not match(f, x, 0), str.split()))
251 echo "Usage: oedebug level \"message\""
255 test ${OEDEBUG:-0} -ge $1 && {
262 if [ x"$MAKE" = x ]; then MAKE=make; fi
263 oenote ${MAKE} ${EXTRA_OEMAKE} "$@"
264 ${MAKE} ${EXTRA_OEMAKE} "$@" || die "oe_runmake failed"
268 # Purpose: Install shared library file and
269 # create the necessary links
274 #oenote installing shared library $1 to $2
276 libname=`basename $1`
277 install -m 755 $1 $2/$libname
278 sonamelink=`${HOST_PREFIX}readelf -d $1 |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
279 solink=`echo $libname | sed -e 's/\.so\..*/.so/'`
280 ln -sf $libname $2/$sonamelink
281 ln -sf $libname $2/$solink
285 # Purpose: Install a library, in all its forms
288 # oe_libinstall libltdl ${STAGING_LIBDIR}/
289 # oe_libinstall -C src/libblah libblah ${D}/${libdir}/
296 while [ "$#" -gt 0 ]; do
312 oefatal "oe_libinstall: unknown option: $1"
324 if [ -z "$destpath" ]; then
325 oefatal "oe_libinstall: no destination path specified"
327 if echo "$destpath/" | egrep '^${STAGING_LIBDIR}/' >/dev/null
333 if [ -z "$silent" ]; then
334 echo >&2 "oe_libinstall: $*"
339 if [ -z "$dir" ]; then
345 # Sanity check that the libname.lai is unique
346 number_of_files=`(cd $dir; find . -name "$dotlai") | wc -l`
347 if [ $number_of_files -gt 1 ]; then
348 oefatal "oe_libinstall: $dotlai is not unique in $dir"
352 dir=$dir`(cd $dir;find . -name "$dotlai") | sed "s/^\.//;s/\/$dotlai\$//;q"`
358 # If such file doesn't exist, try to cut version suffix
359 if [ ! -f "$lafile" ]; then
360 libname1=`echo "$libname" | sed 's/-[0-9.]*$//'`
362 if [ -f "$lafile1" ]; then
368 if [ -f "$lafile" ]; then
370 eval `cat $lafile|grep "^library_names="`
373 library_names="$libname.so* $libname.dll.a"
376 __runcmd install -d $destpath/
378 if [ -f "$dota" -o -n "$require_static" ]; then
379 __runcmd install -m 0644 $dota $destpath/
381 if [ -f "$dotlai" -a -n "$libtool" ]; then
382 if test -n "$staging_install"
384 # stop libtool using the final directory name for libraries
386 __runcmd rm -f $destpath/$libname.la
387 __runcmd sed -e 's/^installed=yes$/installed=no/' \
388 -e '/^dependency_libs=/s,${WORKDIR}[[:alnum:]/\._+-]*/\([[:alnum:]\._+-]*\),${STAGING_LIBDIR}/\1,g' \
389 -e "/^dependency_libs=/s,\([[:space:]']\)${libdir},\1${STAGING_LIBDIR},g" \
390 $dotlai >$destpath/$libname.la
392 __runcmd install -m 0644 $dotlai $destpath/$libname.la
396 for name in $library_names; do
397 files=`eval echo $name`
399 if [ ! -e "$f" ]; then
400 if [ -n "$libtool" ]; then
401 oefatal "oe_libinstall: $dir/$f not found."
403 elif [ -L "$f" ]; then
404 __runcmd cp -P "$f" $destpath/
405 elif [ ! -L "$f" ]; then
407 __runcmd install -m 0755 $libfile $destpath/
412 if [ -z "$libfile" ]; then
413 if [ -n "$require_shared" ]; then
414 oefatal "oe_libinstall: unable to locate shared library"
416 elif [ -z "$libtool" ]; then
417 # special case hack for non-libtool .so.#.#.# links
418 baselibfile=`basename "$libfile"`
419 if (echo $baselibfile | grep -qE '^lib.*\.so\.[0-9.]*$'); then
420 sonamelink=`${HOST_PREFIX}readelf -d $libfile |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
421 solink=`echo $baselibfile | sed -e 's/\.so\..*/.so/'`
422 if [ -n "$sonamelink" -a x"$baselibfile" != x"$sonamelink" ]; then
423 __runcmd ln -sf $baselibfile $destpath/$sonamelink
425 __runcmd ln -sf $baselibfile $destpath/$solink
429 __runcmd cd "$olddir"
432 def package_stagefile(file, d):
435 if bb.data.getVar('PSTAGING_ACTIVE', d, True) == "1":
436 destfile = file.replace(bb.data.getVar("TMPDIR", d, 1), bb.data.getVar("PSTAGE_TMPDIR_STAGE", d, 1))
437 bb.mkdirhier(os.path.dirname(destfile))
438 #print "%s to %s" % (file, destfile)
439 bb.copyfile(file, destfile)
441 package_stagefile_shell() {
442 if [ "$PSTAGING_ACTIVE" = "1" ]; then
444 destfile=`echo $srcfile | sed s#${TMPDIR}#${PSTAGE_TMPDIR_STAGE}#`
445 destdir=`dirname $destfile`
447 cp -dp $srcfile $destfile
452 # Purpose: Install machine dependent files, if available
453 # If not available, check if there is a default
454 # If no default, just touch the destination
457 # oe_machinstall -m 0644 fstab ${D}/etc/fstab
459 # TODO: Check argument number?
461 filename=`basename $3`
464 for o in `echo ${OVERRIDES} | tr ':' ' '`; do
465 if [ -e $dirname/$o/$filename ]; then
466 oenote $dirname/$o/$filename present, installing to $4
467 install $1 $2 $dirname/$o/$filename $4
471 # oenote overrides specific file NOT present, trying default=$3...
473 oenote $3 present, installing to $4
476 oenote $3 NOT present, touching empty $4
482 do_listtasks[nostamp] = "1"
483 python do_listtasks() {
485 # emit variables and shell functions
486 #bb.data.emit_env(sys.__stdout__, d)
487 # emit the metadata which isnt valid shell
489 if bb.data.getVarFlag(e, 'task', d):
490 sys.__stdout__.write("%s\n" % e)
494 do_clean[dirs] = "${TOPDIR}"
495 do_clean[nostamp] = "1"
496 python base_do_clean() {
497 """clear the build and temp directories"""
498 dir = bb.data.expand("${WORKDIR}", d)
499 if dir == '//': raise bb.build.FuncFailed("wrong DATADIR")
500 bb.note("removing " + dir)
501 os.system('rm -rf ' + dir)
503 dir = "%s.*" % bb.data.expand(bb.data.getVar('STAMP', d), d)
504 bb.note("removing " + dir)
505 os.system('rm -f '+ dir)
508 #Uncomment this for bitbake 1.8.12
509 #addtask rebuild after do_${BB_DEFAULT_TASK}
511 do_rebuild[dirs] = "${TOPDIR}"
512 do_rebuild[nostamp] = "1"
513 python base_do_rebuild() {
514 """rebuild a package"""
515 from bb import __version__
517 from distutils.version import LooseVersion
519 def LooseVersion(v): print "WARNING: sanity.bbclass can't compare versions without python-distutils"; return 1
520 if (LooseVersion(__version__) < LooseVersion('1.8.11')):
521 bb.build.exec_func('do_clean', d)
522 bb.build.exec_task('do_' + bb.data.getVar('BB_DEFAULT_TASK', d, 1), d)
526 do_mrproper[dirs] = "${TOPDIR}"
527 do_mrproper[nostamp] = "1"
528 python base_do_mrproper() {
529 """clear downloaded sources, build and temp directories"""
530 dir = bb.data.expand("${DL_DIR}", d)
531 if dir == '/': bb.build.FuncFailed("wrong DATADIR")
532 bb.debug(2, "removing " + dir)
533 os.system('rm -rf ' + dir)
534 bb.build.exec_func('do_clean', d)
538 do_distclean[dirs] = "${TOPDIR}"
539 do_distclean[nostamp] = "1"
540 python base_do_distclean() {
541 """clear downloaded sources, build and temp directories"""
544 bb.build.exec_func('do_clean', d)
546 src_uri = bb.data.getVar('SRC_URI', d, 1)
550 for uri in src_uri.split():
551 if bb.decodeurl(uri)[0] == "file":
555 local = bb.data.expand(bb.fetch.localpath(uri, d), d)
556 except bb.MalformedUrl, e:
557 bb.debug(1, 'Unable to generate local path for malformed uri: %s' % e)
559 bb.note("removing %s" % local)
561 if os.path.exists(local + ".md5"):
562 os.remove(local + ".md5")
563 if os.path.exists(local):
566 bb.note("Error in removal: %s" % e)
569 SCENEFUNCS += "base_scenefunction"
571 python base_do_setscene () {
572 for f in (bb.data.getVar('SCENEFUNCS', d, 1) or '').split():
573 bb.build.exec_func(f, d)
574 if not os.path.exists(bb.data.getVar('STAMP', d, 1) + ".do_setscene"):
575 bb.build.make_stamp("do_setscene", d)
577 do_setscene[selfstamp] = "1"
578 addtask setscene before do_fetch
580 python base_scenefunction () {
581 stamp = bb.data.getVar('STAMP', d, 1) + ".needclean"
582 if os.path.exists(stamp):
583 bb.build.exec_func("do_clean", d)
588 do_fetch[dirs] = "${DL_DIR}"
589 do_fetch[depends] = "shasum-native:do_populate_staging"
590 python base_do_fetch() {
593 localdata = bb.data.createCopy(d)
594 bb.data.update_data(localdata)
596 src_uri = bb.data.getVar('SRC_URI', localdata, 1)
601 bb.fetch.init(src_uri.split(),d)
602 except bb.fetch.NoMethodError:
603 (type, value, traceback) = sys.exc_info()
604 raise bb.build.FuncFailed("No method: %s" % value)
607 bb.fetch.go(localdata)
608 except bb.fetch.MissingParameterError:
609 (type, value, traceback) = sys.exc_info()
610 raise bb.build.FuncFailed("Missing parameters: %s" % value)
611 except bb.fetch.FetchError:
612 (type, value, traceback) = sys.exc_info()
613 raise bb.build.FuncFailed("Fetch failed: %s" % value)
614 except bb.fetch.MD5SumError:
615 (type, value, traceback) = sys.exc_info()
616 raise bb.build.FuncFailed("MD5 failed: %s" % value)
618 (type, value, traceback) = sys.exc_info()
619 raise bb.build.FuncFailed("Unknown fetch Error: %s" % value)
622 # Verify the SHA and MD5 sums we have in OE and check what do
624 checksum_paths = bb.data.getVar('BBPATH', d, True).split(":")
626 # reverse the list to give precedence to directories that
627 # appear first in BBPATH
628 checksum_paths.reverse()
630 checksum_files = ["%s/conf/checksums.ini" % path for path in checksum_paths]
632 parser = base_chk_load_parser(checksum_files)
634 bb.note("No conf/checksums.ini found, not checking checksums")
637 bb.note("Creating the CheckSum parser failed")
640 pv = bb.data.getVar('PV', d, True)
641 pn = bb.data.getVar('PN', d, True)
644 for url in src_uri.split():
645 localpath = bb.data.expand(bb.fetch.localpath(url, localdata), localdata)
646 (type,host,path,_,_,_) = bb.decodeurl(url)
647 uri = "%s://%s%s" % (type,host,path)
649 if type == "http" or type == "https" or type == "ftp" or type == "ftps":
650 if not base_chk_file(parser, pn, pv,uri, localpath, d):
651 if not bb.data.getVar("OE_ALLOW_INSECURE_DOWNLOADS",d, True):
652 bb.fatal("%s-%s: %s has no entry in conf/checksums.ini, not checking URI" % (pn,pv,uri))
654 bb.note("%s-%s: %s has no entry in conf/checksums.ini, not checking URI" % (pn,pv,uri))
656 raise bb.build.FuncFailed("Checksum of '%s' failed" % uri)
659 addtask fetchall after do_fetch
660 do_fetchall[recrdeptask] = "do_fetch"
666 do_checkuri[nostamp] = "1"
667 python do_checkuri() {
670 localdata = bb.data.createCopy(d)
671 bb.data.update_data(localdata)
673 src_uri = bb.data.getVar('SRC_URI', localdata, 1)
676 bb.fetch.init(src_uri.split(),d)
677 except bb.fetch.NoMethodError:
678 (type, value, traceback) = sys.exc_info()
679 raise bb.build.FuncFailed("No method: %s" % value)
682 bb.fetch.checkstatus(localdata)
683 except bb.fetch.MissingParameterError:
684 (type, value, traceback) = sys.exc_info()
685 raise bb.build.FuncFailed("Missing parameters: %s" % value)
686 except bb.fetch.FetchError:
687 (type, value, traceback) = sys.exc_info()
688 raise bb.build.FuncFailed("Fetch failed: %s" % value)
689 except bb.fetch.MD5SumError:
690 (type, value, traceback) = sys.exc_info()
691 raise bb.build.FuncFailed("MD5 failed: %s" % value)
693 (type, value, traceback) = sys.exc_info()
694 raise bb.build.FuncFailed("Unknown fetch Error: %s" % value)
697 addtask checkuriall after do_checkuri
698 do_checkuriall[recrdeptask] = "do_checkuri"
699 do_checkuriall[nostamp] = "1"
700 base_do_checkuriall() {
704 addtask buildall after do_build
705 do_buildall[recrdeptask] = "do_build"
711 def oe_unpack_file(file, data, url = None):
714 url = "file://%s" % file
715 dots = file.split(".")
716 if dots[-1] in ['gz', 'bz2', 'Z']:
717 efile = os.path.join(bb.data.getVar('WORKDIR', data, 1),os.path.basename('.'.join(dots[0:-1])))
721 if file.endswith('.tar'):
722 cmd = 'tar x --no-same-owner -f %s' % file
723 elif file.endswith('.tgz') or file.endswith('.tar.gz') or file.endswith('.tar.Z'):
724 cmd = 'tar xz --no-same-owner -f %s' % file
725 elif file.endswith('.tbz') or file.endswith('.tbz2') or file.endswith('.tar.bz2'):
726 cmd = 'bzip2 -dc %s | tar x --no-same-owner -f -' % file
727 elif file.endswith('.gz') or file.endswith('.Z') or file.endswith('.z'):
728 cmd = 'gzip -dc %s > %s' % (file, efile)
729 elif file.endswith('.bz2'):
730 cmd = 'bzip2 -dc %s > %s' % (file, efile)
731 elif file.endswith('.zip') or file.endswith('.jar'):
733 (type, host, path, user, pswd, parm) = bb.decodeurl(url)
736 cmd = '%s %s' % (cmd, file)
737 elif os.path.isdir(file):
739 filespath = bb.data.getVar("FILESPATH", data, 1).split(":")
741 if file[0:len(fp)] == fp:
742 destdir = file[len(fp):file.rfind('/')]
743 destdir = destdir.strip('/')
746 elif not os.access("%s/%s" % (os.getcwd(), destdir), os.F_OK):
747 os.makedirs("%s/%s" % (os.getcwd(), destdir))
750 cmd = 'cp -pPR %s %s/%s/' % (file, os.getcwd(), destdir)
752 (type, host, path, user, pswd, parm) = bb.decodeurl(url)
753 if not 'patch' in parm:
754 # The "destdir" handling was specifically done for FILESPATH
755 # items. So, only do so for file:// entries.
757 destdir = bb.decodeurl(url)[1] or "."
760 bb.mkdirhier("%s/%s" % (os.getcwd(), destdir))
761 cmd = 'cp %s %s/%s/' % (file, os.getcwd(), destdir)
766 dest = os.path.join(os.getcwd(), os.path.basename(file))
767 if os.path.exists(dest):
768 if os.path.samefile(file, dest):
771 # Change to subdir before executing command
772 save_cwd = os.getcwd();
773 parm = bb.decodeurl(url)[5]
775 newdir = ("%s/%s" % (os.getcwd(), parm['subdir']))
779 cmd = "PATH=\"%s\" %s" % (bb.data.getVar('PATH', data, 1), cmd)
780 bb.note("Unpacking %s to %s/" % (file, os.getcwd()))
787 addtask unpack after do_fetch
788 do_unpack[dirs] = "${WORKDIR}"
789 python base_do_unpack() {
792 localdata = bb.data.createCopy(d)
793 bb.data.update_data(localdata)
795 src_uri = bb.data.getVar('SRC_URI', localdata)
798 src_uri = bb.data.expand(src_uri, localdata)
799 for url in src_uri.split():
801 local = bb.data.expand(bb.fetch.localpath(url, localdata), localdata)
802 except bb.MalformedUrl, e:
803 raise bb.build.FuncFailed('Unable to generate local path for malformed uri: %s' % e)
805 raise bb.build.FuncFailed('Unable to locate local file for %s' % url)
806 local = os.path.realpath(local)
807 ret = oe_unpack_file(local, localdata, url)
809 raise bb.build.FuncFailed()
812 METADATA_SCM = "${@base_get_scm(d)}"
813 METADATA_REVISION = "${@base_get_scm_revision(d)}"
814 METADATA_BRANCH = "${@base_get_scm_branch(d)}"
819 baserepo = os.path.dirname(os.path.dirname(which(d.getVar("BBPATH", 1), "classes/base.bbclass")))
820 for (scm, scmpath) in {"svn": ".svn",
822 "monotone": "_MTN"}.iteritems():
823 if os.path.exists(os.path.join(baserepo, scmpath)):
824 return "%s %s" % (scm, baserepo)
825 return "<unknown> %s" % baserepo
827 def base_get_scm_revision(d):
828 (scm, path) = d.getVar("METADATA_SCM", 1).split()
830 if scm != "<unknown>":
831 return globals()["base_get_metadata_%s_revision" % scm](path, d)
837 def base_get_scm_branch(d):
838 (scm, path) = d.getVar("METADATA_SCM", 1).split()
840 if scm != "<unknown>":
841 return globals()["base_get_metadata_%s_branch" % scm](path, d)
847 def base_get_metadata_monotone_branch(path, d):
848 monotone_branch = "<unknown>"
850 monotone_branch = file( "%s/_MTN/options" % path ).read().strip()
851 if monotone_branch.startswith( "database" ):
852 monotone_branch_words = monotone_branch.split()
853 monotone_branch = monotone_branch_words[ monotone_branch_words.index( "branch" )+1][1:-1]
856 return monotone_branch
858 def base_get_metadata_monotone_revision(path, d):
859 monotone_revision = "<unknown>"
861 monotone_revision = file( "%s/_MTN/revision" % path ).read().strip()
862 if monotone_revision.startswith( "format_version" ):
863 monotone_revision_words = monotone_revision.split()
864 monotone_revision = monotone_revision_words[ monotone_revision_words.index( "old_revision" )+1][1:-1]
867 return monotone_revision
869 def base_get_metadata_svn_revision(path, d):
870 revision = "<unknown>"
872 revision = file( "%s/.svn/entries" % path ).readlines()[3].strip()
877 def base_get_metadata_git_branch(path, d):
879 branch = os.popen('cd %s; git symbolic-ref HEAD' % path).read().rstrip()
882 return branch.replace("refs/heads/", "")
885 def base_get_metadata_git_revision(path, d):
887 rev = os.popen("cd %s; git show-ref HEAD" % path).read().split(" ")[0].rstrip()
893 addhandler base_eventhandler
894 python base_eventhandler() {
895 from bb import note, error, data
896 from bb.event import Handled, NotHandled, getName
900 messages["Completed"] = "completed"
901 messages["Succeeded"] = "completed"
902 messages["Started"] = "started"
903 messages["Failed"] = "failed"
907 if name.startswith("Task"):
908 msg += "package %s: task %s: " % (data.getVar("PF", e.data, 1), e.task)
909 msg += messages.get(name[4:]) or name[4:]
910 elif name.startswith("Build"):
911 msg += "build %s: " % e.name
912 msg += messages.get(name[5:]) or name[5:]
913 elif name == "UnsatisfiedDep":
914 msg += "package %s: dependency %s %s" % (e.pkg, e.dep, name[:-3].lower())
918 # Only need to output when using 1.8 or lower, the UI code handles it
920 if (int(bb.__version__.split(".")[0]) <= 1 and int(bb.__version__.split(".")[1]) <= 8):
924 if name.startswith("BuildStarted"):
925 bb.data.setVar( 'BB_VERSION', bb.__version__, e.data )
926 statusvars = bb.data.getVar("BUILDCFG_VARS", e.data, 1).split()
927 statuslines = ["%-17s = \"%s\"" % (i, bb.data.getVar(i, e.data, 1) or '') for i in statusvars]
928 statusmsg = "\nOE Build Configuration:\n%s\n" % '\n'.join(statuslines)
931 needed_vars = bb.data.getVar("BUILDCFG_NEEDEDVARS", e.data, 1).split()
933 for v in needed_vars:
934 val = bb.data.getVar(v, e.data, 1)
935 if not val or val == 'INVALID':
938 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))
941 # Handle removing stamps for 'rebuild' task
943 if name.startswith("StampUpdate"):
944 for (fn, task) in e.targets:
945 #print "%s %s" % (task, fn)
946 if task == "do_rebuild":
947 dir = "%s.*" % e.stampPrefix[fn]
948 bb.note("Removing stamps: " + dir)
949 os.system('rm -f '+ dir)
950 os.system('touch ' + e.stampPrefix[fn] + '.needclean')
952 if not data in e.__dict__:
955 log = data.getVar("EVENTLOG", e.data, 1)
957 logfile = file(log, "a")
958 logfile.write("%s\n" % msg)
964 addtask configure after do_unpack do_patch
965 do_configure[dirs] = "${S} ${B}"
966 do_configure[deptask] = "do_populate_staging"
967 base_do_configure() {
971 addtask compile after do_configure
972 do_compile[dirs] = "${S} ${B}"
974 if [ -e Makefile -o -e makefile ]; then
975 oe_runmake || die "make failed"
977 oenote "nothing to compile"
985 do_populate_staging[dirs] = "${STAGING_DIR_TARGET}/${layout_bindir} ${STAGING_DIR_TARGET}/${layout_libdir} \
986 ${STAGING_DIR_TARGET}/${layout_includedir} \
987 ${STAGING_BINDIR_NATIVE} ${STAGING_LIBDIR_NATIVE} \
988 ${STAGING_INCDIR_NATIVE} \
992 # Could be compile but populate_staging and do_install shouldn't run at the same time
993 addtask populate_staging after do_install
995 python do_populate_staging () {
996 bb.build.exec_func('do_stage', d)
999 addtask install after do_compile
1000 do_install[dirs] = "${D} ${S} ${B}"
1001 # Remove and re-create ${D} so that is it guaranteed to be empty
1002 do_install[cleandirs] = "${D}"
1012 addtask build after do_populate_staging
1014 do_build[func] = "1"
1016 # Functions that update metadata based on files outputted
1017 # during the build process.
1019 def explode_deps(s):
1031 r[-1] += ' ' + ' '.join(j)
1036 def packaged(pkg, d):
1038 return os.access(get_subpkgedata_fn(pkg, d) + '.packaged', os.R_OK)
1040 def read_pkgdatafile(fn):
1045 c = codecs.getdecoder("string_escape")
1049 if os.access(fn, os.R_OK):
1052 lines = f.readlines()
1054 r = re.compile("([^:]+):\s*(.*)")
1058 pkgdata[m.group(1)] = decode(m.group(2))
1062 def get_subpkgedata_fn(pkg, d):
1064 archs = bb.data.expand("${PACKAGE_ARCHS}", d).split(" ")
1066 pkgdata = bb.data.expand('${TMPDIR}/pkgdata/', d)
1067 targetdir = bb.data.expand('${TARGET_VENDOR}-${TARGET_OS}/runtime/', d)
1069 fn = pkgdata + arch + targetdir + pkg
1070 if os.path.exists(fn):
1072 return bb.data.expand('${PKGDATA_DIR}/runtime/%s' % pkg, d)
1074 def has_subpkgdata(pkg, d):
1076 return os.access(get_subpkgedata_fn(pkg, d), os.R_OK)
1078 def read_subpkgdata(pkg, d):
1080 return read_pkgdatafile(get_subpkgedata_fn(pkg, d))
1082 def has_pkgdata(pn, d):
1084 fn = bb.data.expand('${PKGDATA_DIR}/%s' % pn, d)
1085 return os.access(fn, os.R_OK)
1087 def read_pkgdata(pn, d):
1089 fn = bb.data.expand('${PKGDATA_DIR}/%s' % pn, d)
1090 return read_pkgdatafile(fn)
1092 python read_subpackage_metadata () {
1094 data = read_pkgdata(bb.data.getVar('PN', d, 1), d)
1096 for key in data.keys():
1097 bb.data.setVar(key, data[key], d)
1099 for pkg in bb.data.getVar('PACKAGES', d, 1).split():
1100 sdata = read_subpkgdata(pkg, d)
1101 for key in sdata.keys():
1102 bb.data.setVar(key, sdata[key], d)
1107 # Collapse FOO_pkg variables into FOO
1109 def read_subpkgdata_dict(pkg, d):
1112 subd = read_pkgdatafile(get_subpkgedata_fn(pkg, d))
1114 newvar = var.replace("_" + pkg, "")
1115 ret[newvar] = subd[var]
1118 # Make sure MACHINE isn't exported
1119 # (breaks binutils at least)
1120 MACHINE[unexport] = "1"
1122 # Make sure TARGET_ARCH isn't exported
1123 # (breaks Makefiles using implicit rules, e.g. quilt, as GNU make has this
1124 # in them, undocumented)
1125 TARGET_ARCH[unexport] = "1"
1127 # Make sure DISTRO isn't exported
1128 # (breaks sysvinit at least)
1129 DISTRO[unexport] = "1"
1132 def base_after_parse(d):
1133 import bb, os, exceptions
1135 source_mirror_fetch = bb.data.getVar('SOURCE_MIRROR_FETCH', d, 0)
1136 if not source_mirror_fetch:
1137 need_host = bb.data.getVar('COMPATIBLE_HOST', d, 1)
1140 this_host = bb.data.getVar('HOST_SYS', d, 1)
1141 if not re.match(need_host, this_host):
1142 raise bb.parse.SkipPackage("incompatible with host %s" % this_host)
1144 need_machine = bb.data.getVar('COMPATIBLE_MACHINE', d, 1)
1147 this_machine = bb.data.getVar('MACHINE', d, 1)
1148 if this_machine and not re.match(need_machine, this_machine):
1149 raise bb.parse.SkipPackage("incompatible with machine %s" % this_machine)
1151 pn = bb.data.getVar('PN', d, 1)
1153 # OBSOLETE in bitbake 1.7.4
1154 srcdate = bb.data.getVar('SRCDATE_%s' % pn, d, 1)
1156 bb.data.setVar('SRCDATE', srcdate, d)
1158 use_nls = bb.data.getVar('USE_NLS_%s' % pn, d, 1)
1160 bb.data.setVar('USE_NLS', use_nls, d)
1162 # Git packages should DEPEND on git-native
1163 srcuri = bb.data.getVar('SRC_URI', d, 1)
1164 if "git://" in srcuri:
1165 depends = bb.data.getVarFlag('do_fetch', 'depends', d) or ""
1166 depends = depends + " git-native:do_populate_staging"
1167 bb.data.setVarFlag('do_fetch', 'depends', depends, d)
1169 # 'multimachine' handling
1170 mach_arch = bb.data.getVar('MACHINE_ARCH', d, 1)
1171 pkg_arch = bb.data.getVar('PACKAGE_ARCH', d, 1)
1173 if (pkg_arch == mach_arch):
1174 # Already machine specific - nothing further to do
1178 # We always try to scan SRC_URI for urls with machine overrides
1179 # unless the package sets SRC_URI_OVERRIDES_PACKAGE_ARCH=0
1181 override = bb.data.getVar('SRC_URI_OVERRIDES_PACKAGE_ARCH', d, 1)
1184 for p in [ "${PF}", "${P}", "${PN}", "files", "" ]:
1185 path = bb.data.expand(os.path.join("${FILE_DIRNAME}", p, "${MACHINE}"), d)
1186 if os.path.isdir(path):
1189 for s in srcuri.split():
1190 if not s.startswith("file://"):
1192 local = bb.data.expand(bb.fetch.localpath(s, d), d)
1194 if local.startswith(mp):
1195 #bb.note("overriding PACKAGE_ARCH from %s to %s" % (pkg_arch, mach_arch))
1196 bb.data.setVar('PACKAGE_ARCH', "${MACHINE_ARCH}", d)
1197 bb.data.setVar('MULTIMACH_ARCH', mach_arch, d)
1200 multiarch = pkg_arch
1202 packages = bb.data.getVar('PACKAGES', d, 1).split()
1203 for pkg in packages:
1204 pkgarch = bb.data.getVar("PACKAGE_ARCH_%s" % pkg, d, 1)
1206 # We could look for != PACKAGE_ARCH here but how to choose
1207 # if multiple differences are present?
1208 # Look through PACKAGE_ARCHS for the priority order?
1209 if pkgarch and pkgarch == mach_arch:
1210 multiarch = mach_arch
1213 bb.data.setVar('MULTIMACH_ARCH', multiarch, d)
1217 from bb import __version__
1220 # Remove this for bitbake 1.8.12
1222 from distutils.version import LooseVersion
1224 def LooseVersion(v): print "WARNING: sanity.bbclass can't compare versions without python-distutils"; return 1
1225 if (LooseVersion(__version__) >= LooseVersion('1.8.11')):
1226 deps = bb.data.getVarFlag('do_rebuild', 'deps', d) or []
1227 deps.append('do_' + bb.data.getVar('BB_DEFAULT_TASK', d, 1))
1228 bb.data.setVarFlag('do_rebuild', 'deps', deps, d)
1231 def check_app_exists(app, d):
1232 from bb import which, data
1234 app = data.expand(app, d)
1235 path = data.getVar('PATH', d, 1)
1236 return len(which(path, app)) != 0
1238 def check_gcc3(data):
1239 # Primarly used by qemu to make sure we have a workable gcc-3.4.x.
1240 # Start by checking for the program name as we build it, was not
1241 # all host-provided gcc-3.4's will work.
1243 gcc3_versions = 'gcc-3.4.6 gcc-3.4.4 gcc34 gcc-3.4.7 gcc-3.3 gcc33 gcc-3.3.6 gcc-3.2 gcc32'
1245 for gcc3 in gcc3_versions.split():
1246 if check_app_exists(gcc3, data):
1254 # Configuration data from site files
1255 # Move to autotools.bbclass?
1258 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
1262 ${DEBIAN_MIRROR}/main http://snapshot.debian.net/archive/pool
1263 ${DEBIAN_MIRROR} ftp://ftp.de.debian.org/debian/pool
1264 ${DEBIAN_MIRROR} ftp://ftp.au.debian.org/debian/pool
1265 ${DEBIAN_MIRROR} ftp://ftp.cl.debian.org/debian/pool
1266 ${DEBIAN_MIRROR} ftp://ftp.hr.debian.org/debian/pool
1267 ${DEBIAN_MIRROR} ftp://ftp.fi.debian.org/debian/pool
1268 ${DEBIAN_MIRROR} ftp://ftp.hk.debian.org/debian/pool
1269 ${DEBIAN_MIRROR} ftp://ftp.hu.debian.org/debian/pool
1270 ${DEBIAN_MIRROR} ftp://ftp.ie.debian.org/debian/pool
1271 ${DEBIAN_MIRROR} ftp://ftp.it.debian.org/debian/pool
1272 ${DEBIAN_MIRROR} ftp://ftp.jp.debian.org/debian/pool
1273 ${DEBIAN_MIRROR} ftp://ftp.no.debian.org/debian/pool
1274 ${DEBIAN_MIRROR} ftp://ftp.pl.debian.org/debian/pool
1275 ${DEBIAN_MIRROR} ftp://ftp.ro.debian.org/debian/pool
1276 ${DEBIAN_MIRROR} ftp://ftp.si.debian.org/debian/pool
1277 ${DEBIAN_MIRROR} ftp://ftp.es.debian.org/debian/pool
1278 ${DEBIAN_MIRROR} ftp://ftp.se.debian.org/debian/pool
1279 ${DEBIAN_MIRROR} ftp://ftp.tr.debian.org/debian/pool
1280 ${GNU_MIRROR} ftp://mirrors.kernel.org/gnu
1281 ${GNU_MIRROR} ftp://ftp.matrix.com.br/pub/gnu
1282 ${GNU_MIRROR} ftp://ftp.cs.ubc.ca/mirror2/gnu
1283 ${GNU_MIRROR} ftp://sunsite.ust.hk/pub/gnu
1284 ${GNU_MIRROR} ftp://ftp.ayamura.org/pub/gnu
1285 ${KERNELORG_MIRROR} http://www.kernel.org/pub
1286 ${KERNELORG_MIRROR} ftp://ftp.us.kernel.org/pub
1287 ${KERNELORG_MIRROR} ftp://ftp.uk.kernel.org/pub
1288 ${KERNELORG_MIRROR} ftp://ftp.hk.kernel.org/pub
1289 ${KERNELORG_MIRROR} ftp://ftp.au.kernel.org/pub
1290 ${KERNELORG_MIRROR} ftp://ftp.jp.kernel.org/pub
1291 ftp://ftp.gnupg.org/gcrypt/ ftp://ftp.franken.de/pub/crypt/mirror/ftp.gnupg.org/gcrypt/
1292 ftp://ftp.gnupg.org/gcrypt/ ftp://ftp.surfnet.nl/pub/security/gnupg/
1293 ftp://ftp.gnupg.org/gcrypt/ http://gulus.USherbrooke.ca/pub/appl/GnuPG/
1294 ftp://dante.ctan.org/tex-archive ftp://ftp.fu-berlin.de/tex/CTAN
1295 ftp://dante.ctan.org/tex-archive http://sunsite.sut.ac.jp/pub/archives/ctan/
1296 ftp://dante.ctan.org/tex-archive http://ctan.unsw.edu.au/
1297 ftp://ftp.gnutls.org/pub/gnutls ftp://ftp.gnutls.org/pub/gnutls/
1298 ftp://ftp.gnutls.org/pub/gnutls ftp://ftp.gnupg.org/gcrypt/gnutls/
1299 ftp://ftp.gnutls.org/pub/gnutls http://www.mirrors.wiretapped.net/security/network-security/gnutls/
1300 ftp://ftp.gnutls.org/pub/gnutls ftp://ftp.mirrors.wiretapped.net/pub/security/network-security/gnutls/
1301 ftp://ftp.gnutls.org/pub/gnutls http://josefsson.org/gnutls/releases/
1302 http://ftp.info-zip.org/pub/infozip/src/ http://mirror.switch.ch/ftp/mirror/infozip/src/
1303 http://ftp.info-zip.org/pub/infozip/src/ ftp://sunsite.icm.edu.pl/pub/unix/archiving/info-zip/src/
1304 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.cerias.purdue.edu/pub/tools/unix/sysutils/lsof/
1305 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.tau.ac.il/pub/unix/admin/
1306 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.cert.dfn.de/pub/tools/admin/lsof/
1307 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.fu-berlin.de/pub/unix/tools/lsof/
1308 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.kaizo.org/pub/lsof/
1309 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.tu-darmstadt.de/pub/sysadmin/lsof/
1310 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.tux.org/pub/sites/vic.cc.purdue.edu/tools/unix/lsof/
1311 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://gd.tuwien.ac.at/utils/admin-tools/lsof/
1312 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://sunsite.ualberta.ca/pub/Mirror/lsof/
1313 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://the.wiretapped.net/pub/security/host-security/lsof/
1314 http://www.apache.org/dist http://archive.apache.org/dist