You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(build): migrate BuildInfo to NormalizedPath (Phase 2 of #437) (#454)
* feat(build): migrate BuildInfo path fields to NormalizedPath (Phase 2 of #437)
Phase 2 of the NormalizedPath migration plan from #437. Phase 1 (#450)
landed the `NormalizedPath` type in `fbuild-core::path`; this PR routes
`BuildInfo`'s ten `*_path` fields plus the `aliases` block through it
and proves the cross-platform JSON contract directly.
Changes
-------
- `NormalizedPath::serialize` now emits the slash-form, case-preserving
rendering (`display_slash`). Cache keys (`key()`) keep their
case-folded form for `Hash`/`Eq` stability on Windows + default macOS,
but serialization stays human-readable while still being byte-
identical across platforms.
- Added `NormalizedPath::default()` (empty path) so `#[serde(default)]`
preserves the existing "missing → empty-string" sentinel that
downstream Python consumers (FastLED's `_create_board_info`,
`_find_build_info`) rely on.
- `BuildInfo`'s ten `*_path` fields (`prog_path`, `cc_path`, `cxx_path`,
`ar_path`, `objcopy_path`, `size_path`, `nm_path`, `cppfilt_path`,
`readelf_path`, `objdump_path`) and `aliases: BTreeMap<String, _>`
values switched from `String` to `NormalizedPath`. JSON schema is
unchanged for downstream consumers — `NormalizedPath` (de)serializes
as a plain JSON string.
- `fbuild-cli`'s `symbols_cmd` consumers updated to read/write
`NormalizedPath` instead of `String`.
Tests
-----
- New `emit_json_uses_forward_slashes_regardless_of_input_separators`
test pins the cross-platform JSON contract directly — constructs
`BuildInfo` via `Path::join` (which leaks `\` on Windows) and
asserts the emitted JSON contains zero backslashes.
- Retired the `pj()` helper from build_info.rs: assertions now compare
against literal slash-form expectations on every platform — the
workaround the issue's acceptance criteria explicitly asked us to
remove.
- New `NormalizedPath` tests: `serialize_emits_slash_form` and
(cfg=windows) `serialize_strips_extended_length_prefix`.
- `json_round_trip_preserves_path_form` updated to assert `original ==
back` (Equal under `NormalizedPath`'s normalized comparison).
Acceptance vs. #437
-------------------
- [x] `NormalizedPath` exists in `fbuild-core` and `Hash`/`Eq` produce
identical bytes for `C:\Users\x\a` and `C:/Users/x/a` (#450).
- [x] `BuildInfo`'s nine path fields are `NormalizedPath`, and
`build_info.json` emits the canonical (slash-form) string on
every platform.
- [ ] `cargo dylint --all` errors on new raw-path slots — deferred to
Phase 3 per the original plan.
- [x] `fbuild symbols` regression test passes without a `pj()` helper.
Closes#437 (Phase 2).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test(core): split NormalizedPath serialize tests by platform
CI on macOS + Ubuntu failed `serialize_emits_slash_form` because the
test used `r"C:\Users\zach\bin\avr-nm"` as input and then asserted
the serialized JSON contains no `\`. On Unix the backslash is a
legal filename character — not a separator — so the implementation
correctly preserves it. The assertion was wrong, not the code.
Split into three:
- `serialize_emits_slash_form`: forward-slash input survives
unchanged everywhere (the core invariant).
- `serialize_converts_backslash_input_to_forward_slashes_on_windows`
(cfg=windows): Windows-only conversion of `\` → `/`.
- `serialize_preserves_backslashes_as_content_on_unix`
(cfg=not(windows)): proves we *don't* mangle real filenames
containing `\` on Linux/macOS.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments