4 return oe.utils.uniq(iterable)
6 def base_path_join(a, *p):
7 return oe.path.join(a, *p)
9 def base_path_relative(src, dest):
10 return oe.path.relative(src, dest)
12 def base_path_out(path, d):
13 return oe.path.format_display(path, d)
15 def base_read_file(filename):
16 return oe.utils.read_file(filename)
18 def base_ifelse(condition, iftrue = True, iffalse = False):
19 return oe.utils.ifelse(condition, iftrue, iffalse)
21 def base_conditional(variable, checkvalue, truevalue, falsevalue, d):
22 return oe.utils.conditional(variable, checkvalue, truevalue, falsevalue, d)
24 def base_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
25 return oe.utils.less_or_equal(variable, checkvalue, truevalue, falsevalue, d)
27 def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
28 return oe.utils.version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d)
30 def base_contains(variable, checkvalues, truevalue, falsevalue, d):
31 return oe.utils.contains(variable, checkvalues, truevalue, falsevalue, d)
33 def base_both_contain(variable1, variable2, checkvalue, d):
34 return oe.utils.both_contain(variable1, variable2, checkvalue, d)
36 def base_prune_suffix(var, suffixes, d):
37 return oe.utils.prune_suffix(var, suffixes, d)
39 def oe_filter(f, str, d):
40 return oe.utils.str_filter(f, str, d)
42 def oe_filter_out(f, str, d):
43 return oe.utils.str_filter_out(f, str, d)
46 """List any existing machine specific filespath directories"""
47 machine = d.getVar("MACHINE", True)
48 filespathpkg = d.getVar("FILESPATHPKG", True).split(":")
49 for basepath in d.getVar("FILESPATHBASE", True).split(":"):
50 for pkgpath in filespathpkg:
51 machinepath = os.path.join(basepath, pkgpath, machine)
52 if os.path.isdir(machinepath):
55 def is_machine_specific(d):
56 """Determine whether the current recipe is machine specific"""
57 machinepaths = set(machine_paths(d))
58 urldatadict = bb.fetch.init(d.getVar("SRC_URI", True).split(), d, True)
59 for urldata in (urldata for urldata in urldatadict.itervalues()
60 if urldata.type == "file"):
61 if any(urldata.localpath.startswith(mp + "/") for mp in machinepaths):
67 if d.getVarFlag(v, "export"):
68 env[v] = d.getVar(v, True) or ""
71 def oe_run(d, cmd, **kwargs):
73 kwargs["env"] = oe_popen_env(d)
74 return oe.process.run(cmd, **kwargs)
76 def oe_popen(d, cmd, **kwargs):
78 kwargs["env"] = oe_popen_env(d)
79 return oe.process.Popen(cmd, **kwargs)
81 def oe_system(d, cmd, **kwargs):
82 """ Popen based version of os.system. """
83 if not "shell" in kwargs:
84 kwargs["shell"] = True
85 return oe_popen(d, cmd, **kwargs).wait()
87 # for MD5/SHA handling
88 def base_chk_load_parser(config_paths):
90 parser = ConfigParser.ConfigParser()
91 if len(parser.read(config_paths)) < 1:
92 raise ValueError("no ini files could be found")
96 def setup_checksum_deps(d):
100 if d.getVar("PN", True) != "shasum-native":
101 depends = d.getVarFlag("do_fetch", "depends") or ""
102 d.setVarFlag("do_fetch", "depends", "%s %s" %
103 (depends, "shasum-native:do_populate_sysroot"))
105 def base_get_hash_flags(params):
107 name = params["name"]
111 md5flag = "%s.md5sum" % name
112 sha256flag = "%s.sha256sum" % name
115 sha256flag = "sha256sum"
117 return (md5flag, sha256flag)
119 def base_chk_file_checksum(localpath, src_uri, expected_md5sum, expected_sha256sum, params, data):
120 strict_checking = True
121 if bb.data.getVar("OE_STRICT_CHECKSUMS", data, True) != "1":
122 strict_checking = False
123 if not os.path.exists(localpath):
124 localpath = base_path_out(localpath, data)
125 bb.note("The localpath does not exist '%s'" % localpath)
126 raise Exception("The path does not exist '%s'" % localpath)
128 md5data = bb.utils.md5_file(localpath)
129 sha256data = bb.utils.sha256_file(localpath)
132 shapipe = os.popen('PATH=%s oe_sha256sum "%s"' % (bb.data.getVar('PATH', data, True), localpath))
133 sha256data = (shapipe.readline().split() or [ "" ])[0]
137 raise Exception("Executing shasum failed")
139 bb.note("Executing shasum failed")
141 if (expected_md5sum == None or expected_md5sum == None):
142 from string import maketrans
143 trtable = maketrans("", "")
144 uname = src_uri.split("/")[-1].translate(trtable, "-+._")
147 ufile = open("%s/%s.sum" % (bb.data.getVar("TMPDIR", data, 1), uname), "wt")
152 raise Exception("Creating %s.sum failed" % uname)
154 (md5flag, sha256flag) = base_get_hash_flags(params)
155 ufile.write("SRC_URI[%s] = \"%s\"\nSRC_URI[%s] = \"%s\"\n" % (md5flag, md5data, sha256flag, sha256data))
157 bb.note("This package has no checksums, please add to recipe")
158 bb.note("\nSRC_URI[%s] = \"%s\"\nSRC_URI[%s] = \"%s\"\n" % (md5flag, md5data, sha256flag, sha256data))
160 # fail for strict, continue for disabled strict checksums
161 return not strict_checking
163 if (expected_md5sum and expected_md5sum != md5data) or (expected_sha256sum and expected_sha256sum != sha256data):
164 (md5flag, sha256flag) = base_get_hash_flags(params)
165 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))
166 bb.note("Your checksums:\nSRC_URI[%s] = \"%s\"\nSRC_URI[%s] = \"%s\"\n" % (md5flag, md5data, sha256flag, sha256data))
171 def base_get_checksums(pn, pv, src_uri, localpath, params, data):
172 # Try checksum from recipe and then parse checksums.ini
173 # and try PN-PV-SRC_URI first and then try PN-SRC_URI
174 # we rely on the get method to create errors
175 (md5flag, sha256flag) = base_get_hash_flags(params)
176 expected_md5sum = bb.data.getVarFlag("SRC_URI", md5flag, data)
177 expected_sha256sum = bb.data.getVarFlag("SRC_URI", sha256flag, data)
179 return (expected_md5sum, expected_sha256sum)
181 def base_chk_file(pn, pv, src_uri, localpath, params, data):
182 (expected_md5sum, expected_sha256sum) = base_get_checksums(pn, pv, src_uri, localpath, params, data)
183 return base_chk_file_checksum(localpath, src_uri, expected_md5sum, expected_sha256sum, params, data)
187 echo "Usage: oedebug level \"message\""
191 test ${OEDEBUG:-0} -ge $1 && {
198 # Purpose: Install shared library file and
199 # create the necessary links
204 #oenote installing shared library $1 to $2
206 libname=`basename $1`
207 install -m 755 $1 $2/$libname
208 sonamelink=`${HOST_PREFIX}readelf -d $1 |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
209 solink=`echo $libname | sed -e 's/\.so\..*/.so/'`
210 ln -sf $libname $2/$sonamelink
211 ln -sf $libname $2/$solink
215 # Purpose: Install a library, in all its forms
218 # oe_libinstall libltdl ${STAGING_LIBDIR}/
219 # oe_libinstall -C src/libblah libblah ${D}/${libdir}/
226 while [ "$#" -gt 0 ]; do
242 oefatal "oe_libinstall: unknown option: $1"
254 if [ -z "$destpath" ]; then
255 oefatal "oe_libinstall: no destination path specified"
257 if echo "$destpath/" | egrep '^${STAGING_LIBDIR}/' >/dev/null
263 if [ -z "$silent" ]; then
264 echo >&2 "oe_libinstall: $*"
269 if [ -z "$dir" ]; then
275 # Sanity check that the libname.lai is unique
276 number_of_files=`(cd $dir; find . -name "$dotlai") | wc -l`
277 if [ $number_of_files -gt 1 ]; then
278 oefatal "oe_libinstall: $dotlai is not unique in $dir"
282 dir=$dir`(cd $dir;find . -name "$dotlai") | sed "s/^\.//;s/\/$dotlai\$//;q"`
288 # If such file doesn't exist, try to cut version suffix
289 if [ ! -f "$lafile" ]; then
290 libname1=`echo "$libname" | sed 's/-[0-9.]*$//'`
292 if [ -f "$lafile1" ]; then
298 if [ -f "$lafile" ]; then
300 eval `cat $lafile|grep "^library_names="`
303 library_names="$libname.so* $libname.dll.a $libname.*.dylib"
306 __runcmd install -d $destpath/
308 if [ -f "$dota" -o -n "$require_static" ]; then
309 __runcmd install -m 0644 $dota $destpath/
311 if [ -f "$dotlai" -a -n "$libtool" ]; then
312 if [ -n "$staging_install" -a "${LIBTOOL_HAS_SYSROOT}" = "no" ]
314 # stop libtool using the final directory name for libraries
316 __runcmd rm -f $destpath/$libname.la
317 __runcmd sed -e 's/^installed=yes$/installed=no/' \
318 -e '/^dependency_libs=/s,${WORKDIR}[[:alnum:]/\._+-]*/\([[:alnum:]\._+-]*\),${STAGING_LIBDIR}/\1,g' \
319 -e "/^dependency_libs=/s,\([[:space:]']\)${libdir},\1${STAGING_LIBDIR},g" \
320 $dotlai >$destpath/$libname.la
322 __runcmd install -m 0644 $dotlai $destpath/$libname.la
326 for name in $library_names; do
327 files=`eval echo $name`
329 if [ ! -e "$f" ]; then
330 if [ -n "$libtool" ]; then
331 oefatal "oe_libinstall: $dir/$f not found."
333 elif [ -L "$f" ]; then
334 __runcmd cp -P "$f" $destpath/
335 elif [ ! -L "$f" ]; then
337 __runcmd install -m 0755 $libfile $destpath/
342 if [ -z "$libfile" ]; then
343 if [ -n "$require_shared" ]; then
344 oefatal "oe_libinstall: unable to locate shared library"
346 elif [ -z "$libtool" ]; then
347 # special case hack for non-libtool .so.#.#.# links
348 baselibfile=`basename "$libfile"`
349 if (echo $baselibfile | grep -qE '^lib.*\.so\.[0-9.]*$'); then
350 sonamelink=`${HOST_PREFIX}readelf -d $libfile |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'`
351 solink=`echo $baselibfile | sed -e 's/\.so\..*/.so/'`
352 if [ -n "$sonamelink" -a x"$baselibfile" != x"$sonamelink" ]; then
353 __runcmd ln -sf $baselibfile $destpath/$sonamelink
355 __runcmd ln -sf $baselibfile $destpath/$solink
359 __runcmd cd "$olddir"
363 # Purpose: Install machine dependent files, if available
364 # If not available, check if there is a default
365 # If no default, just touch the destination
368 # oe_machinstall -m 0644 fstab ${D}/etc/fstab
370 # TODO: Check argument number?
372 filename=`basename $3`
375 for o in `echo ${OVERRIDES} | tr ':' ' '`; do
376 if [ -e $dirname/$o/$filename ]; then
377 oenote $dirname/$o/$filename present, installing to $4
378 install $1 $2 $dirname/$o/$filename $4
382 # oenote overrides specific file NOT present, trying default=$3...
384 oenote $3 present, installing to $4
387 oenote $3 NOT present, touching empty $4
393 # Create a wrapper script
395 # These are useful to work around relocation issues, by setting environment
396 # variables which point to paths in the filesystem.
398 # Usage: create_wrapper FILENAME [[VAR=VALUE]..]
403 # run echo via env to test syntactic validity of the variable arguments
404 env $@ echo "Generating wrapper script for $cmd"
407 cmdname=`basename $cmd`.real
410 realpath=\`readlink -fn \$0\`
411 exec env $@ \`dirname \$realpath\`/$cmdname "\$@"
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))
435 r[-1] += ' ' + ' '.join(j)
440 def base_set_filespath(path, d):
441 bb.note("base_set_filespath usage is deprecated, %s should be fixed" % d.getVar("P", 1))
443 # The ":" ensures we have an 'empty' override
444 overrides = (bb.data.getVar("OVERRIDES", d, 1) or "") + ":"
446 for o in overrides.split(":"):
447 filespath.append(os.path.join(p, o))
448 return ":".join(filespath)
450 # These directory stack functions are based upon the versions in the Korn
451 # Shell documentation - http://docstore.mik.ua/orelly/unix3/korn/ch04_07.htm.
458 cd ${dirname:?"missing directory name."} || return 1
459 _DIRSTACK="$PWD $_DIRSTACK"
464 _DIRSTACK=${_DIRSTACK#* }