Repository navigation
fix(ci): merge root platformio.ini build_flags into synthesised PIO env (#2664) - #2794
Conversation
bash compile --backend platformio synthesises a fresh PIO project at
.build/pio/<env>/platformio.ini from ci/boards.py and historically
ignored build_flags declared in the user's root platformio.ini. Anyone
editing [env:<board>].build_flags at the project root reasonably
expects those flags to take effect; without this merge they silently
vanish, producing "flags work under fbuild but not under platformio"
bugs (e.g. a missing ESP32-C6 USB-CDC routing flag → silent device).
This patch adds get_root_platformio_build_flags() in
ci/compiler/build_config.py, which reuses the existing PlatformIOIni
parser (handles extends + ${env:...} substitution) to extract the
matching env's flags. _init_platformio_build() in ci/compiler/pio.py
appends those flags to the cloned board's build_flags right before
apply_board_specific_config writes the synthesised ini.
Ordering: Board flags first, root flags appended — repeated -D's let
the root file override per PlatformIO's "last wins" semantics, which
matches the principle of least surprise for the issue's reporter.
A malformed or missing root ini returns [] and never blocks a build.
Tests: ci/tests/test_root_platformio_flag_merge.py covers the missing
file, no-matching-env, direct flags, extends inheritance with
${env:...} substitution, and malformed-input cases.
Closes #2664
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughThis PR resolves the silent discarding of root ChangesRoot platformio.ini build flags extraction and merge
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
ci/compiler/pio.py (1)
1-4:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winFix file structure: shebang must be line 1.
The shebang
#!/usr/bin/env python3must be the first line of the file. Currently, an import appears before it, which violates Python file structure conventions and the coding guidelines for import ordering.🔧 Proposed fix
-from ci.util.global_interrupt_handler import handle_keyboard_interrupt - - #!/usr/bin/env python3 """ PlatformIO Builder for FastLED Provides a clean interface for building FastLED projects with PlatformIO. """ +from ci.util.global_interrupt_handler import handle_keyboard_interrupt + import gc import hashlib🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ci/compiler/pio.py` around lines 1 - 4, Move the shebang to the very first line of the file and then place imports after it; specifically ensure "#!/usr/bin/env python3" appears before the import of handle_keyboard_interrupt (from ci.util.global_interrupt_handler import handle_keyboard_interrupt) and that import ordering follows PEP8 after the shebang.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@ci/compiler/pio.py`:
- Around line 1-4: Move the shebang to the very first line of the file and then
place imports after it; specifically ensure "#!/usr/bin/env python3" appears
before the import of handle_keyboard_interrupt (from
ci.util.global_interrupt_handler import handle_keyboard_interrupt) and that
import ordering follows PEP8 after the shebang.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d4137d56-10db-4473-b014-7458ad626db9
📒 Files selected for processing (3)
ci/compiler/build_config.pyci/compiler/pio.pyci/tests/test_root_platformio_flag_merge.py
Closes #2664.
Summary
bash compile --backend platformiosynthesises a fresh PIO project at.build/pio/<env>/platformio.inifromci/boards.pyand was silently discardingbuild_flagsdeclared in the user's rootplatformio.ini. Anyone editing[env:<board>].build_flagsat the project root reasonably expects those flags to take effect; without this merge they silently vanish, producing subtle "flags work under fbuild but not under--backend=platformio" bugs (e.g. a missing ESP32-C6 USB-CDC routing flag → silent device, ~1h debug for the issue reporter).Option chosen: 1 (merge)
Per the issue's "Proposed fix" list, option 1 ("Merge root
[env:<board>].build_flagsinto the synthesised PIO config") was straightforward to implement here because the codebase already has aPlatformIOIniparser (ci/compiler/platformio_ini.py) that resolvesextends =and${env:...}substitutions. No need to rewrite the synthesizer or change Board semantics.Option 2 (
extends = ../../../platformio.ini::env:<board>) was rejected: the synthesised file is written under.build/pio/<env>/after package URLs have been rewritten to localfile://paths, and a hardextendspointing at the original root file would re-introduce raw URLs and reorder cache optimisation. Option 3 (docs only) wasn't necessary because option 1 was small.Files changed
ci/compiler/build_config.py— new module-level helperget_root_platformio_build_flags(board_name, project_root). Reads the rootplatformio.ini, resolves inheritance via the existingPlatformIOIniparser, returns the matching env'sbuild_flags(or[]for missing file / no match / parse error — never raises).ci/compiler/pio.py—_init_platformio_build()calls the helper and appends the returned flags onto the cloned board'sbuild_flagsright beforeapply_board_specific_config()writes the synthesised ini. This sits next to the existing-Wl,-Map,…and-fopt-info-all=…augmentation block, which is the canonical place build_flags are extended for the synthesised env.ci/tests/test_root_platformio_flag_merge.py— 5 unit tests covering: missing root file, no matching[env:<board>], direct flags,extends+${env:...}substitution, malformed input.Ordering / precedence
Board flags first, root flags appended. PlatformIO's "last wins" semantics for repeated
-D/ linker flags mean the root file effectively overrides the Board — which is what the issue reporter expects, since they're editing the obvious file.Test plan
uv run pytest ci/tests/test_root_platformio_flag_merge.py ci/tests/test_board_to_platformio_ini.py -v→ 8 passedbash lint→ all phases green (python_pipeline, cpp_linting, javascript_linting, meson_linting)-DSOME_FLAG=1to[env:esp32c6]in rootplatformio.ini, runbash compile esp32c6 --examples AutoResearch --backend platformio, confirmSOME_FLAGappears in.build/pio/esp32c6/platformio.iniand in the compiled firmware.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
platformio.iniconfiguration file, which will be properly resolved and merged during the build process.Tests