Skip to content

fix(ci): mirror fbuild artifacts AFTER pio metadata gen (AVR8JS+QEMU still red) - #2291

Merged
zackees merged 1 commit into
masterfrom
fix-fbuild-mirror-order
Apr 18, 2026
Merged

zackees merged 1 commit into
masterfrom
fix-fbuild-mirror-order

Conversation

@zackees

@zackees zackees commented Apr 18, 2026 •

Copy link
Copy Markdown
Member

Summary

PR #2285 added _mirror_fbuild_artifacts_to_pio to copy firmware artifacts from fbuild's .fbuild/build/<env>/release/ path into the legacy .pio/build/<env>/ path. This was supposed to unblock AVR8JS + QEMU workflows that look for firmware.{elf,hex} at the PlatformIO location.

It didn't fully work. AVR8JS + QEMU still appear broken. Reproduced locally and found the bug.

Root cause

_mirror_fbuild_artifacts_to_pio was called before generate_build_info_json_from_existing_build. On a fresh build (CI is always fresh), the mirror target directory does not exist yet. generate_build_info_json_from_existing_build calls pio project metadata --json-output, which PREPARES that directory by wiping and re-creating it — clobbering the firmware files we just mirrored. Only idedata.json remains.

Reproduction (local)

With pre-fix code, on a freshly-cleared .pio/ subdirectory:

  • bash compile uno --examples Blink prints Mirrored fbuild artifacts to ... firmware.elf, firmware.hex, then Generating build metadata, then Generated build_info_Blink.json.
  • After completion, .build/pio/uno/.pio/build/uno/ contains only idedata.json. The mirrored firmware.elf and firmware.hex are gone.

With the fix applied, same starting state:

  • bash compile uno --examples Blink prints Generating build metadata, then Generated build_info_Blink.json, then Mirrored fbuild artifacts to ... firmware.elf, firmware.hex.
  • After completion, .build/pio/uno/.pio/build/uno/ contains firmware.elf, firmware.hex, and idedata.json.

Fix

Swap the order inside _build_with_fbuild:

  1. generate_build_info_json_from_existing_build first (this is what wipes the directory)
  2. _mirror_fbuild_artifacts_to_pio second (nothing else touches the directory after this)

+9 / -6 in ci/compiler/pio.py. No API changes.

Test plan

  • Fresh-dir reproduction confirmed pre-fix (idedata.json only → mirror files wiped)
  • Post-fix verification on fresh dir (all three files present)
  • CI: AVR8JS Uno + QEMU C3/S3/DEV now pass

Note: GitHub Actions runners have been sitting on 46+ min queues for these specific workflows since #2285 merged, so CI hasn't surfaced that the previous fix was incomplete. This PR should make those runs green once they dequeue.

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Chores
    • Optimized the build process execution order for improved efficiency during compilation.

PR #2285 introduced `_mirror_fbuild_artifacts_to_pio` to copy firmware
artifacts from `.fbuild/build/<env>/release/` into `.pio/build/<env>/`
so QEMU and AVR8JS workflow scripts can keep finding them at the
legacy path. The mirror was called immediately after a successful
fbuild compile and BEFORE `generate_build_info_json_from_existing_build`.

Problem: on a fresh build (CI is always fresh), the `.pio/build/<env>/`
directory does not exist yet. `generate_build_info_json_from_existing_build`
invokes `pio project metadata --json-output`, which prepares that
directory by wiping and re-creating it — clobbering the firmware.elf /
firmware.hex we just copied in. After the compile returns, only
`idedata.json` remains; the workflow then fails with
"firmware.elf not found in .pio/build/<env>".

Reproduced locally on a freshly-deleted `.pio/` dir — mirror prints
success but files are gone immediately after.

Fix: swap the order. Generate build metadata first (which wipes the
dir), then mirror firmware artifacts so nothing else touches them.

Verified locally: after `bash compile uno --examples Blink` on a
fresh `.pio/`, the mirrored dir now contains firmware.elf, firmware.hex,
and idedata.json as expected.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Apr 18, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The _build_with_fbuild method in ci/compiler/pio.py was updated to call generate_build_info_json_from_existing_build before _mirror_fbuild_artifacts_to_pio, reversing their previous execution order. Control flow, exception handling, and failure paths remain unchanged.

Changes

Cohort / File(s) Summary
Build Pipeline Reordering
ci/compiler/pio.py
Moved generate_build_info_json_from_existing_build invocation to execute before _mirror_fbuild_artifacts_to_pio in the _build_with_fbuild method, maintaining identical exception handling and control flow.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 First the metadata, then the mirror's gleam,
Reordering steps within the build machine,
No logic lost, just timing set just right,
The artifacts dance in proper sequence's light! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main change: swapping the order of mirror and metadata generation steps to fix a build artifact deletion bug.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-fbuild-mirror-order

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
ci/compiler/pio.py (1)

670-686: LGTM — ordering fix is correct; minor observation on ignored return.

Running generate_build_info_json_from_existing_build first is the right fix: pio project metadata --json-output recreates .pio/build/<env>/ and would otherwise wipe the mirrored firmware.elf/firmware.hex. The inline comment clearly documents the invariant.

One small note (non-blocking, pre-existing pattern): the bool return of generate_build_info_json_from_existing_build is still ignored. If metadata generation fails here, _mirror_fbuild_artifacts_to_pio will still create .pio/build/<env>/ and copy firmware artifacts, but idedata.json / build_info.json won't be present — downstream tools (crash decoder, build_with_merged_bin diagnostics) that rely on build_info.json will then silently operate on a partial artifact set. Consider at least logging a warning when it returns False so CI failures are easier to diagnose.

Optional refactor
-            generate_build_info_json_from_existing_build(
-                self.build_dir, self.board, example
-            )
+            if not generate_build_info_json_from_existing_build(
+                self.build_dir, self.board, example
+            ):
+                print(
+                    f"Warning: build_info.json generation failed for {example} "
+                    f"on {environment}; downstream tooling may be degraded."
+                )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ci/compiler/pio.py` around lines 670 - 686, The call to
generate_build_info_json_from_existing_build currently ignores its boolean
return value; detect when it returns False and emit a warning (using the
existing logging/print approach) before proceeding to
_mirror_fbuild_artifacts_to_pio so failures to produce
idedata.json/build_info.json are visible in CI logs; ensure the warning message
includes context (environment, example/board) so downstream tooling issues can
be diagnosed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@ci/compiler/pio.py`:
- Around line 670-686: The call to generate_build_info_json_from_existing_build
currently ignores its boolean return value; detect when it returns False and
emit a warning (using the existing logging/print approach) before proceeding to
_mirror_fbuild_artifacts_to_pio so failures to produce
idedata.json/build_info.json are visible in CI logs; ensure the warning message
includes context (environment, example/board) so downstream tooling issues can
be diagnosed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1f7bf293-901e-4c39-8204-ecebbe872a9b

📥 Commits

Reviewing files that changed from the base of the PR and between 73cd62b and 4589763.

📒 Files selected for processing (1)
  • ci/compiler/pio.py

@zackees
zackees merged commit de11566 into master Apr 18, 2026
68 of 80 checks passed
zackees added a commit that referenced this pull request Apr 18, 2026
Replaces the Docker-based emulation CI pipeline (avr8js_docker_template.yml,
qemu_docker_template.yml) with direct `fbuild test-emu` invocations. fbuild
2.1.16+ ships a native `test-emu` subcommand that:

- Compiles the sketch and runs it under avr8js / qemu / simavr.
- Handles --timeout, --halt-on-success, --halt-on-error, --expect natively,
  replacing ~400 lines of bash+Python-inline orchestration per template.
- Auto-downloads the Espressif QEMU binary on first use, eliminating the
  espressif/idf Docker image pull.
- Auto-installs the avr8js npm package into ~/.fbuild/cache/, so the
  niteris/fastled-avr8js Docker image is no longer needed.
- Reads firmware from its own .fbuild/build/<env>/release/ layout directly,
  obviating the .pio/build/ path-mirror workarounds added in #2285 and
  patched in #2291.

Both templates drop from ~400 lines to ~150, preserving:
- The trusted/pr-code security checkout split.
- Python 3.11 + uv pinning, `uv sync` for deps.
- Halt / success / error regexes (AVR8JS: "Test setup starting" + "Test loop";
  QEMU: "Test finished.*completed.*iterations|Starting loop iteration 2" +
  "Guru Meditation|abort()").
- Artifact uploads for both success and failure paths.

Dependencies:
- FastLED/fbuild#85 (ESP32-C3 RISC-V QEMU support) — required for the
  qemu_esp32c3_test.yml path. Once merged, the C3 job starts passing.
- FastLED/fbuild#86 (avr8js auto-install robustness) — required for the
  avr8js path. Belt-and-suspenders `npm install [email protected]` added to
  the workflow as a hedge until #86 lands.

Follow-ups (not in this PR):
- Remove `_mirror_fbuild_artifacts_to_pio` (ci/compiler/pio.py:56-99) and
  its call site, plus the `use_fbuild = False` override in
  build_with_merged_bin (lines 1189-1196), once CI is confirmed green.
- Close #2291 as obsolete (mirror-ordering fix is no longer on the emulation
  code path).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees deleted the fix-fbuild-mirror-order branch August 30, 2026 22:22
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.

1 participant