diff options
Diffstat (limited to 'meta/classes/utils.bbclass')
| -rw-r--r-- | meta/classes/utils.bbclass | 284 |
1 files changed, 192 insertions, 92 deletions
diff --git a/meta/classes/utils.bbclass b/meta/classes/utils.bbclass index 9930a24269..96463ab323 100644 --- a/meta/classes/utils.bbclass +++ b/meta/classes/utils.bbclass @@ -24,7 +24,8 @@ def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d): return oe.utils.version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d) def base_contains(variable, checkvalues, truevalue, falsevalue, d): - return oe.utils.contains(variable, checkvalues, truevalue, falsevalue, d) + bb.note('base_contains is deprecated, please use bb.utils.contains instead.') + return bb.utils.contains(variable, checkvalues, truevalue, falsevalue, d) def base_both_contain(variable1, variable2, checkvalue, d): return oe.utils.both_contain(variable1, variable2, checkvalue, d) @@ -40,9 +41,9 @@ def oe_filter_out(f, str, d): def machine_paths(d): """List any existing machine specific filespath directories""" - machine = d.getVar("MACHINE", True) - filespathpkg = d.getVar("FILESPATHPKG", True).split(":") - for basepath in d.getVar("FILESPATHBASE", True).split(":"): + machine = d.getVar("MACHINE") + filespathpkg = d.getVar("FILESPATHPKG").split(":") + for basepath in d.getVar("FILESPATHBASE").split(":"): for pkgpath in filespathpkg: machinepath = os.path.join(basepath, pkgpath, machine) if os.path.isdir(machinepath): @@ -51,51 +52,28 @@ def machine_paths(d): def is_machine_specific(d): """Determine whether the current recipe is machine specific""" machinepaths = set(machine_paths(d)) - srcuri = d.getVar("SRC_URI", True).split() + srcuri = d.getVar("SRC_URI").split() for url in srcuri: fetcher = bb.fetch2.Fetch([srcuri], d) if url.startswith("file://"): if any(fetcher.localpath(url).startswith(mp + "/") for mp in machinepaths): return True -def oe_popen_env(d): - env = d.getVar("__oe_popen_env", False) - if env is None: - env = {} - for v in d.keys(): - if d.getVarFlag(v, "export"): - env[v] = d.getVar(v, True) or "" - d.setVar("__oe_popen_env", env) - return env - -def oe_run(d, cmd, **kwargs): - import oe.process - kwargs["env"] = oe_popen_env(d) - return oe.process.run(cmd, **kwargs) - -def oe_popen(d, cmd, **kwargs): - import oe.process - kwargs["env"] = oe_popen_env(d) - return oe.process.Popen(cmd, **kwargs) - -def oe_system(d, cmd, **kwargs): - """ Popen based version of os.system. """ - if not "shell" in kwargs: - kwargs["shell"] = True - return oe_popen(d, cmd, **kwargs).wait() - oe_soinstall() { # Purpose: Install shared library file and # create the necessary links - # Example: - # - # oe_ - # - #bbnote installing shared library $1 to $2 - # + # Example: oe_soinstall libfoo.so.1.2.3 ${D}${libdir} libname=`basename $1` + case "$libname" in + *.so) + bbfatal "oe_soinstall: Shared library must haved versioned filename (e.g. libfoo.so.1.2.3)" + ;; + esac install -m 755 $1 $2/$libname sonamelink=`${HOST_PREFIX}readelf -d $1 |grep 'Library soname:' |sed -e 's/.*\[\(.*\)\].*/\1/'` + if [ -z $sonamelink ]; then + bbfatal "oe_soinstall: $libname is missing ELF tag 'SONAME'." + fi solink=`echo $libname | sed -e 's/\.so\..*/.so/'` ln -sf $libname $2/$sonamelink ln -sf $libname $2/$solink @@ -272,72 +250,194 @@ oe_machinstall() { } create_cmdline_wrapper () { - # Create a wrapper script - # - # These are useful to work around relocation issues, by setting environment - # variables which point to paths in the filesystem. - # - # Usage: create_wrapper FILENAME [[VAR=VALUE]..] - - cmd=$1 - shift - - # run echo via env to test syntactic validity of the variable arguments - echo "Generating wrapper script for $cmd" - - mv $cmd $cmd.real - cmdname=`basename $cmd`.real - cat <<END >$cmd -#!/bin/sh + # Create a wrapper script where commandline options are needed + # + # These are useful to work around relocation issues, by passing extra options + # to a program + # + # Usage: create_cmdline_wrapper FILENAME <extra-options> + + cmd=$1 + shift + + echo "Generating wrapper script for $cmd" + + mv $cmd $cmd.real + cmdname=`basename $cmd` + dirname=`dirname $cmd` + cmdoptions=$@ + if [ "${base_prefix}" != "" ]; then + relpath=`python3 -c "import os; print(os.path.relpath('${D}${base_prefix}', '$dirname'))"` + cmdoptions=`echo $@ | sed -e "s:${base_prefix}:\\$realdir/$relpath:g"` + fi + cat <<END >$cmd +#!/bin/bash realpath=\`readlink -fn \$0\` -exec \`dirname \$realpath\`/$cmdname "\$@" +realdir=\`dirname \$realpath\` +exec -a \`dirname \$realpath\`/$cmdname \`dirname \$realpath\`/$cmdname.real $cmdoptions "\$@" END - chmod +x $cmd + chmod +x $cmd } create_wrapper () { - # Create a wrapper script - # - # These are useful to work around relocation issues, by setting environment - # variables which point to paths in the filesystem. - # - # Usage: create_wrapper FILENAME [[VAR=VALUE]..] - - cmd=$1 - shift - - # run echo via env to test syntactic validity of the variable arguments - env $@ echo "Generating wrapper script for $cmd" - - mv $cmd $cmd.real - cmdname=`basename $cmd`.real - cat <<END >$cmd -#!/bin/sh + # Create a wrapper script where extra environment variables are needed + # + # These are useful to work around relocation issues, by setting environment + # variables which point to paths in the filesystem. + # + # Usage: create_wrapper FILENAME [[VAR=VALUE]..] + + cmd=$1 + shift + + echo "Generating wrapper script for $cmd" + + mv $cmd $cmd.real + cmdname=`basename $cmd` + dirname=`dirname $cmd` + exportstring=$@ + if [ "${base_prefix}" != "" ]; then + relpath=`python3 -c "import os; print(os.path.relpath('${D}${base_prefix}', '$dirname'))"` + exportstring=`echo $@ | sed -e "s:${base_prefix}:\\$realdir/$relpath:g"` + fi + cat <<END >$cmd +#!/bin/bash realpath=\`readlink -fn \$0\` -exec env $@ \`dirname \$realpath\`/$cmdname "\$@" +realdir=\`dirname \$realpath\` +export $exportstring +exec -a \`dirname \$realpath\`/$cmdname \`dirname \$realpath\`/$cmdname.real "\$@" END - chmod +x $cmd + chmod +x $cmd +} + +# Copy files/directories from $1 to $2 but using hardlinks +# (preserve symlinks) +hardlinkdir () { + from=$1 + to=$2 + (cd $from; find . -print0 | cpio --null -pdlu $to) } -def check_app_exists(app, d): - from bb import which, data - app = data.expand(app, d) - path = data.getVar('PATH', d, 1) - return bool(which(path, app)) +def check_app_exists(app, d): + app = d.expand(app).strip() + path = d.getVar('PATH') + return bool(bb.utils.which(path, app)) def explode_deps(s): - return bb.utils.explode_deps(s) + return bb.utils.explode_deps(s) def base_set_filespath(path, d): - filespath = [] - extrapaths = (bb.data.getVar("FILESEXTRAPATHS", d, True) or "") - # Don't prepend empty strings to the path list - if extrapaths != "": - path = extrapaths.split(":") + path - # The ":" ensures we have an 'empty' override - overrides = (bb.data.getVar("OVERRIDES", d, 1) or "") + ":" - for p in path: - for o in overrides.split(":"): - filespath.append(os.path.join(p, o)) - return ":".join(filespath) + filespath = [] + extrapaths = (d.getVar("FILESEXTRAPATHS") or "") + # Remove default flag which was used for checking + extrapaths = extrapaths.replace("__default:", "") + # Don't prepend empty strings to the path list + if extrapaths != "": + path = extrapaths.split(":") + path + # The ":" ensures we have an 'empty' override + overrides = (":" + (d.getVar("FILESOVERRIDES") or "")).split(":") + overrides.reverse() + for o in overrides: + for p in path: + if p != "": + filespath.append(os.path.join(p, o)) + return ":".join(filespath) + +def extend_variants(d, var, extend, delim=':'): + """Return a string of all bb class extend variants for the given extend""" + variants = [] + whole = d.getVar(var) or "" + for ext in whole.split(): + eext = ext.split(delim) + if len(eext) > 1 and eext[0] == extend: + variants.append(eext[1]) + return " ".join(variants) + +def multilib_pkg_extend(d, pkg): + variants = (d.getVar("MULTILIB_VARIANTS") or "").split() + if not variants: + return pkg + pkgs = pkg + for v in variants: + pkgs = pkgs + " " + v + "-" + pkg + return pkgs + +def get_multilib_datastore(variant, d): + localdata = bb.data.createCopy(d) + overrides = localdata.getVar("OVERRIDES", False) + ":virtclass-multilib-" + variant + localdata.setVar("OVERRIDES", overrides) + localdata.setVar("MLPREFIX", variant + "-") + return localdata + +def all_multilib_tune_values(d, var, unique = True, need_split = True, delim = ' '): + """Return a string of all ${var} in all multilib tune configuration""" + values = [] + value = d.getVar(var) or "" + if value != "": + if need_split: + for item in value.split(delim): + values.append(item) + else: + values.append(value) + variants = d.getVar("MULTILIB_VARIANTS") or "" + for item in variants.split(): + localdata = get_multilib_datastore(item, d) + value = localdata.getVar(var) or "" + if value != "": + if need_split: + for item in value.split(delim): + values.append(item) + else: + values.append(value) + if unique: + #we do this to keep order as much as possible + ret = [] + for value in values: + if not value in ret: + ret.append(value) + else: + ret = values + return " ".join(ret) + +def all_multilib_tune_list(vars, d): + """ + Return a list of ${VAR} for each variable VAR in vars from each + multilib tune configuration. + Is safe to be called from a multilib recipe/context as it can + figure out the original tune and remove the multilib overrides. + """ + values = {} + for v in vars: + values[v] = [] + + localdata = bb.data.createCopy(d) + overrides = localdata.getVar("OVERRIDES", False).split(":") + newoverrides = [] + for o in overrides: + if not o.startswith("virtclass-multilib-"): + newoverrides.append(o) + localdata.setVar("OVERRIDES", ":".join(newoverrides)) + localdata.setVar("MLPREFIX", "") + origdefault = localdata.getVar("DEFAULTTUNE_MULTILIB_ORIGINAL") + if origdefault: + localdata.setVar("DEFAULTTUNE", origdefault) + values['ml'] = [''] + for v in vars: + values[v].append(localdata.getVar(v)) + variants = d.getVar("MULTILIB_VARIANTS") or "" + for item in variants.split(): + localdata = get_multilib_datastore(item, d) + values[v].append(localdata.getVar(v)) + values['ml'].append(item) + return values + +# If the user hasn't set up their name/email, set some defaults +check_git_config() { + if ! git config user.email > /dev/null ; then + git config --local user.email "${PATCH_GIT_USER_EMAIL}" + fi + if ! git config user.name > /dev/null ; then + git config --local user.name "${PATCH_GIT_USER_NAME}" + fi +} |
