| |
@@ -5,6 +5,7 @@
|
| |
from pyparsing import ParseException
|
| |
|
| |
from . import log
|
| |
+ from . import TARGET_ARCHES
|
| |
|
| |
pp.ParserElement.enablePackrat()
|
| |
|
| |
@@ -60,7 +61,7 @@
|
| |
|
| |
|
| |
@functools.cache
|
| |
- def evaluate_predicate(name: str, value: str) -> bool:
|
| |
+ def evaluate_predicate(name: str, value: str, target_arch: str) -> bool:
|
| |
# based on: https://doc.rust-lang.org/reference/conditional-compilation.html
|
| |
|
| |
match name:
|
| |
@@ -68,7 +69,7 @@
|
| |
# Needs to be ignored, as we cannot generate patches that are
|
| |
# different depending on the host architecture - except if the
|
| |
# target architecture is "wasm32", which we don't support.
|
| |
- return value not in ["wasm32", "wasm64"]
|
| |
+ return value == target_arch
|
| |
|
| |
case "target_feature":
|
| |
# The "target_feature" predicate can be ignored as well, since the
|
| |
@@ -114,30 +115,32 @@
|
| |
return True
|
| |
case "windows":
|
| |
return False
|
| |
+ case "miri":
|
| |
+ return False
|
| |
case _:
|
| |
log.warn(
|
| |
f"Ignoring unknown identifier {name!r} in cfg-expression. "
|
| |
- + 'Only "unix" and "windows" are standard identifiers, '
|
| |
- + 'any non-standard "--cfg" flags are not supported.'
|
| |
+ + 'only "unix", "windows", and "miri" are standard identifiers; '
|
| |
+ + 'any non-standard "--cfg" flags are ignored.'
|
| |
)
|
| |
return False
|
| |
|
| |
|
| |
- def evaluate(expr, nested=False) -> bool:
|
| |
+ def evaluate(expr, target_arch: str, nested: bool = False) -> bool:
|
| |
if hasattr(expr, "asList"):
|
| |
expr = expr.asList() # compat with pyparsing 2.7.x
|
| |
match expr:
|
| |
case ["cfg", subexpr] if not nested:
|
| |
- return evaluate(subexpr, True)
|
| |
+ return evaluate(subexpr, target_arch, True)
|
| |
case ["not", subexpr] if nested:
|
| |
- return not evaluate(subexpr, True)
|
| |
+ return not evaluate(subexpr, target_arch, True)
|
| |
case ["all", *args] if nested:
|
| |
- return all(evaluate(arg, True) for arg in args)
|
| |
+ return all(evaluate(arg, target_arch, True) for arg in args)
|
| |
case ["any", *args] if nested:
|
| |
- return any(evaluate(arg, True) for arg in args)
|
| |
+ return any(evaluate(arg, target_arch, True) for arg in args)
|
| |
case [variable, value] if nested:
|
| |
v = ast.literal_eval(value)
|
| |
- return evaluate_predicate(variable, v)
|
| |
+ return evaluate_predicate(variable, v, target_arch)
|
| |
case [variable] if nested:
|
| |
return evaluate_atom(variable)
|
| |
case _:
|
| |
@@ -145,5 +148,8 @@
|
| |
|
| |
|
| |
def parse_and_evaluate(expr):
|
| |
- parsed = cfg_grammar().parseString(expr)
|
| |
- return evaluate(parsed[0])
|
| |
+ parsed = cfg_grammar().parseString(expr)[0]
|
| |
+
|
| |
+ # evaluate cfg-expression for all supported target_arch values
|
| |
+ # returns True if it evaluates to True for any supported architecture
|
| |
+ return any(evaluate(parsed, target_arch) for target_arch in TARGET_ARCHES)
|
| |
Some cfg-expressions evaluated to "False" because all target_arch
checks were evaluated as "True", but that broke in situations where
the cfg-expression checked for the absence of a match for a specific
target_arch.
With this change, cfg-expressions are now evaluated once for every
supported target_arch, and they evaluate to "True" if the expression
evaluated to "True" for any value of target_arch.
Fixes #231