Skip to content

Commit 726e00d

Browse files
committed
refactor: prefer trace over cache
1 parent bd0b244 commit 726e00d

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/lake/Lake/Build/Common.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,17 +560,17 @@ Retrieve artifacts from the Lake cache using only the outputs stored in the save
560560
open ResolveOutputs in
561561
/--
562562
Retrieve artifacts from the Lake cache using the outputs stored in either
563-
the saved trace file or (unless `traceOnly` is `true`) in the cached input-to-content mapping.
563+
the saved trace file or in the cached input-to-content mapping.
564564
565565
**For internal use only.**
566566
-/
567567
@[inline] public nonrec def getArtifacts?
568568
[ResolveOutputs α] (inputHash : Hash) (savedTrace : SavedTrace) (pkg : Package)
569569
: JobM (Option α) := do
570-
if let some a ← getArtifactsUsingCache? inputHash pkg then
571-
return some a
572570
if let some a ← getArtifactsUsingTrace? inputHash savedTrace pkg then
573571
return some a
572+
if let some a ← getArtifactsUsingCache? inputHash pkg then
573+
return some a
574574
return none
575575

576576
/-- **For internal use only.** -/

tests/lake/tests/cache/test.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,11 @@ if command -v jq > /dev/null; then # skip if no jq found
280280
test_cmd rm -f $libPath
281281
inputHash=$(jq -r '.depHash' $libPath.trace)
282282
echo $inputHash
283+
test_cmd rm -f $libPath.trace
283284
echo bogus > "$CACHE_DIR/outputs/test/$inputHash.json"
284285
test_out 'invalid JSON' build Test:static
285-
test_cmd rm -f $libPath
286+
test_exp -f $libPath
287+
test_cmd rm -f $libPath $libPath.trace
286288
echo '"bogus"' > "$CACHE_DIR/outputs/test/$inputHash.json"
287289
test_out 'some output(s) have issues' build Test:static
288290
test_exp -f $libPath

tests/lake/tests/ltar/test.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ source ../common.sh
77
export LAKE_CACHE_DIR=
88

99
#-------------------------------------------------------------------------------
10-
# The tests covers the (offline) use of `leantar` in Lake
10+
# This test suite covers the (offline) use of `leantar` in Lake
1111
#-------------------------------------------------------------------------------
1212

1313
# Test regular build does not produce an `ltar`
@@ -58,13 +58,21 @@ test_exp -f .lake/build/ir/Test.ltar
5858
# `--keep-local`. Since the build mapping includes module outputs and the
5959
# tracked mapping only includes the `ltar`, the tracking mapping should
6060
# require an unpack, whereas the build mapping should not.
61+
rm -rf .lake/build
6162
test_run cache add .lake/outputs.jsonl --keep-local
6263
LAKE_ARTIFACT_CACHE=true test_not_out "leantar" build +Test --no-build -v
64+
rm -rf .lake/build
6365
test_run cache add .lake/outputs.jsonl
6466
LAKE_ARTIFACT_CACHE=true test_out "leantar" build +Test --no-build -v
67+
rm -rf .lake/build
6568
# Unpack should have overwritten the cached input with the module outputs
6669
LAKE_ARTIFACT_CACHE=true test_not_out "leantar" build +Test --no-build -v
6770

71+
# Test that Lake prefers the local trace outputs over the cache
72+
rm -rf .lake/build.lib/*.[!t]*
73+
test_run cache add .lake/outputs.jsonl
74+
LAKE_ARTIFACT_CACHE=true test_not_out "leantar" build +Test --no-build -v
75+
6876
# Test producing an `ltar` without already restored artifacts
6977
rm -rf .lake/cache .lake/build
7078
LAKE_ARTIFACT_CACHE=true test_run build +Test -v

0 commit comments

Comments
 (0)