Skip to content

Commit

Permalink
py: Reuse makeqstrdefs split output instead of touching files.
Browse files Browse the repository at this point in the history
Since previous commit calling 'makeqstrdefs.py split' will generate
a file already so it's not needed to touch another file anymore.

Signed-off-by: stijn <[email protected]>
  • Loading branch information
stinos committed Sep 11, 2024
1 parent 45a0bec commit 2a85995
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
4 changes: 2 additions & 2 deletions docs/develop/qstr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ Processing happens in the following stages:
means that ``qstr.i.last`` will only contain data from files that have
changed since the last compile.

2. ``qstr.split`` is an empty file created after running ``makeqstrdefs.py split``
on qstr.i.last. It's just used as a dependency to indicate that the step ran.
2. ``qstr.split`` is a file created after running ``makeqstrdefs.py split``
on qstr.i.last. It's used as a dependency to indicate that the step ran.
This script outputs one file per input C file, ``genhdr/qstr/...file.c.qstr``,
which contains only the matched QSTRs. Each QSTR is printed as ``Q(Foo)``.
This step is necessary to combine the existing files with the new data
Expand Down
22 changes: 17 additions & 5 deletions py/makeqstrdefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,11 @@ class Args:
sys.exit(0)

args.mode = sys.argv[2]
args.input_filename = sys.argv[3] # Unused for command=cat
args.input_filename = sys.argv[3] # Possibly unused for command=cat
args.output_dir = sys.argv[4]
args.output_file = None if len(sys.argv) == 5 else sys.argv[5] # Unused for command=split

args.output_file = (
None if len(sys.argv) == 5 else sys.argv[5]
) # Possibly unused for command=split
if args.mode not in (_MODE_QSTR, _MODE_COMPRESS, _MODE_MODULE, _MODE_ROOT_POINTER):
print("error: mode %s unrecognised" % sys.argv[2])
sys.exit(2)
Expand All @@ -238,12 +239,23 @@ class Args:
except OSError:
pass

if args.command in ("split", "cat"):
args.split_file = args.output_dir + "/" + args.mode + ".split"
# _ has been used historically to indicate 'not an actual argument'
def is_actual_file(arg):
return args is not None and arg != "_"

if args.command == "split":
args.split_file = (
args.output_file
if is_actual_file(args.output_file)
else args.output_dir + "/" + args.mode + ".split"
)
with io.open(args.input_filename, encoding="utf-8") as infile:
process_file(infile)

if args.command == "cat":
args.split_file = (
args.input_filename
if is_actual_file(args.input_filename)
else args.output_dir + "/" + args.mode + ".split"
)
cat_together()
15 changes: 6 additions & 9 deletions py/mkrules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,15 @@ add_custom_command(

add_custom_command(
OUTPUT ${MICROPY_QSTRDEFS_SPLIT}
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py split qstr ${MICROPY_GENHDR_DIR}/qstr.i.last ${MICROPY_GENHDR_DIR}/qstr _
COMMAND touch ${MICROPY_QSTRDEFS_SPLIT}
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py split qstr ${MICROPY_GENHDR_DIR}/qstr.i.last ${MICROPY_GENHDR_DIR}/qstr ${MICROPY_QSTRDEFS_SPLIT}
DEPENDS ${MICROPY_QSTRDEFS_LAST}
VERBATIM
COMMAND_EXPAND_LISTS
)

add_custom_command(
OUTPUT ${MICROPY_QSTRDEFS_COLLECTED}
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py cat qstr _ ${MICROPY_GENHDR_DIR}/qstr ${MICROPY_QSTRDEFS_COLLECTED}
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py cat qstr ${MICROPY_QSTRDEFS_SPLIT} ${MICROPY_GENHDR_DIR}/qstr ${MICROPY_QSTRDEFS_COLLECTED}
BYPRODUCTS "${MICROPY_QSTRDEFS_COLLECTED}.hash"
DEPENDS ${MICROPY_QSTRDEFS_SPLIT}
VERBATIM
Expand Down Expand Up @@ -127,16 +126,15 @@ add_custom_command(

add_custom_command(
OUTPUT ${MICROPY_MODULEDEFS_SPLIT}
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py split module ${MICROPY_GENHDR_DIR}/qstr.i.last ${MICROPY_GENHDR_DIR}/module _
COMMAND touch ${MICROPY_MODULEDEFS_SPLIT}
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py split module ${MICROPY_GENHDR_DIR}/qstr.i.last ${MICROPY_GENHDR_DIR}/module ${MICROPY_MODULEDEFS_SPLIT}
DEPENDS ${MICROPY_QSTRDEFS_LAST}
VERBATIM
COMMAND_EXPAND_LISTS
)

add_custom_command(
OUTPUT ${MICROPY_MODULEDEFS_COLLECTED}
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py cat module _ ${MICROPY_GENHDR_DIR}/module ${MICROPY_MODULEDEFS_COLLECTED}
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py cat module ${MICROPY_MODULEDEFS_SPLIT} ${MICROPY_GENHDR_DIR}/module ${MICROPY_MODULEDEFS_COLLECTED}
BYPRODUCTS "${MICROPY_MODULEDEFS_COLLECTED}.hash"
DEPENDS ${MICROPY_MODULEDEFS_SPLIT}
VERBATIM
Expand All @@ -153,16 +151,15 @@ add_custom_command(

add_custom_command(
OUTPUT ${MICROPY_ROOT_POINTERS_SPLIT}
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py split root_pointer ${MICROPY_GENHDR_DIR}/qstr.i.last ${MICROPY_GENHDR_DIR}/root_pointer _
COMMAND touch ${MICROPY_ROOT_POINTERS_SPLIT}
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py split root_pointer ${MICROPY_GENHDR_DIR}/qstr.i.last ${MICROPY_GENHDR_DIR}/root_pointer ${MICROPY_ROOT_POINTERS_SPLIT}
DEPENDS ${MICROPY_QSTRDEFS_LAST}
VERBATIM
COMMAND_EXPAND_LISTS
)

add_custom_command(
OUTPUT ${MICROPY_ROOT_POINTERS_COLLECTED}
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py cat root_pointer _ ${MICROPY_GENHDR_DIR}/root_pointer ${MICROPY_ROOT_POINTERS_COLLECTED}
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py cat root_pointer ${MICROPY_ROOT_POINTERS_SPLIT} ${MICROPY_GENHDR_DIR}/root_pointer ${MICROPY_ROOT_POINTERS_COLLECTED}
BYPRODUCTS "${MICROPY_ROOT_POINTERS_COLLECTED}.hash"
DEPENDS ${MICROPY_ROOT_POINTERS_SPLIT}
VERBATIM
Expand Down
20 changes: 8 additions & 12 deletions py/mkrules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -123,42 +123,38 @@ $(HEADER_BUILD)/qstr.i.last: $(SRC_QSTR) $(QSTR_GLOBAL_DEPENDENCIES) | $(QSTR_GL

$(HEADER_BUILD)/qstr.split: $(HEADER_BUILD)/qstr.i.last
$(ECHO) "GEN $@"
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py split qstr $< $(HEADER_BUILD)/qstr _
$(Q)$(TOUCH) $@
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py split qstr $< $(HEADER_BUILD)/qstr $(HEADER_BUILD)/qstr.split

$(QSTR_DEFS_COLLECTED): $(HEADER_BUILD)/qstr.split
$(ECHO) "GEN $@"
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py cat qstr _ $(HEADER_BUILD)/qstr $@
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py cat qstr $(HEADER_BUILD)/qstr.split $(HEADER_BUILD)/qstr $@

# Module definitions via MP_REGISTER_MODULE.
$(HEADER_BUILD)/moduledefs.split: $(HEADER_BUILD)/qstr.i.last
$(ECHO) "GEN $@"
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py split module $< $(HEADER_BUILD)/module _
$(Q)$(TOUCH) $@
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py split module $< $(HEADER_BUILD)/module $(HEADER_BUILD)/moduledefs.split

$(HEADER_BUILD)/moduledefs.collected: $(HEADER_BUILD)/moduledefs.split
$(ECHO) "GEN $@"
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py cat module _ $(HEADER_BUILD)/module $@
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py cat module $(HEADER_BUILD)/moduledefs.split $(HEADER_BUILD)/module $@

# Module definitions via MP_REGISTER_ROOT_POINTER.
$(HEADER_BUILD)/root_pointers.split: $(HEADER_BUILD)/qstr.i.last
$(ECHO) "GEN $@"
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py split root_pointer $< $(HEADER_BUILD)/root_pointer _
$(Q)$(TOUCH) $@
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py split root_pointer $< $(HEADER_BUILD)/root_pointer $(HEADER_BUILD)/root_pointers.split

$(HEADER_BUILD)/root_pointers.collected: $(HEADER_BUILD)/root_pointers.split
$(ECHO) "GEN $@"
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py cat root_pointer _ $(HEADER_BUILD)/root_pointer $@
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py cat root_pointer $(HEADER_BUILD)/root_pointers.split $(HEADER_BUILD)/root_pointer $@

# Compressed error strings.
$(HEADER_BUILD)/compressed.split: $(HEADER_BUILD)/qstr.i.last
$(ECHO) "GEN $@"
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py split compress $< $(HEADER_BUILD)/compress _
$(Q)$(TOUCH) $@
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py split compress $< $(HEADER_BUILD)/compress $(HEADER_BUILD)/compressed.split

$(HEADER_BUILD)/compressed.collected: $(HEADER_BUILD)/compressed.split
$(ECHO) "GEN $@"
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py cat compress _ $(HEADER_BUILD)/compress $@
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py cat compress $(HEADER_BUILD)/compressed.split $(HEADER_BUILD)/compress $@

# $(sort $(var)) removes duplicates
#
Expand Down

0 comments on commit 2a85995

Please sign in to comment.