From a07cbe9416ef2ff729a06c946d2042f5ec48fafe Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sun, 13 Sep 2026 16:54:01 -0400 Subject: [PATCH] Regenerate translation data when TRANSLATION changes in a build dir `compressed_translations.generated.h` depended only on the generator, the `.mo` file and `qstrdefs.generated.h`, all of which are older than the header once a language has been built once. Building another language in the same directory therefore kept the previous language's Huffman tables and linked the new language's strings against them, and switching back to an already-built language did not relink at all. Add `translation.stamp`, rewritten only when `TRANSLATION` differs from its content, as a prerequisite of the header. A language change now regenerates the header and `translations-*.c`, which rebuilds `translate.o` and the translations object and relinks the firmware. Rebuilding the same language is still a no-op. Co-Authored-By: Claude Fable 5.1 --- py/py.mk | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/py/py.mk b/py/py.mk index ff7de79b9d8..8326ea4b637 100644 --- a/py/py.mk +++ b/py/py.mk @@ -302,6 +302,14 @@ $(HEADER_BUILD)/compressed.data.h: $(HEADER_BUILD)/compressed.collected $(HEADER_BUILD)/$(TRANSLATION).mo: $(TOP)/locale/$(TRANSLATION).po | $(HEADER_BUILD) $(Q)$(PYTHON) $(TOP)/tools/msgfmt.py -o $@ $^ +# Records which TRANSLATION the generated header was built for. It is rewritten +# only when the language changes, so that building another language in the +# same build directory regenerates compressed_translations.generated.h and +# translations-*.c instead of linking one language's strings against another +# language's tables. +$(HEADER_BUILD)/translation.stamp: FORCE | $(HEADER_BUILD) + $(Q)if [ "$$(cat $@ 2>/dev/null)" != "$(TRANSLATION)" ]; then echo "$(TRANSLATION)" > $@; fi + # translations-*.c is generated as a side-effect of building compressed_translations.generated.h # Specifying both in a single rule actually causes the rule to be run twice! # This alternative makes it run just once. @@ -310,7 +318,7 @@ $(HEADER_BUILD)/$(TRANSLATION).mo: $(TOP)/locale/$(TRANSLATION).po | $(HEADER_BU $(PY_BUILD)/translations-$(TRANSLATION).c: $(HEADER_BUILD)/compressed_translations.generated.h @true -$(HEADER_BUILD)/compressed_translations.generated.h: $(PY_SRC)/maketranslationdata.py $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.generated.h +$(HEADER_BUILD)/compressed_translations.generated.h: $(PY_SRC)/maketranslationdata.py $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.generated.h $(HEADER_BUILD)/translation.stamp $(STEPECHO) "GEN $@" $(Q)mkdir -p $(PY_BUILD) $(Q)$(PYTHON) $(PY_SRC)/maketranslationdata.py --compression_filename $(HEADER_BUILD)/compressed_translations.generated.h --translation $(HEADER_BUILD)/$(TRANSLATION).mo --translation_filename $(PY_BUILD)/translations-$(TRANSLATION).c --qstrdefs_filename $(HEADER_BUILD)/qstrdefs.generated.h --compression_level $(CIRCUITPY_MESSAGE_COMPRESSION_LEVEL) $(HEADER_BUILD)/qstrdefs.preprocessed.h