cutter/scripts/meson_configure_qmake_in.py

27 lines
620 B
Python
Raw Permalink Normal View History

import sys
import re
import json
in_filename = sys.argv[1]
out_filename = sys.argv[2]
vars = json.loads(sys.argv[3])
with open(in_filename, "r") as f:
content = f.read()
content = content.replace("\\\"", "\"")
varname_pattern = re.compile("[A-Za-z0-9_]+")
for name, value in vars.items():
if varname_pattern.fullmatch(name) is None:
print("Name \"{}\" is not a valid variable name.".format(name))
continue
pattern = "\\$\\$({}|\\{{{}\\}})".format(name, name)
print(pattern)
2019-02-17 13:51:31 +00:00
content = re.sub(pattern, str(value), content)
with open(out_filename, "w") as f:
f.write(content)