Skip to content

dylint: ban raw .fbuild path literals outside fbuild-paths; ratchet to zero #1349

Closed

Description

@zackees

Problem

fbuild-paths declares itself the single source of truth for all .fbuild paths (crates/fbuild-paths/src/lib.rs:3), but the .fbuild / .fbuild/build path segments are hardcoded as raw string literals in 69 files across the workspace — including production code:

  • fbuild-cli/src/cli/{ide,debug,symbols_cmd,ide_debug,clang_tools,args,dispatch,lib_select}.rs
  • fbuild-build-engine/src/{linker.rs,build_info.rs,symbol_analyzer,framework_libs.rs}
  • fbuild-daemon/src/{handlers/libraries.rs,handlers/emulator,models.rs}
  • fbuild-deploy/src/{lpc.rs,wlink.rs,wchisp.rs,probe_rs.rs,lpc_debugger_reflash.rs}
  • fbuild-core/src/{response_file.rs,path.rs,lib.rs}
  • plus ~25 test files hand-rolling fixture layouts like dir.join(".fbuild/build/uno/release/...")

Raw literals drift from the real layout rules (env-segment auto-collapse, FBUILD_BUILD_DIR override, PIO .build/pio layouts — see agents/docs/path-conventions.md) and silently break compile_cwd_from_output / BuildLayout consumers when the layout evolves.

Proposal

  1. New dylint lint dylints/ban_raw_fbuild_path (pattern after the existing dylints/ban_raw_subprocess crate): flag string literals containing .fbuild outside crates/fbuild-paths/src/** (the sanctioned definition site).
  2. Export canonical primitives from fbuild-paths: FBUILD_DIR_NAME / BUILD_DIR_NAME consts plus the existing project_fbuild_dir() / BuildLayout::resolve() so call sites have a mechanical replacement.
  3. Ratchet: land the lint with a baseline allowlist of the current 69 files; each file must be sanitized (route through BuildLayout / the new consts) and removed from the allowlist; the allowlist may only shrink. CI fails on any new raw-literal site.
  4. Test fixtures should build layouts via fbuild_paths::BuildLayout::new(project, env, profile).resolve() instead of hand-rolled join(".fbuild/build/...") chains.

Acceptance

  • dylints/ban_raw_fbuild_path lint crate exists, wired into the dylint CI gate alongside ban_raw_subprocess
  • Baseline allowlist checked in; count recorded in this issue
  • Allowlist reaches zero (or only fbuild-paths definition sites remain)

Activity

  1. zackees commented on Aug 22, 2026

    @zackees
    MemberAuthor

    Acceptance items 1 and 2 landed in #1353 (merged as 49ec69c).

    Item 1 — lint crate wired into the Dylint gate. dylints/ban_raw_fbuild_path flags any string literal whose contents include .fbuild. It catches both real-world shapes — Path::join(".fbuild") segments and format!(".fbuild/build/{}/release/...") templates — because rustc lowers format_args! pieces to HIR Lit nodes, so the late pass sees them. Discovered via [workspace.metadata.dylint] libraries = [{ path = "dylints/*" }]; registered in the root exclude list, ci/hooks/crate_guard.py, and dylints/README.md.

    Item 2 — baseline recorded: 47 files. Plus one permanent exemption, crates/fbuild-paths/src/lib.rs, the definition site itself.

    The baseline came from a comment-stripping, raw-string- and escape-aware Rust string-literal scanner rather than a line grep, then was trued up against cargo-dylint dylint --lib ban_raw_fbuild_path -- --workspace --all-targets, which now exits 0 with zero violations. Two notes for whoever picks up the ratchet:

    • crates/fbuild-cli/src/cli/args.rs is on the list because clap's #[derive(Subcommand)] stringifies /// doc text into help strings; the literal's call site is the #[derive] item, so the whole file is exempt rather than one doc line.
    • assert!(cond) synthesizes "assertion failed: <stringified cond>" with no source span at all. Those are dropped by a dummy-span guard — a diagnostic nobody can locate is one nobody can fix.

    Item 3 — ratchet to zero — remains open, which is why this issue stays open. The list is shrink-only and that is now enforced, not just documented: ci/check_fbuild_path_baseline.py diffs src/allowlist.txt against origin/main in the Dylint job and fails on any added entry. Removals always pass.

    Also exported for the sanitization work: fbuild_paths::FBUILD_DIR_NAME and fbuild_paths::BUILD_DIR_NAME, alongside the existing get_project_fbuild_dir, get_project_build_root, and BuildLayout::resolve. Per-file recipe is in dylints/ban_raw_fbuild_path/README.md → Rollout: sanitize, delete the line, bump the crate version to bust the Dylint .so cache.

  2. zackees commented on Aug 23, 2026

    @zackees
    MemberAuthor

    Baseline was 48 entries at landing. #1383 takes it to 43 by sanitizing all five fbuild-deploy sites (lpc.rs, lpc_debugger_reflash.rs, probe_rs.rs, wchisp.rs, wlink.rs).

    The batch found a live instance of exactly what this issue predicted: all five had re-derived ~/.fbuild/{dev|prod}/tools with var_os("FBUILD_DEV_MODE").is_some(), while fbuild_paths::is_dev_mode() requires the literal 1. FBUILD_DEV_MODE=0 therefore sent managed tools to the dev tree while every other path stayed in prod.

    Remaining 43, by crate: fbuild-build 12, fbuild-build-engine 10, fbuild-cli 9, fbuild-daemon 6, fbuild-core 2, fbuild-paths 1 (the sanctioned definition site), fbuild-library-select 1, fbuild-library 1, fbuild-build-arm 1.

    One structural note for the tail of the ratchet: fbuild-core cannot use fbuild_paths::FBUILD_DIR_NAME — fbuild-paths depends on fbuild-core, not the reverse. Those two entries need either a const that lives in fbuild-core and is re-exported by fbuild-paths, or to stay as permanently-sanctioned sites. Worth deciding before the last batch rather than during it.

  3. 2 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions