2010-04-30 15:35:50 +00:00
|
|
|
def read_file(filename):
|
|
|
|
try:
|
|
|
|
f = file( filename, "r" )
|
|
|
|
except IOError, reason:
|
|
|
|
return "" # WARNING: can't raise an error now because of the new RDEPENDS handling. This is a bit ugly. :M:
|
|
|
|
else:
|
|
|
|
return f.read().strip()
|
|
|
|
return None
|
|
|
|
|
|
|
|
def ifelse(condition, iftrue = True, iffalse = False):
|
|
|
|
if condition:
|
|
|
|
return iftrue
|
|
|
|
else:
|
|
|
|
return iffalse
|
|
|
|
|
|
|
|
def conditional(variable, checkvalue, truevalue, falsevalue, d):
|
Convert to use direct access to the data store (instead of bb.data.*Var*())
This is the result of running the following over the metadata:
sed \
-e 's:bb.data.\(setVar([^,()]*,[^,()]*\), *\([^ )]*\) *):\2.\1):g' \
-e 's:bb.data.\(setVarFlag([^,()]*,[^,()]*,[^,()]*\), *\([^) ]*\) *):\2.\1):g' \
-e 's:bb.data.\(getVar([^,()]*\), *\([^(), ]*\) *,\([^)]*\)):\2.\1,\3):g' \
-e 's:bb.data.\(getVarFlag([^,()]*,[^,()]*\), *\([^(), ]*\) *,\([^)]*\)):\2.\1,\3):g' \
-e 's:bb.data.\(getVarFlag([^,()]*,[^,()]*\), *\([^() ]*\) *):\2.\1):g' \
-e 's:bb.data.\(getVar([^,()]*\), *\([^) ]*\) *):\2.\1):g' \
-i `grep -ril bb.data *`
(From OE-Core rev: b22831fd63164c4db9c0b72934d7d734a6585251)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2011-11-09 15:00:01 +00:00
|
|
|
if d.getVar(variable,1) == checkvalue:
|
2010-04-30 15:35:50 +00:00
|
|
|
return truevalue
|
|
|
|
else:
|
|
|
|
return falsevalue
|
|
|
|
|
|
|
|
def less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
|
Convert to use direct access to the data store (instead of bb.data.*Var*())
This is the result of running the following over the metadata:
sed \
-e 's:bb.data.\(setVar([^,()]*,[^,()]*\), *\([^ )]*\) *):\2.\1):g' \
-e 's:bb.data.\(setVarFlag([^,()]*,[^,()]*,[^,()]*\), *\([^) ]*\) *):\2.\1):g' \
-e 's:bb.data.\(getVar([^,()]*\), *\([^(), ]*\) *,\([^)]*\)):\2.\1,\3):g' \
-e 's:bb.data.\(getVarFlag([^,()]*,[^,()]*\), *\([^(), ]*\) *,\([^)]*\)):\2.\1,\3):g' \
-e 's:bb.data.\(getVarFlag([^,()]*,[^,()]*\), *\([^() ]*\) *):\2.\1):g' \
-e 's:bb.data.\(getVar([^,()]*\), *\([^) ]*\) *):\2.\1):g' \
-i `grep -ril bb.data *`
(From OE-Core rev: b22831fd63164c4db9c0b72934d7d734a6585251)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2011-11-09 15:00:01 +00:00
|
|
|
if float(d.getVar(variable,1)) <= float(checkvalue):
|
2010-04-30 15:35:50 +00:00
|
|
|
return truevalue
|
|
|
|
else:
|
|
|
|
return falsevalue
|
|
|
|
|
|
|
|
def version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
|
2012-02-23 20:46:13 +00:00
|
|
|
result = bb.utils.vercmp_string(d.getVar(variable,True), checkvalue)
|
2010-04-30 15:35:50 +00:00
|
|
|
if result <= 0:
|
|
|
|
return truevalue
|
|
|
|
else:
|
|
|
|
return falsevalue
|
|
|
|
|
|
|
|
def contains(variable, checkvalues, truevalue, falsevalue, d):
|
2011-07-25 18:03:08 +00:00
|
|
|
val = d.getVar(variable, True)
|
2010-04-30 15:35:50 +00:00
|
|
|
if not val:
|
|
|
|
return falsevalue
|
2011-07-25 18:03:08 +00:00
|
|
|
val = set(val.split())
|
|
|
|
if isinstance(checkvalues, basestring):
|
|
|
|
checkvalues = set(checkvalues.split())
|
|
|
|
else:
|
|
|
|
checkvalues = set(checkvalues)
|
|
|
|
if checkvalues.issubset(val):
|
2010-04-30 15:35:50 +00:00
|
|
|
return truevalue
|
|
|
|
return falsevalue
|
|
|
|
|
|
|
|
def both_contain(variable1, variable2, checkvalue, d):
|
Convert to use direct access to the data store (instead of bb.data.*Var*())
This is the result of running the following over the metadata:
sed \
-e 's:bb.data.\(setVar([^,()]*,[^,()]*\), *\([^ )]*\) *):\2.\1):g' \
-e 's:bb.data.\(setVarFlag([^,()]*,[^,()]*,[^,()]*\), *\([^) ]*\) *):\2.\1):g' \
-e 's:bb.data.\(getVar([^,()]*\), *\([^(), ]*\) *,\([^)]*\)):\2.\1,\3):g' \
-e 's:bb.data.\(getVarFlag([^,()]*,[^,()]*\), *\([^(), ]*\) *,\([^)]*\)):\2.\1,\3):g' \
-e 's:bb.data.\(getVarFlag([^,()]*,[^,()]*\), *\([^() ]*\) *):\2.\1):g' \
-e 's:bb.data.\(getVar([^,()]*\), *\([^) ]*\) *):\2.\1):g' \
-i `grep -ril bb.data *`
(From OE-Core rev: b22831fd63164c4db9c0b72934d7d734a6585251)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2011-11-09 15:00:01 +00:00
|
|
|
if d.getVar(variable1,1).find(checkvalue) != -1 and d.getVar(variable2,1).find(checkvalue) != -1:
|
2010-04-30 15:35:50 +00:00
|
|
|
return checkvalue
|
|
|
|
else:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
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 var.endswith(suffix):
|
2011-06-07 09:19:41 +00:00
|
|
|
var = var.replace(suffix, "")
|
|
|
|
|
|
|
|
prefix = d.getVar("MLPREFIX", True)
|
|
|
|
if prefix and var.startswith(prefix):
|
|
|
|
var = var.replace(prefix, "")
|
|
|
|
|
2010-04-30 15:35:50 +00:00
|
|
|
return var
|
|
|
|
|
|
|
|
def str_filter(f, str, d):
|
|
|
|
from re import match
|
|
|
|
return " ".join(filter(lambda x: match(f, x, 0), str.split()))
|
|
|
|
|
|
|
|
def str_filter_out(f, str, d):
|
|
|
|
from re import match
|
|
|
|
return " ".join(filter(lambda x: not match(f, x, 0), str.split()))
|
2010-08-03 17:18:03 +00:00
|
|
|
|
|
|
|
def param_bool(cfg, field, dflt = None):
|
|
|
|
"""Lookup <field> in <cfg> map and convert it to a boolean; take
|
|
|
|
<dflt> when this <field> does not exist"""
|
|
|
|
value = cfg.get(field, dflt)
|
|
|
|
strvalue = str(value).lower()
|
|
|
|
if strvalue in ('yes', 'y', 'true', 't', '1'):
|
|
|
|
return True
|
|
|
|
elif strvalue in ('no', 'n', 'false', 'f', '0'):
|
|
|
|
return False
|
|
|
|
raise ValueError("invalid value for boolean parameter '%s': '%s'" % (field, value))
|
2011-03-07 16:47:35 +00:00
|
|
|
|
|
|
|
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)
|
2012-02-23 19:26:09 +00:00
|
|
|
|
2012-07-10 13:38:02 +00:00
|
|
|
def features_backfill(var,d):
|
|
|
|
# This construct allows the addition of new features to variable specified
|
|
|
|
# as var
|
|
|
|
# Example for var = "DISTRO_FEATURES"
|
2012-02-23 19:26:09 +00:00
|
|
|
# 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
|
2013-03-09 10:33:25 +00:00
|
|
|
features = (d.getVar(var, True) or "").split()
|
2012-07-10 13:38:02 +00:00
|
|
|
backfill = (d.getVar(var+"_BACKFILL", True) or "").split()
|
|
|
|
considered = (d.getVar(var+"_BACKFILL_CONSIDERED", True) or "").split()
|
2012-02-23 19:26:09 +00:00
|
|
|
|
|
|
|
addfeatures = []
|
|
|
|
for feature in backfill:
|
2013-03-09 10:33:25 +00:00
|
|
|
if feature not in features and feature not in considered:
|
2012-02-23 19:26:09 +00:00
|
|
|
addfeatures.append(feature)
|
|
|
|
|
|
|
|
if addfeatures:
|
2013-03-09 10:33:25 +00:00
|
|
|
d.appendVar(var, " " + " ".join(addfeatures))
|
2013-04-04 16:34:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
def packages_filter_out_system(d):
|
|
|
|
"""
|
|
|
|
Return a list of packages from PACKAGES with the "system" packages such as
|
|
|
|
PN-dbg PN-doc PN-locale-eb-gb removed.
|
|
|
|
"""
|
|
|
|
pn = d.getVar('PN', True)
|
|
|
|
blacklist = map(lambda suffix: pn + suffix, ('', '-dbg', '-dev', '-doc', '-locale', '-staticdev'))
|
|
|
|
localepkg = pn + "-locale-"
|
|
|
|
pkgs = []
|
|
|
|
|
|
|
|
for pkg in d.getVar('PACKAGES', True).split():
|
|
|
|
if pkg not in blacklist and localepkg not in pkg:
|
|
|
|
pkgs.append(pkg)
|
|
|
|
return pkgs
|