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 setup_checksum_deps(d):
91 if d.getVar("PN", True) != "shasum-native":
92 depends = d.getVarFlag("do_fetch", "depends") or ""
93 d.setVarFlag("do_fetch", "depends", "%s %s" %
94 (depends, "shasum-native:do_populate_staging"))
96 def base_chk_file_checksum(localpath, src_uri, expected_md5sum, expected_sha256sum, data):
97 strict_checking = bb.data.getVar("OE_STRICT_CHECKSUMS", data, True)
98 if not os.path.exists(localpath):
99 localpath = base_path_out(localpath, data)
100 bb.note("The localpath does not exist '%s'" % localpath)
101 raise Exception("The path does not exist '%s'" % localpath)
103 md5data = bb.utils.md5_file(localpath)
104 sha256data = bb.utils.sha256_file(localpath)
107 shapipe = os.popen('PATH=%s oe_sha256sum "%s"' % (bb.data.getVar('PATH', data, True), localpath))
108 sha256data = (shapipe.readline().split() or [ "" ])[0]
112 raise Exception("Executing shasum failed")
114 bb.note("Executing shasum failed")
116 if (expected_md5sum == None or expected_md5sum == None):
117 from string import maketrans
118 trtable = maketrans("", "")
119 uname = src_uri.split("/")[-1].translate(trtable, "-+._")
122 ufile = open("%s/%s.sum" % (bb.data.getVar("TMPDIR", data, 1), uname), "wt")
127 raise Exception("Creating %s.sum failed" % uname)
129 ufile.write("SRC_URI[md5sum] = \"%s\"\nSRC_URI[sha256sum] = \"%s\"\n" % (md5data, sha256data))
131 bb.note("This package has no checksums, please add to recipe")
132 bb.note("\nSRC_URI[md5sum] = \"%s\"\nSRC_URI[sha256sum] = \"%s\"\n" % (md5data, sha256data))
134 # fail for strict, continue for disabled strict checksums
135 return not strict_checking
137 if (expected_md5sum and expected_md5sum != md5data) or (expected_sha256sum and expected_sha256sum != sha256data):
138 bb.note("The checksums for '%s' did not match.\nExpected MD5: '%s' and Got: '%s'\nExpected SHA256: '%s' and Got: '%s'" % (localpath, expected_md5sum, md5data, expected_sha256sum, sha256data))
139 bb.note("Your checksums:\nSRC_URI[md5sum] = \"%s\"\nSRC_URI[sha256sum] = \"%s\"\n" % (md5data, sha256data))
144 def base_get_checksums(pn, pv, src_uri, localpath, params, data):
145 # Try checksum from recipe and then parse checksums.ini
146 # and try PN-PV-SRC_URI first and then try PN-SRC_URI
147 # we rely on the get method to create errors
149 name = params["name"]
153 md5flag = "%s.md5sum" % name
154 sha256flag = "%s.sha256sum" % name
157 sha256flag = "sha256sum"
158 expected_md5sum = bb.data.getVarFlag("SRC_URI", md5flag, data)
159 expected_sha256sum = bb.data.getVarFlag("SRC_URI", sha256flag, data)
161 if (expected_md5sum and expected_sha256sum):
162 return (expected_md5sum,expected_sha256sum)
164 # missing checksum, parse checksums.ini
166 # Verify the SHA and MD5 sums we have in OE and check what do
168 checksum_paths = bb.data.getVar('BBPATH', data, True).split(":")
170 # reverse the list to give precedence to directories that
171 # appear first in BBPATH
172 checksum_paths.reverse()
174 checksum_files = ["%s/conf/checksums.ini" % path for path in checksum_paths]
176 parser = base_chk_load_parser(checksum_files)
178 bb.note("No conf/checksums.ini found, not checking checksums")
181 bb.note("Creating the CheckSum parser failed: %s:%s" % (sys.exc_info()[0], sys.exc_info()[1]))
183 pn_pv_src = "%s-%s-%s" % (pn,pv,src_uri)
184 pn_src = "%s-%s" % (pn,src_uri)
185 if parser.has_section(pn_pv_src):
186 expected_md5sum = parser.get(pn_pv_src, "md5")
187 expected_sha256sum = parser.get(pn_pv_src, "sha256")
188 elif parser.has_section(pn_src):
189 expected_md5sum = parser.get(pn_src, "md5")
190 expected_sha256sum = parser.get(pn_src, "sha256")
191 elif parser.has_section(src_uri):
192 expected_md5sum = parser.get(src_uri, "md5")
193 expected_sha256sum = parser.get(src_uri, "sha256")
198 bb.note("This package has no checksums in corresponding recipe '%s', please consider moving its checksums from checksums.ini file \
199 \nSRC_URI[%s.md5sum] = \"%s\"\nSRC_URI[%s.sha256sum] = \"%s\"\n" % (bb.data.getVar("FILE", data, True), name, expected_md5sum, name, expected_sha256sum))
201 bb.note("This package has no checksums in corresponding recipe '%s', please consider moving its checksums from checksums.ini file \
202 \nSRC_URI[md5sum] = \"%s\"\nSRC_URI[sha256sum] = \"%s\"\n" % (bb.data.getVar("FILE", data, True), expected_md5sum, expected_sha256sum))
204 return (expected_md5sum, expected_sha256sum)
206 def base_chk_file(pn, pv, src_uri, localpath, params, data):
207 (expected_md5sum, expected_sha256sum) = base_get_checksums(pn, pv, src_uri, localpath, params, data)
208 return base_chk_file_checksum(localpath, src_uri, expected_md5sum, expected_sha256sum, data)
210 def base_read_file(filename):
212 f = file( filename, "r" )
213 except IOError, reason:
214 return "" # WARNING: can't raise an error now because of the new RDEPENDS handling. This is a bit ugly. :M:
216 return f.read().strip()
219 def base_ifelse(condition, iftrue = True, iffalse = False):
225 def base_conditional(variable, checkvalue, truevalue, falsevalue, d):
226 if bb.data.getVar(variable,d,1) == checkvalue:
231 def base_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
232 if float(bb.data.getVar(variable,d,1)) <= float(checkvalue):
237 def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
238 result = bb.vercmp(bb.data.getVar(variable,d,True), checkvalue)
244 def base_contains(variable, checkvalues, truevalue, falsevalue, d):
245 val = bb.data.getVar(variable,d,1)
249 if type(checkvalues).__name__ == "str":
250 checkvalues = [checkvalues]
251 for value in checkvalues:
252 if val.find(value) != -1:
253 matches = matches + 1
254 if matches == len(checkvalues):
258 def base_both_contain(variable1, variable2, checkvalue, d):
259 if bb.data.getVar(variable1,d,1).find(checkvalue) != -1 and bb.data.getVar(variable2,d,1).find(checkvalue) != -1:
264 def base_prune_suffix(var, suffixes, d):
265 # See if var ends with any of the suffixes listed and
267 for suffix in suffixes:
268 if var.endswith(suffix):
269 return var.replace(suffix, "")
272 def oe_filter(f, str, d):
274 return " ".join(filter(lambda x: match(f, x, 0), str.split()))
276 def oe_filter_out(f, str, d):
278 return " ".join(filter(lambda x: not match(f, x, 0), str.split()))
282 echo "Usage: oedebug level \"message\""
286 test ${OEDEBUG:-0} -ge $1 && {
293 # Purpose: Install shared library file and
294 # create the necessary links
299 #oenote installing shared library $1 to $2
301 libname=`basename $1`
302 install -m 755 $1 $2/$libname
303 sonamelink=`${HOST_PREFIX}readelf -d $1 |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
304 solink=`echo $libname | sed -e 's/\.so\..*/.so/'`
305 ln -sf $libname $2/$sonamelink
306 ln -sf $libname $2/$solink
310 # Purpose: Install a library, in all its forms
313 # oe_libinstall libltdl ${STAGING_LIBDIR}/
314 # oe_libinstall -C src/libblah libblah ${D}/${libdir}/
321 while [ "$#" -gt 0 ]; do
337 oefatal "oe_libinstall: unknown option: $1"
349 if [ -z "$destpath" ]; then
350 oefatal "oe_libinstall: no destination path specified"
352 if echo "$destpath/" | egrep '^${STAGING_LIBDIR}/' >/dev/null
358 if [ -z "$silent" ]; then
359 echo >&2 "oe_libinstall: $*"
364 if [ -z "$dir" ]; then
370 # Sanity check that the libname.lai is unique
371 number_of_files=`(cd $dir; find . -name "$dotlai") | wc -l`
372 if [ $number_of_files -gt 1 ]; then
373 oefatal "oe_libinstall: $dotlai is not unique in $dir"
377 dir=$dir`(cd $dir;find . -name "$dotlai") | sed "s/^\.//;s/\/$dotlai\$//;q"`
383 # If such file doesn't exist, try to cut version suffix
384 if [ ! -f "$lafile" ]; then
385 libname1=`echo "$libname" | sed 's/-[0-9.]*$//'`
387 if [ -f "$lafile1" ]; then
393 if [ -f "$lafile" ]; then
395 eval `cat $lafile|grep "^library_names="`
398 library_names="$libname.so* $libname.dll.a"
401 __runcmd install -d $destpath/
403 if [ -f "$dota" -o -n "$require_static" ]; then
404 __runcmd install -m 0644 $dota $destpath/
406 if [ -f "$dotlai" -a -n "$libtool" ]; then
407 if test -n "$staging_install"
409 # stop libtool using the final directory name for libraries
411 __runcmd rm -f $destpath/$libname.la
412 __runcmd sed -e 's/^installed=yes$/installed=no/' \
413 -e '/^dependency_libs=/s,${WORKDIR}[[:alnum:]/\._+-]*/\([[:alnum:]\._+-]*\),${STAGING_LIBDIR}/\1,g' \
414 -e "/^dependency_libs=/s,\([[:space:]']\)${libdir},\1${STAGING_LIBDIR},g" \
415 $dotlai >$destpath/$libname.la
417 __runcmd install -m 0644 $dotlai $destpath/$libname.la
421 for name in $library_names; do
422 files=`eval echo $name`
424 if [ ! -e "$f" ]; then
425 if [ -n "$libtool" ]; then
426 oefatal "oe_libinstall: $dir/$f not found."
428 elif [ -L "$f" ]; then
429 __runcmd cp -P "$f" $destpath/
430 elif [ ! -L "$f" ]; then
432 __runcmd install -m 0755 $libfile $destpath/
437 if [ -z "$libfile" ]; then
438 if [ -n "$require_shared" ]; then
439 oefatal "oe_libinstall: unable to locate shared library"
441 elif [ -z "$libtool" ]; then
442 # special case hack for non-libtool .so.#.#.# links
443 baselibfile=`basename "$libfile"`
444 if (echo $baselibfile | grep -qE '^lib.*\.so\.[0-9.]*$'); then
445 sonamelink=`${HOST_PREFIX}readelf -d $libfile |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
446 solink=`echo $baselibfile | sed -e 's/\.so\..*/.so/'`
447 if [ -n "$sonamelink" -a x"$baselibfile" != x"$sonamelink" ]; then
448 __runcmd ln -sf $baselibfile $destpath/$sonamelink
450 __runcmd ln -sf $baselibfile $destpath/$solink
454 __runcmd cd "$olddir"
458 # Purpose: Install machine dependent files, if available
459 # If not available, check if there is a default
460 # If no default, just touch the destination
463 # oe_machinstall -m 0644 fstab ${D}/etc/fstab
465 # TODO: Check argument number?
467 filename=`basename $3`
470 for o in `echo ${OVERRIDES} | tr ':' ' '`; do
471 if [ -e $dirname/$o/$filename ]; then
472 oenote $dirname/$o/$filename present, installing to $4
473 install $1 $2 $dirname/$o/$filename $4
477 # oenote overrides specific file NOT present, trying default=$3...
479 oenote $3 present, installing to $4
482 oenote $3 NOT present, touching empty $4
487 def check_app_exists(app, d):
488 from bb import which, data
490 app = data.expand(app, d)
491 path = data.getVar('PATH', d, 1)
492 return bool(which(path, app))
495 return bb.utils.explode_deps(s)
497 def base_set_filespath(path, d):
498 bb.note("base_set_filespath usage is deprecated, %s should be fixed" % d.getVar("P", 1))
500 # The ":" ensures we have an 'empty' override
501 overrides = (bb.data.getVar("OVERRIDES", d, 1) or "") + ":"
503 for o in overrides.split(":"):
504 filespath.append(os.path.join(p, o))
505 return ":".join(filespath)