Skip to content

Commit 3c4888a

Browse files
committed
Tup refactor - status update
.agents/codebase-insights.txt: 0006-tup-build-staging-area.md: tup-build-staging-implementation-plan.md: tup-build-staging-status.md: Signed-off-by: Tzanko Matev <[email protected]>
1 parent b0a0dac commit 3c4888a

File tree

4 files changed

+41
-34
lines changed

4 files changed

+41
-34
lines changed

.agents/codebase-insights.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
- `nix/packages/default.nix` now hides helper bindings like `mkNimBinary` via `builtins.removeAttrs` so `perSystem.packages` exposes only real derivations; flake checks will reject non-package values there.
3434
- The generated `appimagePayload` launcher (`bin/ct`) now executes `ct_unwrapped` from the same directory instead of `bin/ct_unwrapped`, fixing AppImage runs where `HERE` already points at `bin/`.
3535
- `ci/build/dev.sh` temporarily moves `src/links` out of the tree before `tup generate` because the generated script writes artifacts directly into `src/`, forcing a full `git clean -xfd src/` afterward.
36+
- The staged Tup layout now lives under `src/build/`; live `tup` runs and `just build` execute from there, and variant artifacts are produced in `src/build-debug/build/`.
37+
- Running a script produced by `tup generate` populates `src/build/`; clean the staging trees with `cd src/build && git clean -fx .` and `cd ../build-debug && git clean -fx .` before resuming live `tup`.
3638
- `!tup_preserve` only mirrors files relative to the directory containing the Tupfile; after moving Tupfiles into `src/build` we copy assets with the new `!cp_preserve` helper so files can originate from the original `src/` tree without confusing tup.
3739
- `!cp_preserve` replaces symlink sources with fresh links pointing at the original target (using `readlink -f`) so mirrored assets stay valid when their relative paths shift.
3840
- `ct_wrapper` resolves `ct_paths.json` by honouring `CODETRACER_CT_PATHS` and otherwise searching upward from both the binary location and the current working directory, so it no longer assumes the wrapper lives at a specific depth in the checkout.

0006-tup-build-staging-area.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ We tried `tup generate --builddir …` to sandbox the outputs, but the option is
1616

1717
We will move the entire Tup configuration into a dedicated staging area at `src/build/`, so that both `tup` FUSE runs and generated scripts create or modify files only inside that subtree while still producing the expected variant outputs (`build-debug/`, etc.).
1818

19-
1. **Establish `src/build/` as the staging tree:** Relocate the root `Tupfile` (providing a thin wrapper in `src/Tupfile` if needed) and every subordinate `Tupfile` under a mirrored directory structure rooted at `src/build/`, while keeping `Tupfile.ini` anchored in `src/` so the Tup root remains the project root. Each rule will reference sources in `../` (or higher) as needed, but outputs and intermediate files stay under `src/build/` by default.
20-
2. **Centralize path conventions:** Introduce helper variables in `Tuprules.tup` (e.g., `SRC_ROOT`, `BUILD_ROOT`, `VARIANT_ROOT`) so recipes can target `src/build/` during generated executions while still honoring variant directories such as `src/build-debug/` when `CONFIG_DEBUG=1` or when explicit output directories are required.
19+
1. **Establish `src/build/` as the staging tree:** Relocate the root `Tupfile` and every subordinate `Tupfile` under a mirrored directory structure rooted at `src/build/`, while keeping `Tupfile.ini` anchored in `src/` so the Tup root remains the project root. The staged layout becomes the canonical entry point—invocations now run from `src/build/` without requiring a compatibility shim in `src/Tupfile`. Each rule references sources in `../` (or higher) as needed, but outputs and intermediate files stay under `src/build/` by default.
20+
2. **Stable path conventions via `SRC_DIR`:** Each staged `Tupfile` declares its own source root with a local `SRC_DIR` variable. This per-file approach is sufficient for the refactor and avoids introducing additional global macros.
2121
3. **Git hygiene:** Add a scoped `.gitignore` inside `src/build/` that admits `tup.sh`, generated metadata (`*.tup` state, temporary outputs), and any new staging directories while keeping declarative build files tracked.
22-
4. **Tooling alignment:** Update `ci/build/dev.sh`, `justfile`, and shell/Nix helpers to invoke `tup` from `src/build/`. The CI clean step will narrow to `git clean -xfd src/build/` instead of the whole source tree, and hacks that relocate `src/links` become unnecessary.
23-
5. **Documentation & onboarding:** Refresh contributor docs to explain the new layout, clarifying that FUSE-based workflows (`tup monitor`) and generated scripts both operate inside `src/build/`, while `tup build-debug` continues to populate `src/build-debug/`.
22+
4. **Tooling alignment:** Update `ci/build/dev.sh`, `justfile`, and shell/Nix helpers to invoke `tup` from `src/build/`. The CI clean step focuses on `src/build/` and `src/build-debug/build/`, and hacks that relocate `src/links` become unnecessary.
23+
5. **Documentation & onboarding:** Refresh contributor docs to explain the new layout, clarifying that FUSE-based workflows (`tup monitor`) operate inside `src/build/`, while `tup build-debug` and generated scripts populate `src/build-debug/build/`. Highlight that `tup generate` writes into the staging tree and document the clean-up sequence required before running the live `tup` monitor again (`cd src/build && git clean -fx .`, followed by `cd ../build-debug && git clean -fx .`).
2424

2525
## Alternatives Considered
2626

@@ -30,10 +30,10 @@ We will move the entire Tup configuration into a dedicated staging area at `src/
3030

3131
## Consequences
3232

33-
- **Positive:** Generated scripts run cleanly without mangling tracked files; CI simplifications; consistent developer experience across environments lacking FUSE; easier to inspect or purge build artifacts via `git clean src/build`.
33+
- **Positive:** Generated scripts run cleanly without polluting tracked files; CI simplifications; consistent developer experience across environments lacking FUSE; easier to inspect or purge build artifacts via `git clean src/build` and `git clean src/build-debug/build`.
3434
- **Neutral/Enabling:** Establishes clearer separation between declarative build metadata and source assets, paving the way for additional variants or build caching under `src/build/`.
35-
- **Negative:** Requires refactoring every `Tupfile` path to account for the new root; risk of path mistakes during migration; temporary churn for developers with pending Tup changes.
36-
- **Risks & Mitigations:** Misconfigured outputs could still escape the sandbox—mitigate by adding integration tests that run `tup generate` + `tup.sh` and assert the set of touched paths. Variant parity must be verified by running `tup build-debug` before and after the move within CI.
35+
- **Negative:** Requires refactoring every `Tupfile` path to account for the new root; risk of path mistakes during migration; temporary churn for developers with pending Tup changes. Running a generated script will populate `src/build/`; developers must clean both `src/build/` and `src/build-debug/` before resuming normal `tup` usage.
36+
- **Risks & Mitigations:** Misconfigured outputs could still escape the sandbox—mitigate by adding integration tests that run `tup generate` + `tup.sh` and assert the set of touched paths. Variant parity must be verified by running `tup build-debug` before and after the move within CI. Document the clean-up sequence after generated runs to avoid confusing residual artifacts.
3737

3838
## Key Locations
3939

@@ -44,14 +44,14 @@ We will move the entire Tup configuration into a dedicated staging area at `src/
4444

4545
## Implementation Notes
4646

47-
1. Mirror the existing Tup hierarchy under `src/build/`, keeping directory-by-directory `Tupfile`s collocated with their rules while adjusting relative paths for inputs and outputs; retain `src/Tupfile.ini` at the root and add a lightweight `src/Tupfile` shim that delegates into `src/build/Tupfile`.
48-
2. Define shared path macros (e.g., `SRC_ROOT = $(TUP_CWD)/../../..`) so recipes can reference the actual sources without brittle `../../..` sequences, and expose a `BUILD_ROOT` for staging outputs.
47+
1. Mirror the existing Tup hierarchy under `src/build/`, keeping directory-by-directory `Tupfile`s collocated with their rules while adjusting relative paths for inputs and outputs; retain `src/Tupfile.ini` at the root and run `tup` directly from `src/build/`.
48+
2. Keep per-directory `SRC_DIR` variables to reference the original sources without introducing additional macros.
4949
3. Create a `.gitignore` within `src/build/` that ignores generated scripts, logs, and `tup` state directories but keeps the committed `Tupfile`s tracked.
50-
4. Update tooling (`ci`, `just`, Nix shells) to execute `tup` from `src/build/`, ensuring variant commands still find `build-debug/tup.config`.
51-
5. Add CI coverage that runs both `tup generate` + generated script and `tup build-debug` to confirm artifacts remain confined to `src/build/` and `src/build-debug/`.
50+
4. Update tooling (`ci`, `just`, Nix shells) to execute `tup` from `src/build/`, ensuring variant commands still find `build-debug/tup.config` and write outputs to `src/build-debug/build/`.
51+
5. Add CI coverage that runs both `tup generate` + generated script and `tup build-debug` to confirm artifacts remain confined to `src/build/` and `src/build-debug/build/`, and document the clean-up requirement after generated runs.
5252

5353
## Status & Next Steps
5454

5555
- Draft ADR for review (this document).
56-
- Prototype the directory move on a feature branch to validate path macros and variant compatibility.
57-
- Once validated, mark this ADR **Accepted** and execute the implementation plan alongside automated regression coverage.
56+
- Prototype the directory move on a feature branch to validate the staged layout, confirm both `tup` and `tup generate` succeed, and measure the clean-up workflow required after generated runs.
57+
- Once validated, mark this ADR **Accepted**, land the staging refactor, update the documentation (including the post-`tup.sh` cleaning steps), and complete the implementation plan alongside automated regression coverage.

tup-build-staging-implementation-plan.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,41 @@ This plan tracks the work required to implement ADR 0006 (“Stage Tup Builds Un
88

99
1. **Create the staging layout**
1010
- Add `src/build/` with placeholders for every directory that currently hosts a `Tupfile`.
11-
- Move the root `Tupfile` and each subordinate `Tupfile` into the mirrored locations (e.g., `src/build/frontend/Tupfile`), leaving `src/Tupfile.ini` anchored at the project root and keeping `Tuprules.tup` wherever is most practical.
12-
- Ensure the Git history retains only the relocated files (remove the old copies rather than duplicating them), and provide a `src/Tupfile` shim that delegates into `src/build/Tupfile` so existing entry points keep working.
11+
- Move the root `Tupfile` and each subordinate `Tupfile` into the mirrored locations (e.g., `src/build/frontend/Tupfile`), leaving `Tupfile.ini` anchored at the project root and keeping `Tuprules.tup` wherever is most practical.
12+
- Ensure the Git history retains only the relocated files (remove the old copies rather than duplicating them). `tup` now runs directly from `src/build/`, so no compatibility shim in `src/Tupfile` is required.
1313

1414
2. **Shared path configuration**
15-
- Introduce `SRC_ROOT`, `BUILD_ROOT`, and `VARIANT_ROOT` variables in `src/build/Tuprules.tup`.
16-
- Replace hard-coded relative paths (e.g., `../bin/...`) with macros so rules are robust after the move.
17-
- Verify all macros expand correctly under both the default staging run and when `CONFIG_*` values switch for variants (`build-debug`).
15+
- Retain per-file `SRC_DIR` variables for referencing source directories; no additional global macros (`SRC_ROOT`, `BUILD_ROOT`, `VARIANT_ROOT`) are necessary.
16+
- Review staged Tupfiles to confirm outputs route into the staging tree using the existing `SRC_DIR` pattern.
1817

1918
3. **Output confinement**
20-
- Adjust commands so intermediate and final outputs default to `$(BUILD_ROOT)` (or a subdirectory) instead of landing inside the source tree.
21-
- Confirm resource-copy rules (`!tup_preserve`, `!cp`, etc.) still put assets in the expected staging paths and that downstream consumers read from the new locations.
19+
- Ensure commands emit intermediate and final outputs into `src/build/` (for live runs) or `src/build-debug/build/` (for variant builds) instead of the source tree.
20+
- Confirm resource-copy rules (`!cp_preserve`, etc.) still put assets in the expected staging paths and that downstream consumers read from the new locations.
2221

2322
## Part 2 – Preserve Variant Behaviour
2423

2524
1. **Variant path wiring**
2625
- Audit references to `build-debug` (and other variant directories) to ensure they resolve relative to the new staging root.
27-
- Update scripts or rules that assume the old `src/` root when reading `tup.config` or variant outputs.
26+
- Update scripts or rules that assume the old `src/build-debug/bin` layout so they target `src/build-debug/build/**` instead.
2827

2928
2. **Regression tests**
3029
- Run `tup build-debug` in the new layout and compare the directory structure of `src/build-debug/` against a baseline (focus on executables in `bin/`, JS bundles, and resource copies).
31-
- Capture discrepancies and update rules or macros until parity is achieved.
30+
- Capture discrepancies and update rules until parity is achieved; ensure the `build-debug/build` subtree contains the expected artifacts.
3231

3332
3. **Generated script validation**
34-
- Run `tup generate tup.sh` inside `src/build/`, execute the script, and assert that all files it produces stay within `src/build/` (aside from the intentional `build-debug` tree).
33+
- Run `tup generate tup.sh` inside `src/build/`, execute the script, and confirm the outputs stay within the staging area (`src/build/`) and `src/build-debug/build/`.
34+
- Document the required clean-up before returning to the live monitor: `cd src/build && git clean -fx .` followed by `cd ../build-debug && git clean -fx .`.
3535
- Add automated checks (e.g., a CI script diffing `git status`) to prevent regressions.
3636

3737
## Part 3 – Tooling & Automation Updates
3838

3939
1. **CI adjustments**
40-
- Simplify `ci/build/dev.sh` to operate entirely within `src/build/`, removing the temporary `src/links` relocation and limiting cleanups to `src/build/` and `src/build-debug/`.
41-
- Update any other CI jobs that run `tup` or expect artifacts in `src/`.
40+
- Simplify `ci/build/dev.sh` to operate entirely within `src/build/`, removing the temporary `src/links` relocation and limiting cleanups to `src/build/` and `src/build-debug/build/`.
41+
- Update any other CI jobs that run `tup` or expect artifacts in `src/`, including the post-`tup.sh` cleaning sequence.
4242

4343
2. **Developer workflows**
44-
- Modify `justfile` recipes, Nix shell hooks (`nix/shells/main.nix`, `armShell.nix`), and helper scripts so they `cd src/build` before invoking `tup`.
45-
- Double-check that commands such as `tup monitor -a` behave identically in the new location.
44+
- Modify `justfile` recipes, Nix shell hooks (`nix/shells/main.nix`, `armShell.nix`), and helper scripts so they `cd src/build` before invoking `tup` and expect outputs in `src/build-debug/build/`.
45+
- Double-check that commands such as `tup monitor -a` behave identically in the new location after cleaning.
4646

4747
3. **Git hygiene**
4848
- Add `src/build/.gitignore` to ignore generated scripts, `.tup` state directories, and transient outputs while keeping committed `Tupfile`s tracked.
@@ -52,14 +52,15 @@ This plan tracks the work required to implement ADR 0006 (“Stage Tup Builds Un
5252

5353
1. **Contributor docs**
5454
- Update build instructions (`README.md`, `docs/book`, onboarding guides) to reference `src/build/` as the entry point for `tup` workflows.
55-
- Highlight the difference between the staging area (`src/build/`) and variant outputs (`src/build-debug/`) to avoid confusion.
55+
- Highlight the difference between the staging area (`src/build/`) and variant outputs (`src/build-debug/build/`) to avoid confusion.
56+
- Document the clean-up sequence required after running a generated script so developers can return to live `tup` runs without residual artifacts.
5657

5758
2. **Knowledge base**
5859
- Refresh `.agents/codebase-insights.txt` (and any other internal notes) to capture the new layout.
5960

6061
3. **Post-migration cleanup**
61-
- Remove temporary workarounds that are no longer necessary (e.g., scripts assuming outputs land in `src/`).
62-
- Monitor developer feedback during the first few sprints and adjust macros or documentation as needed.
62+
- Remove temporary workarounds that are no longer necessary (e.g., scripts assuming outputs land in `src/` or `src/build-debug/bin`).
63+
- Monitor developer feedback during the first few sprints and adjust documentation or supporting scripts as needed.
6364

6465
---
6566

tup-build-staging-status.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# Tup Build Staging Refactor – Status
22

33
## Completed
4-
- Step 1: Created the `src/build/` staging layout, moved the root Tupfile/Tuprules plus crate-specific Tupfiles, added the `src/Tupfile` shim, and kept `Tupfile.ini` rooted in `src/`.
4+
- Relocated the entire Tup graph to `src/build/`, with `Tupfile.ini` still rooted in `src/`; `tup` now runs directly from the staging tree and no `src/Tupfile` shim is needed.
5+
- Standardized on per-file `SRC_DIR` handling for relocated Tupfiles, added `!cp_preserve` plus `src/build/.gitignore`, and refreshed `.agents/codebase-insights.txt`; no further Tupfile edits are planned.
6+
- Validated the build: both `tup` and `tup generate` succeed, `just build` / `just build-once` work end-to-end, and their outputs land under `src/build/` or `src/build-debug/build/` as intended.
57

68
## In Progress
7-
- Step 2: Updating relocated Tupfiles to pull inputs from the original source tree and emit outputs inside `src/build/`. Added `include_rules` to every staged Tupfile, introduced a `!cp_preserve` helper, and rewrote asset copies to use explicit relative paths instead of `!tup_preserve`. Need to validate with `tup` runs (current environment blocks user namespaces) and adjust paths based on the results.
9+
- Update tooling, scripts, and documentation (CI jobs, `justfile`, Nix shells, onboarding guides) to reference `src/build-debug/build/**` and reflect the new staging entry point.
10+
- Capture the operational caveat that a generated script populates `src/build/`; developers must run `cd src/build && git clean -fx .` followed by `cd ../build-debug && git clean -fx .` before returning to live `tup` runs.
811

912
## Next
10-
- Step 2: Validate the updated rules by running `tup` (default + `build-debug`) once user-namespace restrictions are lifted, and fix any remaining path issues that show up.
11-
- Step 3: Refresh tooling, documentation, and CI scripts to rely on the staging tree and ensure `tup generate` produces artifacts only under `src/build/` and the existing variant directories.
13+
- Sweep remaining references to `src/build-debug/bin` (arm shell, docs, helper scripts) and switch them to `src/build-debug/build/**`.
14+
- Document the post-`tup.sh` clean-up sequence across contributor docs and CI scripts, adding automation where possible to enforce a clean staging area.
15+
- Verify CI and developer tooling run successfully with the updated paths and documented clean-up, then mark ADR 0006 as accepted.

0 commit comments

Comments
 (0)