summaryrefslogtreecommitdiffstats
path: root/source-builder
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2022-04-26 10:12:58 +1000
committerChris Johns <chrisj@rtems.org>2022-04-26 10:12:58 +1000
commit4c3708f127a4dd179271a8f17855a4f209953bd5 (patch)
tree6d2995529071d0698a40a4a66fe0ab55267f5555 /source-builder
parent6/7: Use gmp-6.2.1 for GDB (diff)
downloadrtems-source-builder-4c3708f127a4dd179271a8f17855a4f209953bd5.tar.bz2
sb: %if checks are numeric if the left and right values are numbers
- If the left and right values are numbers make the check numeric. Update #4631
Diffstat (limited to 'source-builder')
-rw-r--r--source-builder/sb/config.py69
1 files changed, 35 insertions, 34 deletions
diff --git a/source-builder/sb/config.py b/source-builder/sb/config.py
index 5bc96e2..ad078d9 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):
@@ -915,6 +922,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 +948,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 +1007,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, ''))