Skip to content

Regenerate translation data when TRANSLATION changes in a build dir - #11372

Open
dhalbert wants to merge 1 commit into
adafruit:mainfrom
dhalbert:translation-stamp
Open

Regenerate translation data when TRANSLATION changes in a build dir#11372
dhalbert wants to merge 1 commit into
adafruit:mainfrom
dhalbert:translation-stamp

Conversation

@dhalbert

Copy link
Copy Markdown
Collaborator

Claude wrote this fix, with @dhalbert directing and reviewing.

Problem

Building a language for the second time in the same build directory produces broken firmware. For example: build en_US, then fr, then en_US again.

compressed_translations.generated.h depends on the generator script, the language's .mo file and qstrdefs.generated.h. On the third build all three are older than the header that fr just generated, so make does not regenerate it. translations-en_US.c is a side effect of the same rule, so it is not regenerated either. The firmware links en_US strings against fr's Huffman tables and prints garbage. Its size looks plausible, so nothing flags the problem.

First visits are fine: the .mo file is created fresh, so the header regenerates. That is why the release builds, which visit each language once, are unaffected.

Fix

  • py/py.mk: add $(HEADER_BUILD)/translation.stamp, a FORCE rule that rewrites the file only when its content differs from $(TRANSLATION), and make it a prerequisite of compressed_translations.generated.h. A language change regenerates the header and translations-*.c, which rebuilds translate.o and the translations object and relinks. Rebuilding the same language stays a no-op.

Testing

Built metro_m4_express en_US, fr, en_US, en_US in one build directory: the header's checksum changed on each language switch and returned to its original value, the firmware relinked each time with the correct size (4,952 bytes free for en_US, 1,596 for fr), and the fourth build regenerated and relinked nothing.

🤖 Generated with Claude Code

`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 <noreply@anthropic.com>
@mikeysklar

Copy link
Copy Markdown
Collaborator

Tested on our 8 board farm: Metro M0 Express, Metro M4 AirLift Lite, Metro RP2040, Metro RP2350, Feather nRF52840 Express, Feather STM32F405 Express, Metro ESP32-S2, Metro ESP32-S3.

Built en_US, fr, en_US, en_US in one build directory per board. With the patch the header and firmware checksums changed on each language switch and came back to the step 1 values, the fourth build was a no-op, and the step 3 firmware matched a clean en_US build. The same sequence on the merge base (M4) reproduced the bug: step 3 finished in 1 s and left the fr firmware in place.

Then flashed the fr build and the step 3 en_US build on each board and checked the REPL (ImportError text and the soft reboot line). All 8 boards printed French, then English.

Image sizes are unchanged vs the merge base. Bytes free in flash, en_US:

Board before after
Metro M0 Express 2344 2344
Metro M4 AirLift Lite 10416 10416
Metro RP2040 72092 72092
Metro RP2350 118540 118540
Feather nRF52840 Express 134888 134888
Feather STM32F405 Express 365884 365884
Metro ESP32-S2 1298224 1298224
Metro ESP32-S3 148816 148816

Looks good to us.

@dhalbert

Copy link
Copy Markdown
Collaborator Author

The meowbit failure is not due to the changes here.

@dhalbert
dhalbert requested a review from tannewt September 14, 2026 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants