1 def subprocess_setup():
3 # Python installs a SIGPIPE handler by default. This is usually not what
4 # non-Python subprocesses expect.
5 signal.signal(signal.SIGPIPE, signal.SIG_DFL)
7 def oe_popen(d, cmd, **kwargs):
8 """ Convenience function to call out processes with our exported
9 variables in the environment.
11 from subprocess import Popen
13 if kwargs.get("env") is None:
14 env = d.getVar("__oe_popen_env", False)
18 if d.getVarFlag(v, "export"):
19 env[v] = d.getVar(v, True) or ""
20 d.setVar("__oe_popen_env", env)
23 kwargs["preexec_fn"] = subprocess_setup
25 return Popen(cmd, **kwargs)
27 def oe_system(d, cmd):
28 """ Popen based version of os.system. """
29 return oe_popen(d, cmd, shell=True).wait()
31 # like os.path.join but doesn't treat absolute RHS specially
32 def base_path_join(a, *p):
35 if path == '' or path.endswith('/'):
41 def base_path_relative(src, dest):
42 """ Return a relative path from src to dest.
44 >>> base_path_relative("/usr/bin", "/tmp/foo/bar")
47 >>> base_path_relative("/usr/bin", "/usr/lib")
50 >>> base_path_relative("/tmp", "/tmp/foo/bar")
53 from os.path import sep, pardir, normpath, commonprefix
55 destlist = normpath(dest).split(sep)
56 srclist = normpath(src).split(sep)
58 # Find common section of the path
59 common = commonprefix([destlist, srclist])
60 commonlen = len(common)
62 # Climb back to the point where they differentiate
63 relpath = [ pardir ] * (len(srclist) - commonlen)
64 if commonlen < len(destlist):
65 # Add remaining portion
66 relpath += destlist[commonlen:]
68 return sep.join(relpath)
70 def base_path_out(path, d):
71 """ Prepare a path for display to the user. """
72 rel = base_path_relative(d.getVar("TOPDIR", 1), path)
73 if len(rel) > len(path):
78 # for MD5/SHA handling
79 def base_chk_load_parser(config_paths):
81 parser = ConfigParser.ConfigParser()
82 if len(parser.read(config_paths)) < 1:
83 raise ValueError("no ini files could be found")
87 def base_chk_file_vars(parser, localpath, params, data):
93 md5flag = "%s.md5sum" % name
94 sha256flag = "%s.sha256sum" % name
97 sha256flag = "sha256sum"
98 want_md5sum = bb.data.getVarFlag("SRC_URI", md5flag, data)
99 want_sha256sum = bb.data.getVarFlag("SRC_URI", sha256flag, data)
101 if (want_sha256sum == None and want_md5sum == None):
102 # no checksums to check, nothing to do
105 if not os.path.exists(localpath):
106 localpath = base_path_out(localpath, data)
107 bb.note("The localpath does not exist '%s'" % localpath)
108 raise Exception("The path does not exist '%s'" % localpath)
112 md5pipe = os.popen('PATH=%s md5sum "%s"' % (bb.data.getVar('PATH', data, True), localpath))
113 md5data = (md5pipe.readline().split() or [ "" ])[0]
116 raise Exception("Executing md5sum failed")
117 if want_md5sum != md5data:
118 bb.note("The MD5Sums did not match. Wanted: '%s' and Got: '%s'" % (want_md5sum, md5data))
119 raise Exception("MD5 Sums do not match. Wanted: '%s' Got: '%s'" % (want_md5sum, md5data))
123 shapipe = os.popen('PATH=%s oe_sha256sum "%s"' % (bb.data.getVar('PATH', data, True), localpath))
124 sha256data = (shapipe.readline().split() or [ "" ])[0]
127 raise Exception("Executing shasum failed")
128 if want_sha256sum != sha256data:
129 bb.note("The SHA256Sums did not match. Wanted: '%s' and Got: '%s'" % (want_sha256sum, sha256data))
130 raise Exception("SHA256 Sums do not match. Wanted: '%s' Got: '%s'" % (want_sha256sum, sha256data))
135 def base_chk_file(parser, pn, pv, src_uri, localpath, data):
137 # Try PN-PV-SRC_URI first and then try PN-SRC_URI
138 # we rely on the get method to create errors
139 pn_pv_src = "%s-%s-%s" % (pn,pv,src_uri)
140 pn_src = "%s-%s" % (pn,src_uri)
141 if parser.has_section(pn_pv_src):
142 md5 = parser.get(pn_pv_src, "md5")
143 sha256 = parser.get(pn_pv_src, "sha256")
144 elif parser.has_section(pn_src):
145 md5 = parser.get(pn_src, "md5")
146 sha256 = parser.get(pn_src, "sha256")
147 elif parser.has_section(src_uri):
148 md5 = parser.get(src_uri, "md5")
149 sha256 = parser.get(src_uri, "sha256")
153 # md5 and sha256 should be valid now
154 if not os.path.exists(localpath):
155 localpath = base_path_out(localpath, data)
156 bb.note("The localpath does not exist '%s'" % localpath)
157 raise Exception("The path does not exist '%s'" % localpath)
160 # call md5(sum) and shasum
162 md5pipe = os.popen('PATH=%s md5sum "%s"' % (bb.data.getVar('PATH', data, True), localpath))
163 md5data = (md5pipe.readline().split() or [ "" ])[0]
166 raise Exception("Executing md5sum failed")
169 shapipe = os.popen('PATH=%s oe_sha256sum "%s"' % (bb.data.getVar('PATH', data, True), localpath))
170 shadata = (shapipe.readline().split() or [ "" ])[0]
173 raise Exception("Executing shasum failed")
175 if no_checksum == True: # we do not have conf/checksums.ini entry
177 file = open("%s/checksums.ini" % bb.data.getVar("TMPDIR", data, 1), "a")
182 raise Exception("Creating checksums.ini failed")
184 file.write("[%s]\nmd5=%s\nsha256=%s\n\n" % (src_uri, md5data, shadata))
187 from string import maketrans
188 trtable = maketrans("", "")
189 uname = src_uri.split("/")[-1].translate(trtable, "-+._")
192 ufile = open("%s/%s.sum" % (bb.data.getVar("TMPDIR", data, 1), uname), "wt")
197 raise Exception("Creating %s.sum failed" % uname)
199 ufile.write("SRC_URI = \"%s;name=%s\"\nSRC_URI[%s.md5sum] = \"%s\"\nSRC_URI[%s.sha256sum] = \"%s\"\n" % (src_uri, uname, uname, md5data, uname, shadata))
202 if not bb.data.getVar("OE_STRICT_CHECKSUMS",data, True):
203 bb.note("This package has no entry in checksums.ini, please add one")
204 bb.note("\n[%s]\nmd5=%s\nsha256=%s" % (src_uri, md5data, shadata))
205 bb.note("This package has no checksums in corresponding recipe, please add")
206 bb.note("SRC_URI = \"%s;name=%s\"\nSRC_URI[%s.md5sum] = \"%s\"\nSRC_URI[%s.sha256sum] = \"%s\"\n" % (src_uri, uname, uname, md5data, uname, shadata))
209 bb.note("Missing checksum")
212 if not md5 == md5data:
213 bb.note("The MD5Sums did not match. Wanted: '%s' and Got: '%s'" % (md5,md5data))
214 raise Exception("MD5 Sums do not match. Wanted: '%s' Got: '%s'" % (md5, md5data))
216 if not sha256 == shadata:
217 bb.note("The SHA256 Sums do not match. Wanted: '%s' Got: '%s'" % (sha256,shadata))
218 raise Exception("SHA256 Sums do not match. Wanted: '%s' Got: '%s'" % (sha256, shadata))
222 def base_read_file(filename):
224 f = file( filename, "r" )
225 except IOError, reason:
226 return "" # WARNING: can't raise an error now because of the new RDEPENDS handling. This is a bit ugly. :M:
228 return f.read().strip()
231 def base_ifelse(condition, iftrue = True, iffalse = False):
237 def base_conditional(variable, checkvalue, truevalue, falsevalue, d):
238 if bb.data.getVar(variable,d,1) == checkvalue:
243 def base_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
244 if float(bb.data.getVar(variable,d,1)) <= float(checkvalue):
249 def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
250 result = bb.vercmp(bb.data.getVar(variable,d,True), checkvalue)
256 def base_contains(variable, checkvalues, truevalue, falsevalue, d):
257 val = bb.data.getVar(variable,d,1)
261 if type(checkvalues).__name__ == "str":
262 checkvalues = [checkvalues]
263 for value in checkvalues:
264 if val.find(value) != -1:
265 matches = matches + 1
266 if matches == len(checkvalues):
270 def base_both_contain(variable1, variable2, checkvalue, d):
271 if bb.data.getVar(variable1,d,1).find(checkvalue) != -1 and bb.data.getVar(variable2,d,1).find(checkvalue) != -1:
276 def base_prune_suffix(var, suffixes, d):
277 # See if var ends with any of the suffixes listed and
279 for suffix in suffixes:
280 if var.endswith(suffix):
281 return var.replace(suffix, "")
284 def oe_filter(f, str, d):
286 return " ".join(filter(lambda x: match(f, x, 0), str.split()))
288 def oe_filter_out(f, str, d):
290 return " ".join(filter(lambda x: not match(f, x, 0), str.split()))
294 echo "Usage: oedebug level \"message\""
298 test ${OEDEBUG:-0} -ge $1 && {
305 # Purpose: Install shared library file and
306 # create the necessary links
311 #oenote installing shared library $1 to $2
313 libname=`basename $1`
314 install -m 755 $1 $2/$libname
315 sonamelink=`${HOST_PREFIX}readelf -d $1 |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
316 solink=`echo $libname | sed -e 's/\.so\..*/.so/'`
317 ln -sf $libname $2/$sonamelink
318 ln -sf $libname $2/$solink
322 # Purpose: Install a library, in all its forms
325 # oe_libinstall libltdl ${STAGING_LIBDIR}/
326 # oe_libinstall -C src/libblah libblah ${D}/${libdir}/
333 while [ "$#" -gt 0 ]; do
349 oefatal "oe_libinstall: unknown option: $1"
361 if [ -z "$destpath" ]; then
362 oefatal "oe_libinstall: no destination path specified"
364 if echo "$destpath/" | egrep '^${STAGING_LIBDIR}/' >/dev/null
370 if [ -z "$silent" ]; then
371 echo >&2 "oe_libinstall: $*"
376 if [ -z "$dir" ]; then
382 # Sanity check that the libname.lai is unique
383 number_of_files=`(cd $dir; find . -name "$dotlai") | wc -l`
384 if [ $number_of_files -gt 1 ]; then
385 oefatal "oe_libinstall: $dotlai is not unique in $dir"
389 dir=$dir`(cd $dir;find . -name "$dotlai") | sed "s/^\.//;s/\/$dotlai\$//;q"`
395 # If such file doesn't exist, try to cut version suffix
396 if [ ! -f "$lafile" ]; then
397 libname1=`echo "$libname" | sed 's/-[0-9.]*$//'`
399 if [ -f "$lafile1" ]; then
405 if [ -f "$lafile" ]; then
407 eval `cat $lafile|grep "^library_names="`
410 library_names="$libname.so* $libname.dll.a"
413 __runcmd install -d $destpath/
415 if [ -f "$dota" -o -n "$require_static" ]; then
416 __runcmd install -m 0644 $dota $destpath/
418 if [ -f "$dotlai" -a -n "$libtool" ]; then
419 if test -n "$staging_install"
421 # stop libtool using the final directory name for libraries
423 __runcmd rm -f $destpath/$libname.la
424 __runcmd sed -e 's/^installed=yes$/installed=no/' \
425 -e '/^dependency_libs=/s,${WORKDIR}[[:alnum:]/\._+-]*/\([[:alnum:]\._+-]*\),${STAGING_LIBDIR}/\1,g' \
426 -e "/^dependency_libs=/s,\([[:space:]']\)${libdir},\1${STAGING_LIBDIR},g" \
427 $dotlai >$destpath/$libname.la
429 __runcmd install -m 0644 $dotlai $destpath/$libname.la
433 for name in $library_names; do
434 files=`eval echo $name`
436 if [ ! -e "$f" ]; then
437 if [ -n "$libtool" ]; then
438 oefatal "oe_libinstall: $dir/$f not found."
440 elif [ -L "$f" ]; then
441 __runcmd cp -P "$f" $destpath/
442 elif [ ! -L "$f" ]; then
444 __runcmd install -m 0755 $libfile $destpath/
449 if [ -z "$libfile" ]; then
450 if [ -n "$require_shared" ]; then
451 oefatal "oe_libinstall: unable to locate shared library"
453 elif [ -z "$libtool" ]; then
454 # special case hack for non-libtool .so.#.#.# links
455 baselibfile=`basename "$libfile"`
456 if (echo $baselibfile | grep -qE '^lib.*\.so\.[0-9.]*$'); then
457 sonamelink=`${HOST_PREFIX}readelf -d $libfile |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
458 solink=`echo $baselibfile | sed -e 's/\.so\..*/.so/'`
459 if [ -n "$sonamelink" -a x"$baselibfile" != x"$sonamelink" ]; then
460 __runcmd ln -sf $baselibfile $destpath/$sonamelink
462 __runcmd ln -sf $baselibfile $destpath/$solink
466 __runcmd cd "$olddir"
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
499 def check_app_exists(app, d):
500 from bb import which, data
502 app = data.expand(app, d)
503 path = data.getVar('PATH', d, 1)
504 return len(which(path, app)) != 0
507 return bb.utils.explode_deps(s)
509 def base_set_filespath(path, d):
510 bb.note("base_set_filespath usage is deprecated, %s should be fixed" % d.getVar("P", 1))
512 # The ":" ensures we have an 'empty' override
513 overrides = (bb.data.getVar("OVERRIDES", d, 1) or "") + ":"
515 for o in overrides.split(":"):
516 filespath.append(os.path.join(p, o))
517 return ":".join(filespath)