Skip to content

Commit 1abe1db

Browse files
committed
py/mkrules,makeqstrdefs: Fix argument list too long error in qstr generation.
Support response files in makeqstrdefs.py to handle builds with large numbers of source files (e.g., LVGL with 1200+ files). This prevents shell argument limit exceeded errors during the qstr preprocessing step. The issue was first encountered when including large modules like LVGL. The ARG_MAX limit varies between systems (128KB - 2MB depending on kernel version), which explains why builds succeed on some machines but fail on others with identical source code. Changes: - Modified py/mkrules.mk to write source file list to qstr_sources.txt - Modified py/mkrules.cmake to use inline string replacement - Modified py/makeqstrdefs.py to read from response files with @ prefix This targeted fix only puts the large file list in a separate file while keeping all other arguments on the command line. Signed-off-by: Andrew Leech <[email protected]>
1 parent be48920 commit 1abe1db

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

py/makeqstrdefs.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,12 @@ class Args:
198198
if arg in named_args:
199199
current_tok = arg
200200
else:
201-
named_args[current_tok].append(arg)
201+
# Support response files (starting with @) to avoid argument list too long errors
202+
if arg.startswith("@") and os.path.isfile(arg[1:]):
203+
with open(arg[1:], "r") as f:
204+
named_args[current_tok].extend(f.read().splitlines())
205+
else:
206+
named_args[current_tok].append(arg)
202207

203208
if not named_args["pp"] or len(named_args["output"]) != 1:
204209
print("usage: %s %s ..." % (sys.argv[0], " ... ".join(named_args)))

py/mkrules.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,14 @@ add_custom_target(
122122
# If any of the dependencies in this rule change then the C-preprocessor step must be run.
123123
# It only needs to be passed the list of MICROPY_SOURCE_QSTR files that have changed since
124124
# it was last run, but it looks like it's not possible to specify that with cmake.
125+
126+
# Write source list to response file (convert semicolon-separated to newline-separated)
127+
string(REPLACE ";" "\n" _qstr_sources_newline "${MICROPY_SOURCE_QSTR}")
128+
file(WRITE "${MICROPY_GENHDR_DIR}/qstr_sources.txt" "${_qstr_sources_newline}")
129+
125130
add_custom_command(
126131
OUTPUT ${MICROPY_QSTRDEFS_LAST}
127-
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py pp ${CMAKE_C_COMPILER} -E output ${MICROPY_GENHDR_DIR}/qstr.i.last cflags ${MICROPY_CPP_FLAGS} -DNO_QSTR cxxflags ${MICROPY_CPP_FLAGS} -DNO_QSTR sources ${MICROPY_SOURCE_QSTR}
132+
COMMAND ${Python3_EXECUTABLE} ${MICROPY_PY_DIR}/makeqstrdefs.py pp ${CMAKE_C_COMPILER} -E output ${MICROPY_GENHDR_DIR}/qstr.i.last cflags ${MICROPY_CPP_FLAGS} -DNO_QSTR cxxflags ${MICROPY_CPP_FLAGS} -DNO_QSTR sources @${MICROPY_GENHDR_DIR}/qstr_sources.txt
128133
DEPENDS ${MICROPY_MPVERSION}
129134
${MICROPY_SOURCE_QSTR}
130135
VERBATIM

py/mkrules.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ $(OBJ): | $(HEADER_BUILD)/qstrdefs.generated.h $(HEADER_BUILD)/mpversion.h $(OBJ
134134
# See more information about this process in docs/develop/qstr.rst.
135135
$(HEADER_BUILD)/qstr.i.last: $(SRC_QSTR) $(QSTR_GLOBAL_DEPENDENCIES) | $(QSTR_GLOBAL_REQUIREMENTS)
136136
$(ECHO) "GEN $@"
137-
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py pp $(CPP) output $(HEADER_BUILD)/qstr.i.last cflags $(QSTR_GEN_CFLAGS) cxxflags $(QSTR_GEN_CXXFLAGS) sources $^ dependencies $(QSTR_GLOBAL_DEPENDENCIES) changed_sources $?
137+
$(Q)rm -f $(HEADER_BUILD)/qstr_sources.txt
138+
$(Q)for src in $^; do echo "$$src" >> $(HEADER_BUILD)/qstr_sources.txt; done
139+
$(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py pp $(CPP) output $(HEADER_BUILD)/qstr.i.last cflags $(QSTR_GEN_CFLAGS) cxxflags $(QSTR_GEN_CXXFLAGS) sources @$(HEADER_BUILD)/qstr_sources.txt dependencies $(QSTR_GLOBAL_DEPENDENCIES) changed_sources $?
138140

139141
$(HEADER_BUILD)/qstr.split: $(HEADER_BUILD)/qstr.i.last
140142
$(ECHO) "GEN $@"

0 commit comments

Comments
 (0)