# # Copyright OpenEmbedded Contributors # # SPDX-License-Identifier: GPL-2.0-only # import subprocess import multiprocessing import traceback def read_file(filename): try: f = open( filename, "r" ) except IOError as reason: return "" # WARNING: can't raise an error now because of the new RDEPENDS handling. This is a bit ugly. :M: else: data = f.read().strip() f.close() return data return None def ifelse(condition, iftrue = True, iffalse = False): if condition: return iftrue else: return iffalse def conditional(variable, checkvalue, truevalue, falsevalue, d): if d.getVar(variable) == checkvalue: return truevalue else: return falsevalue def vartrue(var, iftrue, iffalse, d): import oe.types if oe.types.boolean(d.getVar(var)): return iftrue else: return iffalse def less_or_equal(variable, checkvalue, truevalue, falsevalue, d): if float(d.getVar(variable)) <= float(checkvalue): return truevalue else: return falsevalue def version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d): result = bb.utils.vercmp_string(d.getVar(variable), checkvalue) if result <= 0: return truevalue else: return falsevalue def both_contain(variable1, variable2, checkvalue, d): val1 = d.getVar(variable1) val2 = d.getVar(variable2) val1 = set(val1.split()) val2 = set(val2.split()) if isinstance(checkvalue, str): checkvalue = set(checkvalue.split()) else: checkvalue = set(checkvalue) if checkvalue.issubset(val1) and checkvalue.issubset(val2): return " ".join(checkvalue) else: return "" def set_intersect(variable1, variable2, d): """ Expand both variables, interpret them as lists of strings, and return the intersection as a flattened string. For example: s1 = "a b c" s2 = "b c d" s3 = set_intersect(s1, s2) => s3 = "b c" """ val1 = set(d.getVar(variable1).split()) val2 = set(d.getVar(variable2).split()) return " ".join(val1 & val2) def prune_suffix(var, suffixes, d): # See if var ends with any of the suffixes listed and # remove it if found for suffix in suffixes: if suffix and var.endswith(suffix): var = var[:-len(suffix)] prefix = d.getVar("MLPREFIX") if prefix and var.startswith(prefix): var = var[len(prefix):] return var def str_filter(f, str, d): from re import match return " ".join([x for x in str.split() if match(f, x, 0)]) def str_filter_out(f, str, d): from re import match return " ".join([x for x in str.split() if not match(f, x, 0)]) def build_depends_string(depends, task): """Append a taskname to a string of dependencies as used by the [depends] flag""" return " ".join(dep + ":" + task for dep in depends.split()) def inherits(d, *classes): """Return True if the metadata inherits any of the specified classes""" return any(bb.data.inherits_class(cls, d) for cls in classes) def features_backfill(var,d): # This construct allows the addition of new features to variable specified # as var # Example for var = "DISTRO_FEATURES" # This construct allows the addition of new features to DISTRO_FEATURES # that if not present would disable existing functionality, without # disturbing distributions that have already set DISTRO_FEATURES. # Distributions wanting to elide a value in DISTRO_FEATURES_BACKFILL should # add the feature to DISTRO_FEATURES_BACKFILL_CONSIDERED features = (d.getVar(var) or "").split() backfill = (d.getVar(var+"_BACKFILL") or "").split() considered = (d.getVar(var+"_BACKFILL_CONSIDERED") or "").split() addfeatures = [] for feature in backfill: if feature not in features and feature not in considered: addfeatures.append(feature) if addfeatures: d.appendVar(var, " " + " ".join(addfeatures)) def all_distro_features(d, features, truevalue="1", falsevalue=""): """ Returns truevalue if *all* given features are set in DISTRO_FEATURES, else falsevalue. The features can be given as single string or anything that can be turned into a set. This is a shorter, more flexible version of bb.utils.contains("DISTRO_FEATURES", features, truevalue, falsevalue, d). Without explicit true/false values it can be used directly where Python expects a boolean: if oe.utils.all_distro_features(d, "foo bar"): bb.fatal("foo and bar are mutually exclusive DISTRO_FEATURES") With just a truevalue, it can be used to include files that are meant to be used only when requested via DISTRO_FEATURES: require ${@ oe.utils.all_distro_features(d, "foo bar", "foo-and-bar.inc") """ return bb.utils.contains("DISTRO_FEATURES", features, truevalue, falsevalue, d) def any_distro_features(d, features, truevalue="1", falsevalue=""): """ Returns truevalue if at least *one* of the given features is set in DISTRO_FEATURES, else falsevalue. The features can be given as single string or anything that can be turned into a set. This is a shorter, more flexible version of bb.utils.contains_any("DISTRO_FEATURES", features, truevalue, falsevalue, d). Without explicit true/false values it can be used directly where Python expects a boolean: if not oe.utils.any_distro_features(d, "foo bar"): bb.fatal("foo, bar or both must be set in DISTRO_FEATURES") With just a truevalue, it can be used to include files that are meant to be used only when requested via DISTRO_FEATURES: require ${@ oe.utils.any_distro_features(d, "foo bar", "foo-or-bar.inc") """ return bb.utils.contains_any("DISTRO_FEATURES"#!/bin/sh # OE Build Environment Setup Script # # Copyright (C) 2006-2011 Linux Foundation # # SPDX-License-Identifier: GPL-2.0-or-later # # # Normally this is called as '. ./oe-init-build-env <builddir>' # # This works in most shells (not dash), but not all of them pass the arguments # when being sourced. To workaround the shell limitation use "set <builddir>" # prior to sourcing this script. # if [ -n "$BASH_SOURCE" ]; then THIS_SCRIPT=$BASH_SOURCE elif [ -n "$ZSH_NAME" ]; then THIS_SCRIPT=$0 else THIS_SCRIPT="$(pwd)/oe-init-build-env" if [ ! -e "$THIS_SCRIPT" ]; then echo "Error: $THIS_SCRIPT doesn't exist!" >&2 echo "Please run this script in oe-init-build-env's directory." >&2 exit 1 fi fi if [ -n "$BBSERVER" ]; then unset BBSERVER fi if [ -z "$ZSH_NAME" ] && [ "$0" = "$THIS_SCRIPT" ]; then echo "Error: This script needs to be sourced. Please run as '. $THIS_SCRIPT'" >&2 exit 1 fi if [ -z "$OEROOT" ]; then OEROOT=$(dirname "$THIS_SCRIPT") OEROOT=$(readlink -f "$OEROOT") fi unset THIS_SCRIPT export OEROOT . $OEROOT/scripts/oe-buildenv-internal && TEMPLATECONF="$TEMPLATECONF" $OEROOT/scripts/oe-setup-builddir || { unset OEROOT return 1 } unset OEROOT [ -z "$BUILDDIR" ] || cd "$BUILDDIR"
#!/bin/sh # OE Build Environment Setup Script # # Copyright (C) 2006-2011 Linux Foundation # # SPDX-License-Identifier: GPL-2.0-or-later # # # Normally this is called as '. ./oe-init-build-env <builddir>' # # This works in most shells (not dash), but not all of them pass the arguments # when being sourced. To workaround the shell limitation use "set <builddir>" # prior to sourcing this script. # if [ -n "$BASH_SOURCE" ]; then THIS_SCRIPT=$BASH_SOURCE elif [ -n "$ZSH_NAME" ]; then THIS_SCRIPT=$0 else THIS_SCRIPT="$(pwd)/oe-init-build-env" if [ ! -e "$THIS_SCRIPT" ]; then echo "Error: $THIS_SCRIPT doesn't exist!" >&2 echo "Please run this script in oe-init-build-env's directory." >&2 exit 1 fi fi if [ -n "$BBSERVER" ]; then unset BBSERVER fi if [ -z "$ZSH_NAME" ] && [ "$0" = "$THIS_SCRIPT" ]; then echo "Error: This script needs to be sourced. Please run as '. $THIS_SCRIPT'" >&2 exit 1 fi if [ -z "$OEROOT" ]; then OEROOT=$(dirname "$THIS_SCRIPT") OEROOT=$(readlink -f "$OEROOT") fi unset THIS_SCRIPT export OEROOT . $OEROOT/scripts/oe-buildenv-internal && TEMPLATECONF="$TEMPLATECONF" $OEROOT/scripts/oe-setup-builddir || { unset OEROOT return 1 } unset OEROOT [ -z "$BUILDDIR" ] || cd "$BUILDDIR"