cutter/scripts/meson_configure_qmake_in.py
Florian Märkl 239a4bb620
CutterConfig.h (#663)
* Configure CutterConfig.h

* Configure CutterConfig.h in cmake

* Configure CutterConfig.h with meson
2018-08-26 20:37:11 +02:00

27 lines
631 B
Python

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)
content = re.sub(pattern, re.escape(str(value)), content)
with open(out_filename, "w") as f:
f.write(content)