From 2a85995eb680d07e6d6ab93f97682990f6223de0 Mon Sep 17 00:00:00 2001 From: stijn Date: Wed, 28 Aug 2024 12:33:28 +0200 Subject: [PATCH] py: Reuse makeqstrdefs split output instead of touching files. 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 --- docs/develop/qstr.rst | 4 ++-- py/makeqstrdefs.py | 22 +++++++++++++++++----- py/mkrules.cmake | 15 ++++++--------- py/mkrules.mk | 20 ++++++++------------ 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/docs/develop/qstr.rst b/docs/develop/qstr.rst index 5d1ac5bb4a49..49c08baa2217 100644 --- a/docs/develop/qstr.rst +++ b/docs/develop/qstr.rst @@ -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 diff --git a/py/makeqstrdefs.py b/py/makeqstrdefs.py index c68ed99de16a..838ff055d605 100644 --- a/py/makeqstrdefs.py +++ b/py/makeqstrdefs.py @@ -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) @@ -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() diff --git a/py/mkrules.cmake b/py/mkrules.cmake index bfc56abfe80b..fa4d0c1ee5da 100644 --- a/py/mkrules.cmake +++ b/py/mkrules.cmake @@ -89,8 +89,7 @@ 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 @@ -98,7 +97,7 @@ add_custom_command( 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 @@ -127,8 +126,7 @@ 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 @@ -136,7 +134,7 @@ add_custom_command( 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 @@ -153,8 +151,7 @@ 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 @@ -162,7 +159,7 @@ add_custom_command( 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 diff --git a/py/mkrules.mk b/py/mkrules.mk index 0dc1cdfe15ac..471d4936509f 100644 --- a/py/mkrules.mk +++ b/py/mkrules.mk @@ -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 #