diff options
author | stijn <stinos@zoho.com> | 2016-04-23 18:36:07 +0200 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-04-25 22:34:22 +0100 |
commit | 9264d42e2a5659fce2611ec30f15e88956a99695 (patch) | |
tree | 4eeaec5f7cfdb5b7133563911a2a411d4dae5fd5 /py/makeqstrdefs.py | |
parent | b2b771ca02327ce2a1a6896a0c2cd15b26834737 (diff) | |
download | micropython-9264d42e2a5659fce2611ec30f15e88956a99695.tar.gz micropython-9264d42e2a5659fce2611ec30f15e88956a99695.zip |
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
Diffstat (limited to 'py/makeqstrdefs.py')
-rw-r--r-- | py/makeqstrdefs.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/py/makeqstrdefs.py b/py/makeqstrdefs.py index 95e7c80a44..194d901d26 100644 --- a/py/makeqstrdefs.py +++ b/py/makeqstrdefs.py @@ -16,7 +16,8 @@ QSTRING_BLACK_LIST = {'NULL', 'number_of', } def write_out(fname, 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: f.write("\n".join(output) + "\n") @@ -24,11 +25,11 @@ def process_file(f): output = [] last_fname = None for line in f: - if line and line[0:2] == "# ": - comp = line.split() - fname = comp[2] - assert fname[0] == '"' and fname[-1] == '"' - fname = fname[1:-1] + # match gcc-like output (# n "file") and msvc-like output (#line n "file") + if line and (line[0:2] == "# " or line[0:5] == "#line"): + m = re.match(r"#[line]*\s\d+\s\"([^\"]+)\"", line) + assert m is not None + fname = m.group(1) if fname[0] == "/" or not fname.endswith(".c"): continue if fname != last_fname: @@ -70,6 +71,11 @@ def cat_together(): pass if old_hash != new_hash: 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) with open(args.output_file + ".hash", "w") as f: f.write(new_hash) |