fxconv: resolve name_regex in the fxconv-metadata.txt API

Lephenixnoir 2021-12-28 19:01:43 +01:00
parent 4d46661d3b
commit bbf716b031
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
1 changed files with 9 additions and 7 deletions

View File

@ -1178,11 +1178,7 @@ def convert(input, params, target, output=None, model=None, custom=None):
if output is None:
output = os.path.splitext(input)[0] + ".o"
if "name" in params:
elif "name_regex" in params:
params["name"] = re.sub(*params["name_regex"], os.path.basename(input))
if "name" not in params:
raise FxconvError(f"no name specified for conversion '{input}'")
if target["arch"] is None:
@ -1448,7 +1444,8 @@ class Metadata:
def rules_for(self, path):
Returns the parameters that apply to the specified path, or None if no
wildcard matches it.
wildcard matches it. The special key "name_regex" is also resolved into
the regular key "name".
basename = os.path.basename(path)
@ -1460,4 +1457,9 @@ class Metadata:
matched = True
return params if matched else None
if not matched:
return None
if "name_regex" in params and not "name" in params:
params["name"] = re.sub(*params["name_regex"], basename)
return params