Skip to content

Commit 9264d42

Browse files
stinosdpgeorge
authored andcommitted
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
1 parent b2b771c commit 9264d42

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

py/makeqstrdefs.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@
1616

1717
def write_out(fname, output):
1818
if output:
19-
fname = fname.replace("/", "__").replace("..", "@@")
19+
for m, r in [("/", "__"), ("\\", "__"), (":", "@"), ("..", "@@")]:
20+
fname = fname.replace(m, r)
2021
with open(args.output_dir + "/" + fname + ".qstr", "w") as f:
2122
f.write("\n".join(output) + "\n")
2223

2324
def process_file(f):
2425
output = []
2526
last_fname = None
2627
for line in f:
27-
if line and line[0:2] == "# ":
28-
comp = line.split()
29-
fname = comp[2]
30-
assert fname[0] == '"' and fname[-1] == '"'
31-
fname = fname[1:-1]
28+
# match gcc-like output (# n "file") and msvc-like output (#line n "file")
29+
if line and (line[0:2] == "# " or line[0:5] == "#line"):
30+
m = re.match(r"#[line]*\s\d+\s\"([^\"]+)\"", line)
31+
assert m is not None
32+
fname = m.group(1)
3233
if fname[0] == "/" or not fname.endswith(".c"):
3334
continue
3435
if fname != last_fname:
@@ -70,6 +71,11 @@ def cat_together():
7071
pass
7172
if old_hash != new_hash:
7273
print("QSTR updated")
74+
try:
75+
# rename below might fail if file exists
76+
os.remove(args.output_file)
77+
except:
78+
pass
7379
os.rename(args.output_dir + "/out", args.output_file)
7480
with open(args.output_file + ".hash", "w") as f:
7581
f.write(new_hash)

0 commit comments

Comments
 (0)