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_ifelse(condition, iftrue = True, iffalse = False):
168 def base_conditional(variable, checkvalue, truevalue, falsevalue, d):
170 if bb.data.getVar(variable,d,1) == checkvalue:
175 def base_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
177 if float(bb.data.getVar(variable,d,1)) <= float(checkvalue):
182 def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
184 result = bb.vercmp(bb.data.getVar(variable,d,True), checkvalue)
190 def base_contains(variable, checkvalues, truevalue, falsevalue, d):
193 if type(checkvalues).__name__ == "str":
194 checkvalues = [checkvalues]
195 for value in checkvalues:
196 if bb.data.getVar(variable,d,1).find(value) != -1:
197 matches = matches + 1
198 if matches == len(checkvalues):
202 def base_both_contain(variable1, variable2, checkvalue, d):
204 if bb.data.getVar(variable1,d,1).find(checkvalue) != -1 and bb.data.getVar(variable2,d,1).find(checkvalue) != -1:
209 DEPENDS_prepend="${@base_dep_prepend(d)} "
211 # Returns PN with various suffixes removed
212 # or PN if no matching suffix was found.
213 def base_package_name(d):
216 pn = bb.data.getVar('PN', d, 1)
217 if pn.endswith("-native"):
219 elif pn.endswith("-cross"):
221 elif pn.endswith("-initial"):
223 elif pn.endswith("-intermediate"):
225 elif pn.endswith("-sdk"):
231 def base_set_filespath(path, d):
233 bb.note("base_set_filespath usage is deprecated, %s should be fixed" % d.getVar("P", 1))
235 # The ":" ensures we have an 'empty' override
236 overrides = (bb.data.getVar("OVERRIDES", d, 1) or "") + ":"
238 for o in overrides.split(":"):
239 filespath.append(os.path.join(p, o))
240 return ":".join(filespath)
242 def oe_filter(f, str, d):
244 return " ".join(filter(lambda x: match(f, x, 0), str.split()))
246 def oe_filter_out(f, str, d):
248 return " ".join(filter(lambda x: not match(f, x, 0), str.split()))
269 echo "Usage: oedebug level \"message\""
273 test ${OEDEBUG:-0} -ge $1 && {
280 if [ x"$MAKE" = x ]; then MAKE=make; fi
281 oenote ${MAKE} ${EXTRA_OEMAKE} "$@"
282 ${MAKE} ${EXTRA_OEMAKE} "$@" || die "oe_runmake failed"
286 # Purpose: Install shared library file and
287 # create the necessary links
292 #oenote installing shared library $1 to $2
294 libname=`basename $1`
295 install -m 755 $1 $2/$libname
296 sonamelink=`${HOST_PREFIX}readelf -d $1 |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
297 solink=`echo $libname | sed -e 's/\.so\..*/.so/'`
298 ln -sf $libname $2/$sonamelink
299 ln -sf $libname $2/$solink
303 # Purpose: Install a library, in all its forms
306 # oe_libinstall libltdl ${STAGING_LIBDIR}/
307 # oe_libinstall -C src/libblah libblah ${D}/${libdir}/
314 while [ "$#" -gt 0 ]; do
330 oefatal "oe_libinstall: unknown option: $1"
342 if [ -z "$destpath" ]; then
343 oefatal "oe_libinstall: no destination path specified"
345 if echo "$destpath/" | egrep '^${STAGING_LIBDIR}/' >/dev/null
351 if [ -z "$silent" ]; then
352 echo >&2 "oe_libinstall: $*"
357 if [ -z "$dir" ]; then
363 # Sanity check that the libname.lai is unique
364 number_of_files=`(cd $dir; find . -name "$dotlai") | wc -l`
365 if [ $number_of_files -gt 1 ]; then
366 oefatal "oe_libinstall: $dotlai is not unique in $dir"
370 dir=$dir`(cd $dir;find . -name "$dotlai") | sed "s/^\.//;s/\/$dotlai\$//;q"`
376 # If such file doesn't exist, try to cut version suffix
377 if [ ! -f "$lafile" ]; then
378 libname1=`echo "$libname" | sed 's/-[0-9.]*$//'`
380 if [ -f "$lafile1" ]; then
386 if [ -f "$lafile" ]; then
388 eval `cat $lafile|grep "^library_names="`
391 library_names="$libname.so* $libname.dll.a"
394 __runcmd install -d $destpath/
396 if [ -f "$dota" -o -n "$require_static" ]; then
397 __runcmd install -m 0644 $dota $destpath/
399 if [ -f "$dotlai" -a -n "$libtool" ]; then
400 if test -n "$staging_install"
402 # stop libtool using the final directory name for libraries
404 __runcmd rm -f $destpath/$libname.la
405 __runcmd sed -e 's/^installed=yes$/installed=no/' \
406 -e '/^dependency_libs=/s,${WORKDIR}[[:alnum:]/\._+-]*/\([[:alnum:]\._+-]*\),${STAGING_LIBDIR}/\1,g' \
407 -e "/^dependency_libs=/s,\([[:space:]']\)${libdir},\1${STAGING_LIBDIR},g" \
408 $dotlai >$destpath/$libname.la
410 __runcmd install -m 0644 $dotlai $destpath/$libname.la
414 for name in $library_names; do
415 files=`eval echo $name`
417 if [ ! -e "$f" ]; then
418 if [ -n "$libtool" ]; then
419 oefatal "oe_libinstall: $dir/$f not found."
421 elif [ -L "$f" ]; then
422 __runcmd cp -P "$f" $destpath/
423 elif [ ! -L "$f" ]; then
425 __runcmd install -m 0755 $libfile $destpath/
430 if [ -z "$libfile" ]; then
431 if [ -n "$require_shared" ]; then
432 oefatal "oe_libinstall: unable to locate shared library"
434 elif [ -z "$libtool" ]; then
435 # special case hack for non-libtool .so.#.#.# links
436 baselibfile=`basename "$libfile"`
437 if (echo $baselibfile | grep -qE '^lib.*\.so\.[0-9.]*$'); then
438 sonamelink=`${HOST_PREFIX}readelf -d $libfile |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
439 solink=`echo $baselibfile | sed -e 's/\.so\..*/.so/'`
440 if [ -n "$sonamelink" -a x"$baselibfile" != x"$sonamelink" ]; then
441 __runcmd ln -sf $baselibfile $destpath/$sonamelink
443 __runcmd ln -sf $baselibfile $destpath/$solink
447 __runcmd cd "$olddir"
450 def package_stagefile(file, d):
453 if bb.data.getVar('PSTAGING_ACTIVE', d, True) == "1":
454 destfile = file.replace(bb.data.getVar("TMPDIR", d, 1), bb.data.getVar("PSTAGE_TMPDIR_STAGE", d, 1))
455 bb.mkdirhier(os.path.dirname(destfile))
456 #print "%s to %s" % (file, destfile)
457 bb.copyfile(file, destfile)
459 package_stagefile_shell() {
460 if [ "$PSTAGING_ACTIVE" = "1" ]; then
462 destfile=`echo $srcfile | sed s#${TMPDIR}#${PSTAGE_TMPDIR_STAGE}#`
463 destdir=`dirname $destfile`
465 cp -dp $srcfile $destfile
470 # Purpose: Install machine dependent files, if available
471 # If not available, check if there is a default
472 # If no default, just touch the destination
475 # oe_machinstall -m 0644 fstab ${D}/etc/fstab
477 # TODO: Check argument number?
479 filename=`basename $3`
482 for o in `echo ${OVERRIDES} | tr ':' ' '`; do
483 if [ -e $dirname/$o/$filename ]; then
484 oenote $dirname/$o/$filename present, installing to $4
485 install $1 $2 $dirname/$o/$filename $4
489 # oenote overrides specific file NOT present, trying default=$3...
491 oenote $3 present, installing to $4
494 oenote $3 NOT present, touching empty $4
500 do_listtasks[nostamp] = "1"
501 python do_listtasks() {
503 # emit variables and shell functions
504 #bb.data.emit_env(sys.__stdout__, d)
505 # emit the metadata which isnt valid shell
507 if bb.data.getVarFlag(e, 'task', d):
508 sys.__stdout__.write("%s\n" % e)
512 do_clean[dirs] = "${TOPDIR}"
513 do_clean[nostamp] = "1"
514 python base_do_clean() {
515 """clear the build and temp directories"""
516 dir = bb.data.expand("${WORKDIR}", d)
517 if dir == '//': raise bb.build.FuncFailed("wrong DATADIR")
518 bb.note("removing " + base_path_out(dir, d))
519 os.system('rm -rf ' + dir)
521 dir = "%s.*" % bb.data.expand(bb.data.getVar('STAMP', d), d)
522 bb.note("removing " + base_path_out(dir, d))
523 os.system('rm -f '+ dir)
526 #Uncomment this for bitbake 1.8.12
527 #addtask rebuild after do_${BB_DEFAULT_TASK}
529 do_rebuild[dirs] = "${TOPDIR}"
530 do_rebuild[nostamp] = "1"
531 python base_do_rebuild() {
532 """rebuild a package"""
533 from bb import __version__
535 from distutils.version import LooseVersion
537 def LooseVersion(v): print "WARNING: sanity.bbclass can't compare versions without python-distutils"; return 1
538 if (LooseVersion(__version__) < LooseVersion('1.8.11')):
539 bb.build.exec_func('do_clean', d)
540 bb.build.exec_task('do_' + bb.data.getVar('BB_DEFAULT_TASK', d, 1), d)
544 do_mrproper[dirs] = "${TOPDIR}"
545 do_mrproper[nostamp] = "1"
546 python base_do_mrproper() {
547 """clear downloaded sources, build and temp directories"""
548 dir = bb.data.expand("${DL_DIR}", d)
549 if dir == '/': bb.build.FuncFailed("wrong DATADIR")
550 bb.debug(2, "removing " + dir)
551 os.system('rm -rf ' + dir)
552 bb.build.exec_func('do_clean', d)
556 do_distclean[dirs] = "${TOPDIR}"
557 do_distclean[nostamp] = "1"
558 python base_do_distclean() {
559 """clear downloaded sources, build and temp directories"""
562 bb.build.exec_func('do_clean', d)
564 src_uri = bb.data.getVar('SRC_URI', d, 1)
568 for uri in src_uri.split():
569 if bb.decodeurl(uri)[0] == "file":
573 local = bb.data.expand(bb.fetch.localpath(uri, d), d)
574 except bb.MalformedUrl, e:
575 bb.debug(1, 'Unable to generate local path for malformed uri: %s' % e)
577 bb.note("removing %s" % base_path_out(local, d))
579 if os.path.exists(local + ".md5"):
580 os.remove(local + ".md5")
581 if os.path.exists(local):
584 bb.note("Error in removal: %s" % e)
587 SCENEFUNCS += "base_scenefunction"
589 python base_do_setscene () {
590 for f in (bb.data.getVar('SCENEFUNCS', d, 1) or '').split():
591 bb.build.exec_func(f, d)
592 if not os.path.exists(bb.data.getVar('STAMP', d, 1) + ".do_setscene"):
593 bb.build.make_stamp("do_setscene", d)
595 do_setscene[selfstamp] = "1"
596 addtask setscene before do_fetch
598 python base_scenefunction () {
599 stamp = bb.data.getVar('STAMP', d, 1) + ".needclean"
600 if os.path.exists(stamp):
601 bb.build.exec_func("do_clean", d)
606 do_fetch[dirs] = "${DL_DIR}"
607 do_fetch[depends] = "shasum-native:do_populate_staging"
608 python base_do_fetch() {
611 localdata = bb.data.createCopy(d)
612 bb.data.update_data(localdata)
614 src_uri = bb.data.getVar('SRC_URI', localdata, 1)
619 bb.fetch.init(src_uri.split(),d)
620 except bb.fetch.NoMethodError:
621 (type, value, traceback) = sys.exc_info()
622 raise bb.build.FuncFailed("No method: %s" % value)
623 except bb.MalformedUrl:
624 (type, value, traceback) = sys.exc_info()
625 raise bb.build.FuncFailed("Malformed URL: %s" % value)
628 bb.fetch.go(localdata)
629 except bb.fetch.MissingParameterError:
630 (type, value, traceback) = sys.exc_info()
631 raise bb.build.FuncFailed("Missing parameters: %s" % value)
632 except bb.fetch.FetchError:
633 (type, value, traceback) = sys.exc_info()
634 raise bb.build.FuncFailed("Fetch failed: %s" % value)
635 except bb.fetch.MD5SumError:
636 (type, value, traceback) = sys.exc_info()
637 raise bb.build.FuncFailed("MD5 failed: %s" % value)
639 (type, value, traceback) = sys.exc_info()
640 raise bb.build.FuncFailed("Unknown fetch Error: %s" % value)
643 # Verify the SHA and MD5 sums we have in OE and check what do
645 checksum_paths = bb.data.getVar('BBPATH', d, True).split(":")
647 # reverse the list to give precedence to directories that
648 # appear first in BBPATH
649 checksum_paths.reverse()
651 checksum_files = ["%s/conf/checksums.ini" % path for path in checksum_paths]
653 parser = base_chk_load_parser(checksum_files)
655 bb.note("No conf/checksums.ini found, not checking checksums")
658 bb.note("Creating the CheckSum parser failed")
661 pv = bb.data.getVar('PV', d, True)
662 pn = bb.data.getVar('PN', d, True)
665 for url in src_uri.split():
666 localpath = bb.data.expand(bb.fetch.localpath(url, localdata), localdata)
667 (type,host,path,_,_,_) = bb.decodeurl(url)
668 uri = "%s://%s%s" % (type,host,path)
670 if type == "http" or type == "https" or type == "ftp" or type == "ftps":
671 if not base_chk_file(parser, pn, pv,uri, localpath, d):
672 if not bb.data.getVar("OE_ALLOW_INSECURE_DOWNLOADS",d, True):
673 bb.fatal("%s-%s: %s has no entry in conf/checksums.ini, not checking URI" % (pn,pv,uri))
675 bb.note("%s-%s: %s has no entry in conf/checksums.ini, not checking URI" % (pn,pv,uri))
677 raise bb.build.FuncFailed("Checksum of '%s' failed" % uri)
680 addtask fetchall after do_fetch
681 do_fetchall[recrdeptask] = "do_fetch"
687 do_checkuri[nostamp] = "1"
688 python do_checkuri() {
691 localdata = bb.data.createCopy(d)
692 bb.data.update_data(localdata)
694 src_uri = bb.data.getVar('SRC_URI', localdata, 1)
697 bb.fetch.init(src_uri.split(),d)
698 except bb.fetch.NoMethodError:
699 (type, value, traceback) = sys.exc_info()
700 raise bb.build.FuncFailed("No method: %s" % value)
703 bb.fetch.checkstatus(localdata)
704 except bb.fetch.MissingParameterError:
705 (type, value, traceback) = sys.exc_info()
706 raise bb.build.FuncFailed("Missing parameters: %s" % value)
707 except bb.fetch.FetchError:
708 (type, value, traceback) = sys.exc_info()
709 raise bb.build.FuncFailed("Fetch failed: %s" % value)
710 except bb.fetch.MD5SumError:
711 (type, value, traceback) = sys.exc_info()
712 raise bb.build.FuncFailed("MD5 failed: %s" % value)
714 (type, value, traceback) = sys.exc_info()
715 raise bb.build.FuncFailed("Unknown fetch Error: %s" % value)
718 addtask checkuriall after do_checkuri
719 do_checkuriall[recrdeptask] = "do_checkuri"
720 do_checkuriall[nostamp] = "1"
721 base_do_checkuriall() {
725 addtask buildall after do_build
726 do_buildall[recrdeptask] = "do_build"
731 def subprocess_setup():
732 import signal, subprocess
733 # Python installs a SIGPIPE handler by default. This is usually not what
734 # non-Python subprocesses expect.
735 signal.signal(signal.SIGPIPE, signal.SIG_DFL)
737 def oe_unpack_file(file, data, url = None):
738 import bb, os, signal, subprocess
740 url = "file://%s" % file
741 dots = file.split(".")
742 if dots[-1] in ['gz', 'bz2', 'Z']:
743 efile = os.path.join(bb.data.getVar('WORKDIR', data, 1),os.path.basename('.'.join(dots[0:-1])))
747 if file.endswith('.tar'):
748 cmd = 'tar x --no-same-owner -f %s' % file
749 elif file.endswith('.tgz') or file.endswith('.tar.gz') or file.endswith('.tar.Z'):
750 cmd = 'tar xz --no-same-owner -f %s' % file
751 elif file.endswith('.tbz') or file.endswith('.tbz2') or file.endswith('.tar.bz2'):
752 cmd = 'bzip2 -dc %s | tar x --no-same-owner -f -' % file
753 elif file.endswith('.gz') or file.endswith('.Z') or file.endswith('.z'):
754 cmd = 'gzip -dc %s > %s' % (file, efile)
755 elif file.endswith('.bz2'):
756 cmd = 'bzip2 -dc %s > %s' % (file, efile)
757 elif file.endswith('.zip') or file.endswith('.jar'):
759 (type, host, path, user, pswd, parm) = bb.decodeurl(url)
762 cmd = '%s %s' % (cmd, file)
763 elif os.path.isdir(file):
765 filespath = bb.data.getVar("FILESPATH", data, 1).split(":")
767 if file[0:len(fp)] == fp:
768 destdir = file[len(fp):file.rfind('/')]
769 destdir = destdir.strip('/')
772 elif not os.access("%s/%s" % (os.getcwd(), destdir), os.F_OK):
773 os.makedirs("%s/%s" % (os.getcwd(), destdir))
776 cmd = 'cp -pPR %s %s/%s/' % (file, os.getcwd(), destdir)
778 (type, host, path, user, pswd, parm) = bb.decodeurl(url)
779 if not 'patch' in parm:
780 # The "destdir" handling was specifically done for FILESPATH
781 # items. So, only do so for file:// entries.
783 destdir = bb.decodeurl(url)[1] or "."
786 bb.mkdirhier("%s/%s" % (os.getcwd(), destdir))
787 cmd = 'cp %s %s/%s/' % (file, os.getcwd(), destdir)
792 dest = os.path.join(os.getcwd(), os.path.basename(file))
793 if os.path.exists(dest):
794 if os.path.samefile(file, dest):
797 # Change to subdir before executing command
798 save_cwd = os.getcwd();
799 parm = bb.decodeurl(url)[5]
801 newdir = ("%s/%s" % (os.getcwd(), parm['subdir']))
805 cmd = "PATH=\"%s\" %s" % (bb.data.getVar('PATH', data, 1), cmd)
806 bb.note("Unpacking %s to %s/" % (base_path_out(file, data), base_path_out(os.getcwd(), data)))
807 ret = subprocess.call(cmd, preexec_fn=subprocess_setup, shell=True)
813 addtask unpack after do_fetch
814 do_unpack[dirs] = "${WORKDIR}"
815 python base_do_unpack() {
818 localdata = bb.data.createCopy(d)
819 bb.data.update_data(localdata)
821 src_uri = bb.data.getVar('SRC_URI', localdata)
824 src_uri = bb.data.expand(src_uri, localdata)
825 for url in src_uri.split():
827 local = bb.data.expand(bb.fetch.localpath(url, localdata), localdata)
828 except bb.MalformedUrl, e:
829 raise bb.build.FuncFailed('Unable to generate local path for malformed uri: %s' % e)
831 raise bb.build.FuncFailed('Unable to locate local file for %s' % url)
832 local = os.path.realpath(local)
833 ret = oe_unpack_file(local, localdata, url)
835 raise bb.build.FuncFailed()
838 METADATA_SCM = "${@base_get_scm(d)}"
839 METADATA_REVISION = "${@base_get_scm_revision(d)}"
840 METADATA_BRANCH = "${@base_get_scm_branch(d)}"
845 baserepo = os.path.dirname(os.path.dirname(which(d.getVar("BBPATH", 1), "classes/base.bbclass")))
846 for (scm, scmpath) in {"svn": ".svn",
848 "monotone": "_MTN"}.iteritems():
849 if os.path.exists(os.path.join(baserepo, scmpath)):
850 return "%s %s" % (scm, baserepo)
851 return "<unknown> %s" % baserepo
853 def base_get_scm_revision(d):
854 (scm, path) = d.getVar("METADATA_SCM", 1).split()
856 if scm != "<unknown>":
857 return globals()["base_get_metadata_%s_revision" % scm](path, d)
863 def base_get_scm_branch(d):
864 (scm, path) = d.getVar("METADATA_SCM", 1).split()
866 if scm != "<unknown>":
867 return globals()["base_get_metadata_%s_branch" % scm](path, d)
873 def base_get_metadata_monotone_branch(path, d):
874 monotone_branch = "<unknown>"
876 monotone_branch = file( "%s/_MTN/options" % path ).read().strip()
877 if monotone_branch.startswith( "database" ):
878 monotone_branch_words = monotone_branch.split()
879 monotone_branch = monotone_branch_words[ monotone_branch_words.index( "branch" )+1][1:-1]
882 return monotone_branch
884 def base_get_metadata_monotone_revision(path, d):
885 monotone_revision = "<unknown>"
887 monotone_revision = file( "%s/_MTN/revision" % path ).read().strip()
888 if monotone_revision.startswith( "format_version" ):
889 monotone_revision_words = monotone_revision.split()
890 monotone_revision = monotone_revision_words[ monotone_revision_words.index( "old_revision" )+1][1:-1]
893 return monotone_revision
895 def base_get_metadata_svn_revision(path, d):
896 revision = "<unknown>"
898 revision = file( "%s/.svn/entries" % path ).readlines()[3].strip()
903 def base_get_metadata_git_branch(path, d):
905 branch = os.popen('cd %s; PATH=%s git symbolic-ref HEAD 2>/dev/null' % (path, d.getVar("PATH", 1))).read().rstrip()
908 return branch.replace("refs/heads/", "")
911 def base_get_metadata_git_revision(path, d):
913 rev = os.popen("cd %s; PATH=%s git show-ref HEAD 2>/dev/null" % (path, d.getVar("PATH", 1))).read().split(" ")[0].rstrip()
919 addhandler base_eventhandler
920 python base_eventhandler() {
921 from bb import note, error, data
922 from bb.event import Handled, NotHandled, getName
926 if name == "TaskCompleted":
927 msg = "package %s: task %s is complete." % (data.getVar("PF", e.data, 1), e.task)
928 elif name == "UnsatisfiedDep":
929 msg = "package %s: dependency %s %s" % (e.pkg, e.dep, name[:-3].lower())
933 # Only need to output when using 1.8 or lower, the UI code handles it
935 if (int(bb.__version__.split(".")[0]) <= 1 and int(bb.__version__.split(".")[1]) <= 8):
939 if name.startswith("BuildStarted"):
940 bb.data.setVar( 'BB_VERSION', bb.__version__, e.data )
941 statusvars = bb.data.getVar("BUILDCFG_VARS", e.data, 1).split()
942 statuslines = ["%-17s = \"%s\"" % (i, bb.data.getVar(i, e.data, 1) or '') for i in statusvars]
943 statusmsg = "\n%s\n%s\n" % (bb.data.getVar("BUILDCFG_HEADER", e.data, 1), "\n".join(statuslines))
946 needed_vars = bb.data.getVar("BUILDCFG_NEEDEDVARS", e.data, 1).split()
948 for v in needed_vars:
949 val = bb.data.getVar(v, e.data, 1)
950 if not val or val == 'INVALID':
953 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))
956 # Handle removing stamps for 'rebuild' task
958 if name.startswith("StampUpdate"):
959 for (fn, task) in e.targets:
960 #print "%s %s" % (task, fn)
961 if task == "do_rebuild":
962 dir = "%s.*" % e.stampPrefix[fn]
963 bb.note("Removing stamps: " + dir)
964 os.system('rm -f '+ dir)
965 os.system('touch ' + e.stampPrefix[fn] + '.needclean')
967 if not data in e.__dict__:
970 log = data.getVar("EVENTLOG", e.data, 1)
972 logfile = file(log, "a")
973 logfile.write("%s\n" % msg)
979 addtask configure after do_unpack do_patch
980 do_configure[dirs] = "${S} ${B}"
981 do_configure[deptask] = "do_populate_staging"
982 base_do_configure() {
986 addtask compile after do_configure
987 do_compile[dirs] = "${S} ${B}"
989 if [ -e Makefile -o -e makefile ]; then
990 oe_runmake || die "make failed"
992 oenote "nothing to compile"
1000 do_populate_staging[dirs] = "${STAGING_DIR_TARGET}/${layout_bindir} ${STAGING_DIR_TARGET}/${layout_libdir} \
1001 ${STAGING_DIR_TARGET}/${layout_includedir} \
1002 ${STAGING_BINDIR_NATIVE} ${STAGING_LIBDIR_NATIVE} \
1003 ${STAGING_INCDIR_NATIVE} \
1004 ${STAGING_DATADIR} \
1007 # Could be compile but populate_staging and do_install shouldn't run at the same time
1008 addtask populate_staging after do_install
1010 python do_populate_staging () {
1011 bb.build.exec_func('do_stage', d)
1014 addtask install after do_compile
1015 do_install[dirs] = "${D} ${S} ${B}"
1016 # Remove and re-create ${D} so that is it guaranteed to be empty
1017 do_install[cleandirs] = "${D}"
1027 addtask build after do_populate_staging
1029 do_build[func] = "1"
1031 # Functions that update metadata based on files outputted
1032 # during the build process.
1034 def explode_deps(s):
1046 r[-1] += ' ' + ' '.join(j)
1051 def packaged(pkg, d):
1053 return os.access(get_subpkgedata_fn(pkg, d) + '.packaged', os.R_OK)
1055 def read_pkgdatafile(fn):
1060 c = codecs.getdecoder("string_escape")
1064 if os.access(fn, os.R_OK):
1067 lines = f.readlines()
1069 r = re.compile("([^:]+):\s*(.*)")
1073 pkgdata[m.group(1)] = decode(m.group(2))
1077 def get_subpkgedata_fn(pkg, d):
1079 archs = bb.data.expand("${PACKAGE_ARCHS}", d).split(" ")
1081 pkgdata = bb.data.expand('${TMPDIR}/pkgdata/', d)
1082 targetdir = bb.data.expand('${TARGET_VENDOR}-${TARGET_OS}/runtime/', d)
1084 fn = pkgdata + arch + targetdir + pkg
1085 if os.path.exists(fn):
1087 return bb.data.expand('${PKGDATA_DIR}/runtime/%s' % pkg, d)
1089 def has_subpkgdata(pkg, d):
1091 return os.access(get_subpkgedata_fn(pkg, d), os.R_OK)
1093 def read_subpkgdata(pkg, d):
1095 return read_pkgdatafile(get_subpkgedata_fn(pkg, d))
1097 def has_pkgdata(pn, d):
1099 fn = bb.data.expand('${PKGDATA_DIR}/%s' % pn, d)
1100 return os.access(fn, os.R_OK)
1102 def read_pkgdata(pn, d):
1104 fn = bb.data.expand('${PKGDATA_DIR}/%s' % pn, d)
1105 return read_pkgdatafile(fn)
1107 python read_subpackage_metadata () {
1109 data = read_pkgdata(bb.data.getVar('PN', d, 1), d)
1111 for key in data.keys():
1112 bb.data.setVar(key, data[key], d)
1114 for pkg in bb.data.getVar('PACKAGES', d, 1).split():
1115 sdata = read_subpkgdata(pkg, d)
1116 for key in sdata.keys():
1117 bb.data.setVar(key, sdata[key], d)
1122 # Collapse FOO_pkg variables into FOO
1124 def read_subpkgdata_dict(pkg, d):
1127 subd = read_pkgdatafile(get_subpkgedata_fn(pkg, d))
1129 newvar = var.replace("_" + pkg, "")
1130 ret[newvar] = subd[var]
1133 # Make sure MACHINE isn't exported
1134 # (breaks binutils at least)
1135 MACHINE[unexport] = "1"
1137 # Make sure TARGET_ARCH isn't exported
1138 # (breaks Makefiles using implicit rules, e.g. quilt, as GNU make has this
1139 # in them, undocumented)
1140 TARGET_ARCH[unexport] = "1"
1142 # Make sure DISTRO isn't exported
1143 # (breaks sysvinit at least)
1144 DISTRO[unexport] = "1"
1147 def base_after_parse(d):
1148 import bb, os, exceptions
1150 source_mirror_fetch = bb.data.getVar('SOURCE_MIRROR_FETCH', d, 0)
1151 if not source_mirror_fetch:
1152 need_host = bb.data.getVar('COMPATIBLE_HOST', d, 1)
1155 this_host = bb.data.getVar('HOST_SYS', d, 1)
1156 if not re.match(need_host, this_host):
1157 raise bb.parse.SkipPackage("incompatible with host %s" % this_host)
1159 need_machine = bb.data.getVar('COMPATIBLE_MACHINE', d, 1)
1162 this_machine = bb.data.getVar('MACHINE', d, 1)
1163 if this_machine and not re.match(need_machine, this_machine):
1164 raise bb.parse.SkipPackage("incompatible with machine %s" % this_machine)
1166 pn = bb.data.getVar('PN', d, 1)
1168 # OBSOLETE in bitbake 1.7.4
1169 srcdate = bb.data.getVar('SRCDATE_%s' % pn, d, 1)
1171 bb.data.setVar('SRCDATE', srcdate, d)
1173 use_nls = bb.data.getVar('USE_NLS_%s' % pn, d, 1)
1175 bb.data.setVar('USE_NLS', use_nls, d)
1177 # Git packages should DEPEND on git-native
1178 srcuri = bb.data.getVar('SRC_URI', d, 1)
1179 if "git://" in srcuri:
1180 depends = bb.data.getVarFlag('do_fetch', 'depends', d) or ""
1181 depends = depends + " git-native:do_populate_staging"
1182 bb.data.setVarFlag('do_fetch', 'depends', depends, d)
1184 # 'multimachine' handling
1185 mach_arch = bb.data.getVar('MACHINE_ARCH', d, 1)
1186 pkg_arch = bb.data.getVar('PACKAGE_ARCH', d, 1)
1188 if (pkg_arch == mach_arch):
1189 # Already machine specific - nothing further to do
1193 # We always try to scan SRC_URI for urls with machine overrides
1194 # unless the package sets SRC_URI_OVERRIDES_PACKAGE_ARCH=0
1196 override = bb.data.getVar('SRC_URI_OVERRIDES_PACKAGE_ARCH', d, 1)
1199 for p in [ "${PF}", "${P}", "${PN}", "files", "" ]:
1200 path = bb.data.expand(os.path.join("${FILE_DIRNAME}", p, "${MACHINE}"), d)
1201 if os.path.isdir(path):
1204 for s in srcuri.split():
1205 if not s.startswith("file://"):
1207 local = bb.data.expand(bb.fetch.localpath(s, d), d)
1209 if local.startswith(mp):
1210 #bb.note("overriding PACKAGE_ARCH from %s to %s" % (pkg_arch, mach_arch))
1211 bb.data.setVar('PACKAGE_ARCH', "${MACHINE_ARCH}", d)
1212 bb.data.setVar('MULTIMACH_ARCH', mach_arch, d)
1215 multiarch = pkg_arch
1217 packages = bb.data.getVar('PACKAGES', d, 1).split()
1218 for pkg in packages:
1219 pkgarch = bb.data.getVar("PACKAGE_ARCH_%s" % pkg, d, 1)
1221 # We could look for != PACKAGE_ARCH here but how to choose
1222 # if multiple differences are present?
1223 # Look through PACKAGE_ARCHS for the priority order?
1224 if pkgarch and pkgarch == mach_arch:
1225 multiarch = mach_arch
1228 bb.data.setVar('MULTIMACH_ARCH', multiarch, d)
1232 from bb import __version__
1235 # Remove this for bitbake 1.8.12
1237 from distutils.version import LooseVersion
1239 def LooseVersion(v): print "WARNING: sanity.bbclass can't compare versions without python-distutils"; return 1
1240 if (LooseVersion(__version__) >= LooseVersion('1.8.11')):
1241 deps = bb.data.getVarFlag('do_rebuild', 'deps', d) or []
1242 deps.append('do_' + bb.data.getVar('BB_DEFAULT_TASK', d, 1))
1243 bb.data.setVarFlag('do_rebuild', 'deps', deps, d)
1246 def check_app_exists(app, d):
1247 from bb import which, data
1249 app = data.expand(app, d)
1250 path = data.getVar('PATH', d, 1)
1251 return len(which(path, app)) != 0
1253 def check_gcc3(data):
1254 # Primarly used by qemu to make sure we have a workable gcc-3.4.x.
1255 # Start by checking for the program name as we build it, was not
1256 # all host-provided gcc-3.4's will work.
1258 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'
1260 for gcc3 in gcc3_versions.split():
1261 if check_app_exists(gcc3, data):
1269 # Configuration data from site files
1270 # Move to autotools.bbclass?
1273 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
1277 ${DEBIAN_MIRROR}/main http://snapshot.debian.net/archive/pool
1278 ${DEBIAN_MIRROR} ftp://ftp.de.debian.org/debian/pool
1279 ${DEBIAN_MIRROR} ftp://ftp.au.debian.org/debian/pool
1280 ${DEBIAN_MIRROR} ftp://ftp.cl.debian.org/debian/pool
1281 ${DEBIAN_MIRROR} ftp://ftp.hr.debian.org/debian/pool
1282 ${DEBIAN_MIRROR} ftp://ftp.fi.debian.org/debian/pool
1283 ${DEBIAN_MIRROR} ftp://ftp.hk.debian.org/debian/pool
1284 ${DEBIAN_MIRROR} ftp://ftp.hu.debian.org/debian/pool
1285 ${DEBIAN_MIRROR} ftp://ftp.ie.debian.org/debian/pool
1286 ${DEBIAN_MIRROR} ftp://ftp.it.debian.org/debian/pool
1287 ${DEBIAN_MIRROR} ftp://ftp.jp.debian.org/debian/pool
1288 ${DEBIAN_MIRROR} ftp://ftp.no.debian.org/debian/pool
1289 ${DEBIAN_MIRROR} ftp://ftp.pl.debian.org/debian/pool
1290 ${DEBIAN_MIRROR} ftp://ftp.ro.debian.org/debian/pool
1291 ${DEBIAN_MIRROR} ftp://ftp.si.debian.org/debian/pool
1292 ${DEBIAN_MIRROR} ftp://ftp.es.debian.org/debian/pool
1293 ${DEBIAN_MIRROR} ftp://ftp.se.debian.org/debian/pool
1294 ${DEBIAN_MIRROR} ftp://ftp.tr.debian.org/debian/pool
1295 ${GNU_MIRROR} ftp://mirrors.kernel.org/gnu
1296 ${GNU_MIRROR} ftp://ftp.cs.ubc.ca/mirror2/gnu
1297 ${GNU_MIRROR} ftp://sunsite.ust.hk/pub/gnu
1298 ${GNU_MIRROR} ftp://ftp.ayamura.org/pub/gnu
1299 ${KERNELORG_MIRROR} http://www.kernel.org/pub
1300 ${KERNELORG_MIRROR} ftp://ftp.us.kernel.org/pub
1301 ${KERNELORG_MIRROR} ftp://ftp.uk.kernel.org/pub
1302 ${KERNELORG_MIRROR} ftp://ftp.hk.kernel.org/pub
1303 ${KERNELORG_MIRROR} ftp://ftp.au.kernel.org/pub
1304 ${KERNELORG_MIRROR} ftp://ftp.jp.kernel.org/pub
1305 ftp://ftp.gnupg.org/gcrypt/ ftp://ftp.franken.de/pub/crypt/mirror/ftp.gnupg.org/gcrypt/
1306 ftp://ftp.gnupg.org/gcrypt/ ftp://ftp.surfnet.nl/pub/security/gnupg/
1307 ftp://ftp.gnupg.org/gcrypt/ http://gulus.USherbrooke.ca/pub/appl/GnuPG/
1308 ftp://dante.ctan.org/tex-archive ftp://ftp.fu-berlin.de/tex/CTAN
1309 ftp://dante.ctan.org/tex-archive http://sunsite.sut.ac.jp/pub/archives/ctan/
1310 ftp://dante.ctan.org/tex-archive http://ctan.unsw.edu.au/
1311 ftp://ftp.gnutls.org/pub/gnutls ftp://ftp.gnutls.org/pub/gnutls/
1312 ftp://ftp.gnutls.org/pub/gnutls ftp://ftp.gnupg.org/gcrypt/gnutls/
1313 ftp://ftp.gnutls.org/pub/gnutls http://www.mirrors.wiretapped.net/security/network-security/gnutls/
1314 ftp://ftp.gnutls.org/pub/gnutls ftp://ftp.mirrors.wiretapped.net/pub/security/network-security/gnutls/
1315 ftp://ftp.gnutls.org/pub/gnutls http://josefsson.org/gnutls/releases/
1316 http://ftp.info-zip.org/pub/infozip/src/ http://mirror.switch.ch/ftp/mirror/infozip/src/
1317 http://ftp.info-zip.org/pub/infozip/src/ ftp://sunsite.icm.edu.pl/pub/unix/archiving/info-zip/src/
1318 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.cerias.purdue.edu/pub/tools/unix/sysutils/lsof/
1319 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.tau.ac.il/pub/unix/admin/
1320 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.cert.dfn.de/pub/tools/admin/lsof/
1321 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.fu-berlin.de/pub/unix/tools/lsof/
1322 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.kaizo.org/pub/lsof/
1323 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.tu-darmstadt.de/pub/sysadmin/lsof/
1324 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://ftp.tux.org/pub/sites/vic.cc.purdue.edu/tools/unix/lsof/
1325 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://gd.tuwien.ac.at/utils/admin-tools/lsof/
1326 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://sunsite.ualberta.ca/pub/Mirror/lsof/
1327 ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ ftp://the.wiretapped.net/pub/security/host-security/lsof/
1328 http://www.apache.org/dist http://archive.apache.org/dist
1329 ftp://.*/.* http://mirrors.openembedded.org/
1330 https?$://.*/.* http://mirrors.openembedded.org/
1331 ftp://.*/.* http://sources.openembedded.org/
1332 https?$://.*/.* http://sources.openembedded.org/