summaryrefslogtreecommitdiffstats
path: root/source-builder/sb/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'source-builder/sb/config.py')
-rw-r--r--source-builder/sb/config.py126
1 files changed, 63 insertions, 63 deletions
diff --git a/source-builder/sb/config.py b/source-builder/sb/config.py
index 5bc96e2..06762d6 100644
--- a/source-builder/sb/config.py
+++ b/source-builder/sb/config.py
@@ -68,6 +68,13 @@ def _check_nil(value):
istrue = False
return istrue
+def _check_number(value):
+ try:
+ float(value)
+ return True
+ except ValueError:
+ return False
+
class package:
def __init__(self, name, arch, config):
@@ -251,7 +258,7 @@ class file:
re.compile('%select'),
re.compile('%disable') ]
- def __init__(self, name, opts, macros = None):
+ def __init__(self, name, opts, macros = None, load = True):
log.trace('config: %s: initialising' % (name))
self.opts = opts
self.init_name = name
@@ -260,7 +267,8 @@ class file:
self.sf = re.compile(r'%\([^\)]+\)')
self.set_macros(macros)
self._reset(name)
- self.load(name)
+ if load:
+ self.load(name)
def __str__(self):
@@ -778,7 +786,16 @@ class file:
mn = '%{nil}'
if mn:
if mn.lower() in self.macros:
- s = s.replace(m, self.macros[mn.lower()])
+ em = self.macros[mn.lower()]
+ if self.macros.get_type(mn) == 'dir' and ':' in em:
+ ss = []
+ for sp in s.split():
+ if m in sp:
+ sp = ':'.join([sp.replace(mn, ps) for ps in em.split(':')])
+ ss += [sp]
+ s = ' '.join(ss)
+ else:
+ s = s.replace(m, self.macros[mn.lower()])
expanded = True
elif show_warning:
self._error("macro '%s' not found" % (mn))
@@ -915,6 +932,12 @@ class file:
(self.name, self.lc,
self.if_depth,
join_op))
+ # If OR and the previous check was true short circuit the evaluation
+ if join_op == 'or' and cistrue:
+ log.trace('config: %s: %3d: _if[%i]: OR true, short circuit eval' % \
+ (self.name, self.lc,
+ self.if_depth))
+ break
ori = 0
andi = 0
i = len(cls)
@@ -935,10 +958,8 @@ class file:
i = andi
elif andi == 0:
i = ori
- elif ori < andi:
- i = andi
else:
- i = andi
+ i = min(ori, andi)
log.trace('config: %s: %3d: _if[%i]: next OP found at %i' % \
(self.name, self.lc,
self.if_depth,
@@ -996,37 +1017,27 @@ class file:
ifls = (' '.join(ifls[:op_pos]), op, ' '.join(ifls[op_pos + 1:]))
break
if len(ifls) != 3:
- self._error('malformed if: ' + reduce(add, ls, ''))
- if ifls[1] == '==':
- if ifls[0] == ifls[2]:
- istrue = True
- else:
- istrue = False
- elif ifls[1] == '!=' or ifls[1] == '=!':
- if ifls[0] != ifls[2]:
- istrue = True
- else:
- istrue = False
- elif ifls[1] == '>':
- if ifls[0] > ifls[2]:
- istrue = True
- else:
- istrue = False
- elif ifls[1] == '>=' or ifls[1] == '=>':
- if ifls[0] >= ifls[2]:
- istrue = True
- else:
- istrue = False
- elif ifls[1] == '<=' or ifls[1] == '=<':
- if ifls[0] <= ifls[2]:
- istrue = True
- else:
- istrue = False
- elif ifls[1] == '<':
- if ifls[0] < ifls[2]:
- istrue = True
- else:
- istrue = False
+ self._error('malformed if: ' + reduce(add, ls, ''))
+ lhs = ifls[0]
+ operator = ifls[1]
+ rhs = ifls[2]
+ if _check_number(lhs) and _check_number(rhs):
+ log.trace('config: %s: %3d: _if: numeric value check' % \
+ (self.name, self.lc))
+ lhs = float(lhs)
+ rhs = float(rhs)
+ if operator == '==':
+ istrue = lhs == rhs
+ elif operator == '!=' or operator == '=!':
+ istrue = lhs != rhs
+ elif operator == '>':
+ istrue = lhs > rhs
+ elif operator == '>=' or operator == '=>':
+ istrue = lhs >= rhs
+ elif operator == '<=' or operator == '=<':
+ istrue = lhs <= rhs
+ elif operator == '<':
+ istrue = lhs < rhs
else:
self._error('invalid %if operator: ' + reduce(add, ls, ''))
@@ -1344,6 +1355,14 @@ class file:
right = right[:-1]
return end
+ def search_path(confignames):
+ for configname in confignames.split(':'):
+ if not configname.endswith('.cfg'):
+ configname = '%s.cfg' % (configname)
+ if path.exists(configname):
+ return configname
+ return None
+
if self.load_depth == 0:
self._packages[self.package] = package(self.package,
self.define('%{_arch}'),
@@ -1357,7 +1376,7 @@ class file:
#
# Locate the config file. Expand any macros then add the
- # extension. Check if the file exists, therefore directly
+ # extension. Check if the file exists then it is directly
# referenced. If not see if the file contains ':' or the path
# separator. If it does split the path else use the standard config dir
# path in the defaults.
@@ -1365,32 +1384,13 @@ class file:
exname = self.expand(name)
- #
- # Macro could add an extension.
- #
- if exname.endswith('.cfg'):
- configname = exname
- else:
- configname = '%s.cfg' % (exname)
- name = '%s.cfg' % (name)
-
- if ':' in configname:
- cfgname = path.basename(configname)
- else:
- cfgname = common_end(configname, name)
+ configname = search_path(exname)
+ if configname is None:
+ configname = search_path(self.expand(path.join('%{_configdir}', exname)))
+ if configname is None:
+ raise error.general('no config file found: %s' % (','.join(exname.split(':'))))
- if not path.exists(configname):
- if ':' in configname:
- configdirs = path.dirname(configname).split(':')
- else:
- configdirs = self.define('_configdir').split(':')
- for cp in configdirs:
- configname = path.join(path.abspath(cp), cfgname)
- if path.exists(configname):
- break
- configname = None
- if configname is None:
- raise error.general('no config file found: %s' % (cfgname))
+ name = path.basename(configname)
try:
log.trace('config: %s: _open: %s' % (self.name, path.host(configname)))