Skip to content

Commit a925cb5

Browse files
committed
py: Preprocess qstrdefs.h before feeding to makeqstrdata.py.
This is alternative implementation of supporting conditionals in qstrdefs.h, hard to say if it's much cleaner than munging #ifdef's in Python code...
1 parent 6ea0e92 commit a925cb5

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

py/makeqstrdata.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def compute_hash(qstr):
2626
def do_work(infiles):
2727
# read the qstrs in from the input files
2828
qstrs = {}
29+
cpp_header_blocks = 3
2930
for infile in infiles:
3031
with open(infile, 'rt') as f:
3132
line_number = 0
@@ -37,6 +38,14 @@ def do_work(infiles):
3738
if len(line) == 0 or line.startswith('//'):
3839
continue
3940

41+
# We'll have 3 line-number lines for py/qstrdefs.h - initial, leaving it to
42+
# go into other headers, and returning to it.
43+
if line.startswith('# ') and 'py/qstrdefs.h' in line:
44+
cpp_header_blocks -= 1
45+
continue
46+
if cpp_header_blocks != 0:
47+
continue
48+
4049
# verify line is of the correct form
4150
match = re.match(r'Q\((.+)\)$', line)
4251
if not match:

py/py.mk

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ $(PY_BUILD)/py-version.h: FORCE
104104
# Adding an order only dependency on $(PY_BUILD) causes $(PY_BUILD) to get
105105
# created before we run the script to generate the .h
106106
$(PY_BUILD)/qstrdefs.generated.h: | $(PY_BUILD)/
107-
$(PY_BUILD)/qstrdefs.generated.h: $(PY_QSTR_DEFS) $(QSTR_DEFS) $(PY_SRC)/makeqstrdata.py
107+
$(PY_BUILD)/qstrdefs.generated.h: $(PY_QSTR_DEFS) $(QSTR_DEFS) $(PY_SRC)/makeqstrdata.py mpconfigport.h $(PY_SRC)/mpconfig.h
108108
$(ECHO) "makeqstrdata $(PY_QSTR_DEFS) $(QSTR_DEFS)"
109-
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdata.py $(PY_QSTR_DEFS) $(QSTR_DEFS) > $@
109+
$(CPP) $(CFLAGS) $(PY_QSTR_DEFS) -o $(PY_BUILD)/qstrdefs.preprocessed.h
110+
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdata.py $(PY_BUILD)/qstrdefs.preprocessed.h $(QSTR_DEFS) > $@
110111

111112
# We don't know which source files actually need the generated.h (since
112113
# it is #included from str.h). The compiler generated dependencies will cause

py/qstrdefs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
#include "mpconfig.h"
12
// All the qstr definitions in this file are available as constants.
23
// That is, they are in ROM and you can reference them simply as MP_QSTR_xxxx.
3-
// TODO make it so we can use #defines here to select only those words that will be used
44

55
Q(__build_class__)
66
Q(__class__)

0 commit comments

Comments
 (0)