Skip to content

Commit 2a497e9

Browse files
andrewgazelkacodex
andauthored
lib: restore public helper exports (#136)
## Summary - restore public `lib` exports for helper constructors still consumed by ix - keep the current index main changes intact while making `cargoUnitFor` and `mkFleetFor` available again ## Validation - `direnv exec . nix eval .#lib --apply 'lib: builtins.toJSON { cargoUnitFor = builtins.hasAttr "cargoUnitFor" lib; mkFleetFor = builtins.hasAttr "mkFleetFor" lib; }'` - `direnv exec . nix run .#lint` Co-authored-by: Codex <codex@openai.com>
1 parent 811a975 commit 2a497e9

5 files changed

Lines changed: 29 additions & 2 deletions

File tree

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ threshold with Tango's `--fail-threshold` flag.
6464
contains tests. Build the workspace with `extraRustcArgs` passing
6565
`-Cinstrument-coverage`; the report derivation runs each test binary, merges the
6666
LLVM profiles, and writes normalized LCOV to `$out/lcov.info`.
67+
Coverage tests run from writable package-source copies by default, matching
68+
Cargo's expectation that tests can create package-local runtime files.
6769
The selected Rust toolchain must include matching LLVM tools, or
6870
`makeCoverageReport` must receive explicit `llvmCov` and `llvmProfdata` paths.
6971

lib/default.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,7 @@ let
998998
evalImageConfig
999999
mkImage
10001000
mkFleet
1001+
mkFleetFor
10011002
discoverImages
10021003
exampleFleetsFor
10031004
artifacts
@@ -1006,7 +1007,10 @@ let
10061007
buildGradleFatJar
10071008
buildNpmSite
10081009
buildUvApplication
1010+
bunLockFor
10091011
cargoUnit
1012+
cargoUnitFor
1013+
errors
10101014
languages
10111015
minecraft
10121016
mkMinecraftLoader
@@ -1017,6 +1021,7 @@ let
10171021
rustWorkspace
10181022
secrets
10191023
systemdHardening
1024+
uvLockFor
10201025
writeNushellApplication
10211026
writePythonApplication
10221027
;

packages/nix-cargo-unit/src/render.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,6 +2485,8 @@ mod tests {
24852485
assert!(rendered.contains("testPlan = mkTestPlan \"cargo-unit-test-plan\";"));
24862486
assert!(rendered.contains("coverageReport = mkCoverageReport {};"));
24872487
assert!(rendered.contains("makeCoverageReport = mkCoverageReport;"));
2488+
assert!(rendered.contains("writableTestCwd ? true"));
2489+
assert!(rendered.contains(".cargo-unit-writable-cwd-ready"));
24882490
assert!(rendered.contains("llvm-profdata"));
24892491
assert!(rendered.contains("llvm-cov"));
24902492
assert!(!rendered.contains("fallbackLlvmCov"));

packages/nix-cargo-unit/templates/units.nix.askama

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ let
288288
name ? "cargo-unit-coverage",
289289
testArgs ? [],
290290
testArgsByPackage ? {},
291+
writableTestCwd ? true,
291292
llvmCov ? null,
292293
llvmProfdata ? null,
293294
}:
@@ -308,11 +309,12 @@ let
308309
coverage_root="$TMPDIR/cargo-unit-coverage"
309310
profile_dir="$coverage_root/profiles"
310311
source_roots="$coverage_root/source-roots.tsv"
312+
writable_cwd_root="$coverage_root/writable-cwds"
311313
executed_test_binaries="$coverage_root/executed-test-binaries"
312314
merged_profile="$out/merged.profdata"
313315
raw_lcov="$out/raw.lcov"
314316

315-
mkdir -p "$out" "$profile_dir"
317+
mkdir -p "$out" "$profile_dir" "$writable_cwd_root"
316318
: > "$source_roots"
317319
: > "$executed_test_binaries"
318320
export LLVM_PROFILE_FILE="$profile_dir/%p-%m.profraw"
@@ -361,11 +363,22 @@ let
361363
in
362364
''
363365
test_binary=${pkgs.lib.escapeShellArg target.binary}
364-
test_cwd=${pkgs.lib.escapeShellArg packageCwd}
366+
test_source_cwd=${pkgs.lib.escapeShellArg packageCwd}
367+
test_cwd="$test_source_cwd"
365368
if [ ! -x "$test_binary" ]; then
366369
echo >&2 "error: cargo-unit coverage test binary is missing or not executable: $test_binary"
367370
exit 1
368371
fi
372+
${pkgs.lib.optionalString writableTestCwd ''
373+
test_cwd="$writable_cwd_root"/${pkgs.lib.escapeShellArg target.sourceStoreName}
374+
if [ ! -e "$test_cwd/.cargo-unit-writable-cwd-ready" ]; then
375+
rm -rf "$test_cwd"
376+
mkdir -p "$test_cwd"
377+
cp -R "$test_source_cwd"/. "$test_cwd"/
378+
chmod -R u+w "$test_cwd"
379+
touch "$test_cwd/.cargo-unit-writable-cwd-ready"
380+
fi
381+
''}
369382
echo "running coverage target $test_binary"
370383
printf '%s\n' "$test_binary" >> "$executed_test_binaries"
371384
(

tests/fixtures/cargo-unit-hello/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ mod tests {
1111
fn returns_greeting() {
1212
assert_eq!(greeting(), "hello from cargo-unit");
1313
}
14+
15+
#[test]
16+
fn current_dir_is_writable() {
17+
std::fs::write(".cargo-unit-writable-cwd-check", "ok").unwrap();
18+
}
1419
}

0 commit comments

Comments
 (0)