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 """List any existing machine specific filespath directories"""
43 machine = d.getVar("MACHINE", True)
44 filespathpkg = d.getVar("FILESPATHPKG", True).split(":")
45 for basepath in d.getVar("FILESPATHBASE", True).split(":"):
46 for pkgpath in filespathpkg:
47 machinepath = os.path.join(basepath, pkgpath, machine)
48 if os.path.isdir(machinepath):
51 def is_machine_specific(d):
52 """Determine whether the current recipe is machine specific"""
53 machinepaths = set(machine_paths(d))
54 urldatadict = bb.fetch.init(d.getVar("SRC_URI", True).split(), d, True)
55 for urldata in (urldata for urldata in urldatadict.itervalues()
56 if urldata.type == "file"):
57 if any(urldata.localpath.startswith(mp + "/") for mp in machinepaths):
61 env = d.getVar("__oe_popen_env", False)
65 if d.getVarFlag(v, "export"):
66 env[v] = d.getVar(v, True) or ""
67 d.setVar("__oe_popen_env", env)
70 def oe_run(d, cmd, **kwargs):
72 kwargs["env"] = oe_popen_env(d)
73 return oe.process.run(cmd, **kwargs)
75 def oe_popen(d, cmd, **kwargs):
77 kwargs["env"] = oe_popen_env(d)
78 return oe.process.Popen(cmd, **kwargs)
80 def oe_system(d, cmd, **kwargs):
81 """ Popen based version of os.system. """
82 if not "shell" in kwargs:
83 kwargs["shell"] = True
84 return oe_popen(d, cmd, **kwargs).wait()
86 # for MD5/SHA handling
87 def base_chk_load_parser(config_paths):
89 parser = ConfigParser.ConfigParser()
90 if len(parser.read(config_paths)) < 1:
91 raise ValueError("no ini files could be found")
95 def setup_checksum_deps(d):
99 if d.getVar("PN", True) != "shasum-native":
100 depends = d.getVarFlag("do_fetch", "depends") or ""
101 d.setVarFlag("do_fetch", "depends", "%s %s" %
102 (depends, "shasum-native:do_populate_sysroot"))
104 def base_chk_file_checksum(localpath, src_uri, expected_md5sum, expected_sha256sum, data):
105 strict_checking = True
106 if bb.data.getVar("OE_STRICT_CHECKSUMS", data, True) != "1":
107 strict_checking = False
108 if not os.path.exists(localpath):
109 localpath = base_path_out(localpath, data)
110 bb.note("The localpath does not exist '%s'" % localpath)
111 raise Exception("The path does not exist '%s'" % localpath)
113 md5data = bb.utils.md5_file(localpath)
114 sha256data = bb.utils.sha256_file(localpath)
117 shapipe = os.popen('PATH=%s oe_sha256sum "%s"' % (bb.data.getVar('PATH', data, True), localpath))
118 sha256data = (shapipe.readline().split() or [ "" ])[0]
122 raise Exception("Executing shasum failed")
124 bb.note("Executing shasum failed")
126 if (expected_md5sum == None or expected_md5sum == None):
127 from string import maketrans
128 trtable = maketrans("", "")
129 uname = src_uri.split("/")[-1].translate(trtable, "-+._")
132 ufile = open("%s/%s.sum" % (bb.data.getVar("TMPDIR", data, 1), uname), "wt")
137 raise Exception("Creating %s.sum failed" % uname)
139 ufile.write("SRC_URI[md5sum] = \"%s\"\nSRC_URI[sha256sum] = \"%s\"\n" % (md5data, sha256data))
141 bb.note("This package has no checksums, please add to recipe")
142 bb.note("\nSRC_URI[md5sum] = \"%s\"\nSRC_URI[sha256sum] = \"%s\"\n" % (md5data, sha256data))
144 # fail for strict, continue for disabled strict checksums
145 return not strict_checking
147 if (expected_md5sum and expected_md5sum != md5data) or (expected_sha256sum and expected_sha256sum != sha256data):
148 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))
149 bb.note("Your checksums:\nSRC_URI[md5sum] = \"%s\"\nSRC_URI[sha256sum] = \"%s\"\n" % (md5data, sha256data))
154 def base_get_checksums(pn, pv, src_uri, localpath, params, data):
155 # Try checksum from recipe and then parse checksums.ini
156 # and try PN-PV-SRC_URI first and then try PN-SRC_URI
157 # we rely on the get method to create errors
159 name = params["name"]
163 md5flag = "%s.md5sum" % name
164 sha256flag = "%s.sha256sum" % name
167 sha256flag = "sha256sum"
168 expected_md5sum = bb.data.getVarFlag("SRC_URI", md5flag, data)
169 expected_sha256sum = bb.data.getVarFlag("SRC_URI", sha256flag, data)
171 if (expected_md5sum and expected_sha256sum):
172 return (expected_md5sum,expected_sha256sum)
174 # missing checksum, parse checksums.ini
176 # Verify the SHA and MD5 sums we have in OE and check what do
178 checksum_paths = bb.data.getVar('BBPATH', data, True).split(":")
180 # reverse the list to give precedence to directories that
181 # appear first in BBPATH
182 checksum_paths.reverse()
184 checksum_files = ["%s/conf/checksums.ini" % path for path in checksum_paths]
186 parser = base_chk_load_parser(checksum_files)
188 bb.note("No conf/checksums.ini found, not checking checksums")
191 bb.note("Creating the CheckSum parser failed: %s:%s" % (sys.exc_info()[0], sys.exc_info()[1]))
193 pn_pv_src = "%s-%s-%s" % (pn,pv,src_uri)
194 pn_src = "%s-%s" % (pn,src_uri)
195 if parser.has_section(pn_pv_src):
196 expected_md5sum = parser.get(pn_pv_src, "md5")
197 expected_sha256sum = parser.get(pn_pv_src, "sha256")
198 elif parser.has_section(pn_src):
199 expected_md5sum = parser.get(pn_src, "md5")
200 expected_sha256sum = parser.get(pn_src, "sha256")
201 elif parser.has_section(src_uri):
202 expected_md5sum = parser.get(src_uri, "md5")
203 expected_sha256sum = parser.get(src_uri, "sha256")
208 bb.note("This package has no checksums in corresponding recipe '%s', please consider moving its checksums from checksums.ini file \
209 \nSRC_URI[%s.md5sum] = \"%s\"\nSRC_URI[%s.sha256sum] = \"%s\"\n" % (bb.data.getVar("FILE", data, True), name, expected_md5sum, name, expected_sha256sum))
211 bb.note("This package has no checksums in corresponding recipe '%s', please consider moving its checksums from checksums.ini file \
212 \nSRC_URI[md5sum] = \"%s\"\nSRC_URI[sha256sum] = \"%s\"\n" % (bb.data.getVar("FILE", data, True), expected_md5sum, expected_sha256sum))
214 return (expected_md5sum, expected_sha256sum)
216 def base_chk_file(pn, pv, src_uri, localpath, params, data):
217 (expected_md5sum, expected_sha256sum) = base_get_checksums(pn, pv, src_uri, localpath, params, data)
218 return base_chk_file_checksum(localpath, src_uri, expected_md5sum, expected_sha256sum, data)
222 echo "Usage: oedebug level \"message\""
226 test ${OEDEBUG:-0} -ge $1 && {
233 # Purpose: Install shared library file and
234 # create the necessary links
239 #oenote installing shared library $1 to $2
241 libname=`basename $1`
242 install -m 755 $1 $2/$libname
243 sonamelink=`${HOST_PREFIX}readelf -d $1 |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
244 solink=`echo $libname | sed -e 's/\.so\..*/.so/'`
245 ln -sf $libname $2/$sonamelink
246 ln -sf $libname $2/$solink
250 # Purpose: Install a library, in all its forms
253 # oe_libinstall libltdl ${STAGING_LIBDIR}/
254 # oe_libinstall -C src/libblah libblah ${D}/${libdir}/
261 while [ "$#" -gt 0 ]; do
277 oefatal "oe_libinstall: unknown option: $1"
289 if [ -z "$destpath" ]; then
290 oefatal "oe_libinstall: no destination path specified"
292 if echo "$destpath/" | egrep '^${STAGING_LIBDIR}/' >/dev/null
298 if [ -z "$silent" ]; then
299 echo >&2 "oe_libinstall: $*"
304 if [ -z "$dir" ]; then
310 # Sanity check that the libname.lai is unique
311 number_of_files=`(cd $dir; find . -name "$dotlai") | wc -l`
312 if [ $number_of_files -gt 1 ]; then
313 oefatal "oe_libinstall: $dotlai is not unique in $dir"
317 dir=$dir`(cd $dir;find . -name "$dotlai") | sed "s/^\.//;s/\/$dotlai\$//;q"`
323 # If such file doesn't exist, try to cut version suffix
324 if [ ! -f "$lafile" ]; then
325 libname1=`echo "$libname" | sed 's/-[0-9.]*$//'`
327 if [ -f "$lafile1" ]; then
333 if [ -f "$lafile" ]; then
335 eval `cat $lafile|grep "^library_names="`
338 library_names="$libname.so* $libname.dll.a"
341 __runcmd install -d $destpath/
343 if [ -f "$dota" -o -n "$require_static" ]; then
344 __runcmd install -m 0644 $dota $destpath/
346 if [ -f "$dotlai" -a -n "$libtool" ]; then
347 if [ -n "$staging_install" -a "${LIBTOOL_HAS_SYSROOT}" = "no" ]
349 # stop libtool using the final directory name for libraries
351 __runcmd rm -f $destpath/$libname.la
352 __runcmd sed -e 's/^installed=yes$/installed=no/' \
353 -e '/^dependency_libs=/s,${WORKDIR}[[:alnum:]/\._+-]*/\([[:alnum:]\._+-]*\),${STAGING_LIBDIR}/\1,g' \
354 -e "/^dependency_libs=/s,\([[:space:]']\)${libdir},\1${STAGING_LIBDIR},g" \
355 $dotlai >$destpath/$libname.la
357 __runcmd install -m 0644 $dotlai $destpath/$libname.la
361 for name in $library_names; do
362 files=`eval echo $name`
364 if [ ! -e "$f" ]; then
365 if [ -n "$libtool" ]; then
366 oefatal "oe_libinstall: $dir/$f not found."
368 elif [ -L "$f" ]; then
369 __runcmd cp -P "$f" $destpath/
370 elif [ ! -L "$f" ]; then
372 __runcmd install -m 0755 $libfile $destpath/
377 if [ -z "$libfile" ]; then
378 if [ -n "$require_shared" ]; then
379 oefatal "oe_libinstall: unable to locate shared library"
381 elif [ -z "$libtool" ]; then
382 # special case hack for non-libtool .so.#.#.# links
383 baselibfile=`basename "$libfile"`
384 if (echo $baselibfile | grep -qE '^lib.*\.so\.[0-9.]*$'); then
385 sonamelink=`${HOST_PREFIX}readelf -d $libfile |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
386 solink=`echo $baselibfile | sed -e 's/\.so\..*/.so/'`
387 if [ -n "$sonamelink" -a x"$baselibfile" != x"$sonamelink" ]; then
388 __runcmd ln -sf $baselibfile $destpath/$sonamelink
390 __runcmd ln -sf $baselibfile $destpath/$solink
394 __runcmd cd "$olddir"
398 # Purpose: Install machine dependent files, if available
399 # If not available, check if there is a default
400 # If no default, just touch the destination
403 # oe_machinstall -m 0644 fstab ${D}/etc/fstab
405 # TODO: Check argument number?
407 filename=`basename $3`
410 for o in `echo ${OVERRIDES} | tr ':' ' '`; do
411 if [ -e $dirname/$o/$filename ]; then
412 oenote $dirname/$o/$filename present, installing to $4
413 install $1 $2 $dirname/$o/$filename $4
417 # oenote overrides specific file NOT present, trying default=$3...
419 oenote $3 present, installing to $4
422 oenote $3 NOT present, touching empty $4
428 # Create a wrapper script
430 # These are useful to work around relocation issues, by setting environment
431 # variables which point to paths in the filesystem.
433 # Usage: create_wrapper FILENAME [[VAR=VALUE]..]
438 # run echo via env to test syntactic validity of the variable arguments
439 env $@ echo "Generating wrapper script for $cmd"
442 cmdname=`basename $cmd`.real
445 exec env $@ \`dirname \$0\`/$cmdname "\$@"
450 def check_app_exists(app, d):
451 from bb import which, data
453 app = data.expand(app, d)
454 path = data.getVar('PATH', d, 1)
455 return bool(which(path, app))
458 return bb.utils.explode_deps(s)
460 def base_set_filespath(path, d):
461 bb.note("base_set_filespath usage is deprecated, %s should be fixed" % d.getVar("P", 1))
463 # The ":" ensures we have an 'empty' override
464 overrides = (bb.data.getVar("OVERRIDES", d, 1) or "") + ":"
466 for o in overrides.split(":"):
467 filespath.append(os.path.join(p, o))
468 return ":".join(filespath)