2 def base_path_join(a, *p):
3 return oe.path.join(a, *p)
5 def base_path_relative(src, dest):
6 return oe.path.relative(src, dest)
8 def base_path_out(path, d):
9 return oe.path.format_display(path, d)
11 def base_read_file(filename):
12 return oe.utils.read_file(filename)
14 def base_ifelse(condition, iftrue = True, iffalse = False):
15 return oe.utils.ifelse(condition, iftrue, iffalse)
17 def base_conditional(variable, checkvalue, truevalue, falsevalue, d):
18 return oe.utils.conditional(variable, checkvalue, truevalue, falsevalue, d)
20 def base_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
21 return oe.utils.less_or_equal(variable, checkvalue, truevalue, falsevalue, d)
23 def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
24 return oe.utils.version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d)
26 def base_contains(variable, checkvalues, truevalue, falsevalue, d):
27 return oe.utils.contains(variable, checkvalues, truevalue, falsevalue, d)
29 def base_both_contain(variable1, variable2, checkvalue, d):
30 return oe.utils.both_contain(variable1, variable2, checkvalue, d)
32 def base_prune_suffix(var, suffixes, d):
33 return oe.utils.prune_suffix(var, suffixes, d)
35 def oe_filter(f, str, d):
36 return oe.utils.str_filter(f, str, d)
38 def oe_filter_out(f, str, d):
39 return oe.utils.str_filter_out(f, str, d)
42 def subprocess_setup():
44 # Python installs a SIGPIPE handler by default. This is usually not what
45 # non-Python subprocesses expect.
46 signal.signal(signal.SIGPIPE, signal.SIG_DFL)
48 def oe_popen(d, cmd, **kwargs):
49 """ Convenience function to call out processes with our exported
50 variables in the environment.
52 from subprocess import Popen
54 if kwargs.get("env") is None:
55 env = d.getVar("__oe_popen_env", False)
59 if d.getVarFlag(v, "export"):
60 env[v] = d.getVar(v, True) or ""
61 d.setVar("__oe_popen_env", env)
64 kwargs["close_fds"] = True
65 kwargs["preexec_fn"] = subprocess_setup
67 return Popen(cmd, **kwargs)
69 def oe_system(d, cmd, **kwargs):
70 """ Popen based version of os.system. """
71 if not "shell" in kwargs:
72 kwargs["shell"] = True
73 return oe_popen(d, cmd, **kwargs).wait()
75 # for MD5/SHA handling
76 def base_chk_load_parser(config_paths):
78 parser = ConfigParser.ConfigParser()
79 if len(parser.read(config_paths)) < 1:
80 raise ValueError("no ini files could be found")
84 def setup_checksum_deps(d):
88 if d.getVar("PN", True) != "shasum-native":
89 depends = d.getVarFlag("do_fetch", "depends") or ""
90 d.setVarFlag("do_fetch", "depends", "%s %s" %
91 (depends, "shasum-native:do_populate_sysroot"))
93 def base_chk_file_checksum(localpath, src_uri, expected_md5sum, expected_sha256sum, data):
94 strict_checking = True
95 if bb.data.getVar("OE_STRICT_CHECKSUMS", data, True) != "1":
96 strict_checking = False
97 if not os.path.exists(localpath):
98 localpath = base_path_out(localpath, data)
99 bb.note("The localpath does not exist '%s'" % localpath)
100 raise Exception("The path does not exist '%s'" % localpath)
102 md5data = bb.utils.md5_file(localpath)
103 sha256data = bb.utils.sha256_file(localpath)
106 shapipe = os.popen('PATH=%s oe_sha256sum "%s"' % (bb.data.getVar('PATH', data, True), localpath))
107 sha256data = (shapipe.readline().split() or [ "" ])[0]
111 raise Exception("Executing shasum failed")
113 bb.note("Executing shasum failed")
115 if (expected_md5sum == None or expected_md5sum == None):
116 from string import maketrans
117 trtable = maketrans("", "")
118 uname = src_uri.split("/")[-1].translate(trtable, "-+._")
121 ufile = open("%s/%s.sum" % (bb.data.getVar("TMPDIR", data, 1), uname), "wt")
126 raise Exception("Creating %s.sum failed" % uname)
128 ufile.write("SRC_URI[md5sum] = \"%s\"\nSRC_URI[sha256sum] = \"%s\"\n" % (md5data, sha256data))
130 bb.note("This package has no checksums, please add to recipe")
131 bb.note("\nSRC_URI[md5sum] = \"%s\"\nSRC_URI[sha256sum] = \"%s\"\n" % (md5data, sha256data))
133 # fail for strict, continue for disabled strict checksums
134 return not strict_checking
136 if (expected_md5sum and expected_md5sum != md5data) or (expected_sha256sum and expected_sha256sum != sha256data):
137 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))
138 bb.note("Your checksums:\nSRC_URI[md5sum] = \"%s\"\nSRC_URI[sha256sum] = \"%s\"\n" % (md5data, sha256data))
143 def base_get_checksums(pn, pv, src_uri, localpath, params, data):
144 # Try checksum from recipe and then parse checksums.ini
145 # and try PN-PV-SRC_URI first and then try PN-SRC_URI
146 # we rely on the get method to create errors
148 name = params["name"]
152 md5flag = "%s.md5sum" % name
153 sha256flag = "%s.sha256sum" % name
156 sha256flag = "sha256sum"
157 expected_md5sum = bb.data.getVarFlag("SRC_URI", md5flag, data)
158 expected_sha256sum = bb.data.getVarFlag("SRC_URI", sha256flag, data)
160 if (expected_md5sum and expected_sha256sum):
161 return (expected_md5sum,expected_sha256sum)
163 # missing checksum, parse checksums.ini
165 # Verify the SHA and MD5 sums we have in OE and check what do
167 checksum_paths = bb.data.getVar('BBPATH', data, True).split(":")
169 # reverse the list to give precedence to directories that
170 # appear first in BBPATH
171 checksum_paths.reverse()
173 checksum_files = ["%s/conf/checksums.ini" % path for path in checksum_paths]
175 parser = base_chk_load_parser(checksum_files)
177 bb.note("No conf/checksums.ini found, not checking checksums")
180 bb.note("Creating the CheckSum parser failed: %s:%s" % (sys.exc_info()[0], sys.exc_info()[1]))
182 pn_pv_src = "%s-%s-%s" % (pn,pv,src_uri)
183 pn_src = "%s-%s" % (pn,src_uri)
184 if parser.has_section(pn_pv_src):
185 expected_md5sum = parser.get(pn_pv_src, "md5")
186 expected_sha256sum = parser.get(pn_pv_src, "sha256")
187 elif parser.has_section(pn_src):
188 expected_md5sum = parser.get(pn_src, "md5")
189 expected_sha256sum = parser.get(pn_src, "sha256")
190 elif parser.has_section(src_uri):
191 expected_md5sum = parser.get(src_uri, "md5")
192 expected_sha256sum = parser.get(src_uri, "sha256")
197 bb.note("This package has no checksums in corresponding recipe '%s', please consider moving its checksums from checksums.ini file \
198 \nSRC_URI[%s.md5sum] = \"%s\"\nSRC_URI[%s.sha256sum] = \"%s\"\n" % (bb.data.getVar("FILE", data, True), name, expected_md5sum, name, expected_sha256sum))
200 bb.note("This package has no checksums in corresponding recipe '%s', please consider moving its checksums from checksums.ini file \
201 \nSRC_URI[md5sum] = \"%s\"\nSRC_URI[sha256sum] = \"%s\"\n" % (bb.data.getVar("FILE", data, True), expected_md5sum, expected_sha256sum))
203 return (expected_md5sum, expected_sha256sum)
205 def base_chk_file(pn, pv, src_uri, localpath, params, data):
206 (expected_md5sum, expected_sha256sum) = base_get_checksums(pn, pv, src_uri, localpath, params, data)
207 return base_chk_file_checksum(localpath, src_uri, expected_md5sum, expected_sha256sum, data)
211 echo "Usage: oedebug level \"message\""
215 test ${OEDEBUG:-0} -ge $1 && {
222 # Purpose: Install shared library file and
223 # create the necessary links
228 #oenote installing shared library $1 to $2
230 libname=`basename $1`
231 install -m 755 $1 $2/$libname
232 sonamelink=`${HOST_PREFIX}readelf -d $1 |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
233 solink=`echo $libname | sed -e 's/\.so\..*/.so/'`
234 ln -sf $libname $2/$sonamelink
235 ln -sf $libname $2/$solink
239 # Purpose: Install a library, in all its forms
242 # oe_libinstall libltdl ${STAGING_LIBDIR}/
243 # oe_libinstall -C src/libblah libblah ${D}/${libdir}/
250 while [ "$#" -gt 0 ]; do
266 oefatal "oe_libinstall: unknown option: $1"
278 if [ -z "$destpath" ]; then
279 oefatal "oe_libinstall: no destination path specified"
281 if echo "$destpath/" | egrep '^${STAGING_LIBDIR}/' >/dev/null
287 if [ -z "$silent" ]; then
288 echo >&2 "oe_libinstall: $*"
293 if [ -z "$dir" ]; then
299 # Sanity check that the libname.lai is unique
300 number_of_files=`(cd $dir; find . -name "$dotlai") | wc -l`
301 if [ $number_of_files -gt 1 ]; then
302 oefatal "oe_libinstall: $dotlai is not unique in $dir"
306 dir=$dir`(cd $dir;find . -name "$dotlai") | sed "s/^\.//;s/\/$dotlai\$//;q"`
312 # If such file doesn't exist, try to cut version suffix
313 if [ ! -f "$lafile" ]; then
314 libname1=`echo "$libname" | sed 's/-[0-9.]*$//'`
316 if [ -f "$lafile1" ]; then
322 if [ -f "$lafile" ]; then
324 eval `cat $lafile|grep "^library_names="`
327 library_names="$libname.so* $libname.dll.a"
330 __runcmd install -d $destpath/
332 if [ -f "$dota" -o -n "$require_static" ]; then
333 __runcmd install -m 0644 $dota $destpath/
335 if [ -f "$dotlai" -a -n "$libtool" ]; then
336 if test -n "$staging_install"
338 # stop libtool using the final directory name for libraries
340 __runcmd rm -f $destpath/$libname.la
341 __runcmd sed -e 's/^installed=yes$/installed=no/' \
342 -e '/^dependency_libs=/s,${WORKDIR}[[:alnum:]/\._+-]*/\([[:alnum:]\._+-]*\),${STAGING_LIBDIR}/\1,g' \
343 -e "/^dependency_libs=/s,\([[:space:]']\)${libdir},\1${STAGING_LIBDIR},g" \
344 $dotlai >$destpath/$libname.la
346 __runcmd install -m 0644 $dotlai $destpath/$libname.la
350 for name in $library_names; do
351 files=`eval echo $name`
353 if [ ! -e "$f" ]; then
354 if [ -n "$libtool" ]; then
355 oefatal "oe_libinstall: $dir/$f not found."
357 elif [ -L "$f" ]; then
358 __runcmd cp -P "$f" $destpath/
359 elif [ ! -L "$f" ]; then
361 __runcmd install -m 0755 $libfile $destpath/
366 if [ -z "$libfile" ]; then
367 if [ -n "$require_shared" ]; then
368 oefatal "oe_libinstall: unable to locate shared library"
370 elif [ -z "$libtool" ]; then
371 # special case hack for non-libtool .so.#.#.# links
372 baselibfile=`basename "$libfile"`
373 if (echo $baselibfile | grep -qE '^lib.*\.so\.[0-9.]*$'); then
374 sonamelink=`${HOST_PREFIX}readelf -d $libfile |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
375 solink=`echo $baselibfile | sed -e 's/\.so\..*/.so/'`
376 if [ -n "$sonamelink" -a x"$baselibfile" != x"$sonamelink" ]; then
377 __runcmd ln -sf $baselibfile $destpath/$sonamelink
379 __runcmd ln -sf $baselibfile $destpath/$solink
383 __runcmd cd "$olddir"
387 # Purpose: Install machine dependent files, if available
388 # If not available, check if there is a default
389 # If no default, just touch the destination
392 # oe_machinstall -m 0644 fstab ${D}/etc/fstab
394 # TODO: Check argument number?
396 filename=`basename $3`
399 for o in `echo ${OVERRIDES} | tr ':' ' '`; do
400 if [ -e $dirname/$o/$filename ]; then
401 oenote $dirname/$o/$filename present, installing to $4
402 install $1 $2 $dirname/$o/$filename $4
406 # oenote overrides specific file NOT present, trying default=$3...
408 oenote $3 present, installing to $4
411 oenote $3 NOT present, touching empty $4
416 def check_app_exists(app, d):
417 from bb import which, data
419 app = data.expand(app, d)
420 path = data.getVar('PATH', d, 1)
421 return bool(which(path, app))
424 return bb.utils.explode_deps(s)
426 def base_set_filespath(path, d):
427 bb.note("base_set_filespath usage is deprecated, %s should be fixed" % d.getVar("P", 1))
429 # The ":" ensures we have an 'empty' override
430 overrides = (bb.data.getVar("OVERRIDES", d, 1) or "") + ":"
432 for o in overrides.split(":"):
433 filespath.append(os.path.join(p, o))
434 return ":".join(filespath)