Skip to content

Commit 1da1cd0

Browse files
committed
chore: test hard linking
1 parent 043e85a commit 1da1cd0

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/lake/Lake/Build/Common.lean

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -551,11 +551,9 @@ drives and/or file systems), falls back to copying the artifact to the new path.
551551
public def restoreArtifact (file : FilePath) (art : Artifact) (exe := false) : LogIO Artifact := do
552552
unless (← file.pathExists) do
553553
logVerbose s!"found artifact in cache: {art.path}"
554-
try
555-
IO.FS.hardLink art.path file
556-
catch _ =>
557-
logVerbose s!"could not hard link artifact, copying from cache instead..."
558-
createParentDirs file
554+
createParentDirs file
555+
if let .error e ← (IO.FS.hardLink art.path file).toBaseIO then
556+
logVerbose s!"could not hard link artifact, copying from cache instead; error: {e}"
559557
copyFile art.path file
560558
-- make the local file unwritable where possible to discourage users from
561559
-- writing to such paths as this can corrupt the cache if the file was hard linked instead

tests/lake/tests/cache/test.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ test_exp "$(norm_dirname "$cache_art")" = "$CACHE_DIR/artifacts"
5454
test_exp "$cache_art" != "$local_art"
5555
test_cmd cmp -s "$cache_art" "$local_art"
5656

57-
# Verify supported artifacts end up in the cache directory
58-
test_run build \
59-
test:exe Test:static Test:shared +Test:o.export +Test:o.noexport +Module
57+
# Verify supported artifacts use the cache directory
58+
test_run build test:exe Test:static Test:shared \
59+
+Test:dynlib +Test:o.export +Test:o.noexport +Module
6060
test_cached() {
6161
target="$1"; shift
6262
art="$($LAKE query $target)"
@@ -145,7 +145,7 @@ test_out "Fetched Test:c.o" build +Test:o -v --no-build
145145
test_cmd rm -rf "$CACHE_DIR/outputs" .lake/build/ir/Test.c
146146
test_run -v build +Test:c --no-build
147147

148-
# Verify that the olean does need to be present in the build directory
148+
# Verify that the olean does not need to be present in the build directory
149149
test_cmd rm -f .lake/build/lib/lean/Test.olean .lake/build/lib/lean/Test/Imported.olean
150150
test_run -v build +Test.Imported --no-build --wfail
151151
test_run -v build +Test
@@ -168,16 +168,22 @@ test_lines 3 .lake/outputs.jsonl
168168
test_run build Test:static -o .lake/outputs.jsonl
169169
test_lines 6 .lake/outputs.jsonl
170170

171-
# Verify all artifacts end up in the cache directory with `restoreAllArtifacts`
171+
# Verify all artifacts restore from the cache and
172+
# use the build directory with `restoreAllArtifacts`
172173
test_cmd cp -r "$CACHE_DIR" .lake/cache-backup
173174
test_cmd rm -rf "$CACHE_DIR" .lake/build
174-
test_run build -R -KrestoreAll=true \
175-
test:exe Test:static Test:shared +Test:o.export +Test:o.noexport +Module
175+
test_run build -R -KrestoreAll=true test:exe Test:static Test:shared \
176+
+Test:dynlib +Test:o.export +Test:o.noexport +Module
177+
test_cmd rm -rf .lake/build
178+
test_run build -v --no-build test:exe Test:static Test:shared \
179+
+Test:dynlib +Test:o.export +Test:o.noexport +Module
176180
test_restored() {
177181
target="$1"; shift
178182
art="$($LAKE query $target)"
179-
echo "! artifact cached: $target -> $art"
183+
hardlinks="$(stat -c %h "$art")"
184+
echo "! artifact cached (links: $hardlinks): $target -> $art"
180185
test ! "$(norm_dirname "$art")" = "$CACHE_DIR/artifacts"
186+
test $hardlinks -gt 1 # check that the restored artifact is hard linked
181187
if [ -n "${1:-}" ]; then
182188
test "$(basename "$art")" = "$1"
183189
fi

0 commit comments

Comments
 (0)