py/makeqstrdefs.py: Windows compatibility.
- msvc preprocessor output contains full paths with backslashes so the ':' and '\' characters needs to be erased from the paths as well - use a regex for extraction of filenames from preprocessor output so it can handle both gcc and msvc preprocessor output, and spaces in paths (also thanks to a PR from @travnicekivo for part of that regex) - os.rename will fail on windows if the destination file already exists, so simply attempt to delete that file first
This commit is contained in:
parent
b2b771ca02
commit
9264d42e2a
@ -16,7 +16,8 @@ QSTRING_BLACK_LIST = {'NULL', 'number_of', }
|
|||||||
|
|
||||||
def write_out(fname, output):
|
def write_out(fname, output):
|
||||||
if output:
|
if output:
|
||||||
fname = fname.replace("/", "__").replace("..", "@@")
|
for m, r in [("/", "__"), ("\\", "__"), (":", "@"), ("..", "@@")]:
|
||||||
|
fname = fname.replace(m, r)
|
||||||
with open(args.output_dir + "/" + fname + ".qstr", "w") as f:
|
with open(args.output_dir + "/" + fname + ".qstr", "w") as f:
|
||||||
f.write("\n".join(output) + "\n")
|
f.write("\n".join(output) + "\n")
|
||||||
|
|
||||||
@ -24,11 +25,11 @@ def process_file(f):
|
|||||||
output = []
|
output = []
|
||||||
last_fname = None
|
last_fname = None
|
||||||
for line in f:
|
for line in f:
|
||||||
if line and line[0:2] == "# ":
|
# match gcc-like output (# n "file") and msvc-like output (#line n "file")
|
||||||
comp = line.split()
|
if line and (line[0:2] == "# " or line[0:5] == "#line"):
|
||||||
fname = comp[2]
|
m = re.match(r"#[line]*\s\d+\s\"([^\"]+)\"", line)
|
||||||
assert fname[0] == '"' and fname[-1] == '"'
|
assert m is not None
|
||||||
fname = fname[1:-1]
|
fname = m.group(1)
|
||||||
if fname[0] == "/" or not fname.endswith(".c"):
|
if fname[0] == "/" or not fname.endswith(".c"):
|
||||||
continue
|
continue
|
||||||
if fname != last_fname:
|
if fname != last_fname:
|
||||||
@ -70,6 +71,11 @@ def cat_together():
|
|||||||
pass
|
pass
|
||||||
if old_hash != new_hash:
|
if old_hash != new_hash:
|
||||||
print("QSTR updated")
|
print("QSTR updated")
|
||||||
|
try:
|
||||||
|
# rename below might fail if file exists
|
||||||
|
os.remove(args.output_file)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
os.rename(args.output_dir + "/out", args.output_file)
|
os.rename(args.output_dir + "/out", args.output_file)
|
||||||
with open(args.output_file + ".hash", "w") as f:
|
with open(args.output_file + ".hash", "w") as f:
|
||||||
f.write(new_hash)
|
f.write(new_hash)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user