Debian Codegraph @

test/blackbox-tests/test-cases/pkg/install-symlinks/basic-caching.t

raw
1 Test that packages with symlinks in their install output are properly cached.
2 Dune resolves symlinks to hardlinks so that the cache can store them.
3
4 The compiler is one such package that has this kind of layout.
5
6 $ export DUNE_CACHE=enabled
7 $ export DUNE_CACHE_ROOT=$PWD/_cache
8
9 $ make_lockdir
10
11 Create a package that installs both a regular file and a symlink to it.
12 This is similar to how compilers install binaries (e.g., ocamlc -> ocamlc.opt).
13
14 $ make_lockpkg foo <<EOF
15 > (version 0.0.1)
16 > (build
17 > (system "\
18 > true BUILDING_FOO_PACKAGE \
19 > && mkdir -p %{lib}/%{pkg-self:name} \
20 > && printf 'real content\n' > %{lib}/%{pkg-self:name}/real.txt \
21 > && ln -s real.txt %{lib}/%{pkg-self:name}/link.txt \
22 > && touch %{lib}/%{pkg-self:name}/META"))
23 > EOF
24
25 $ cat > dune-project <<EOF
26 > (lang dune 3.22)
27 > (package
28 > (name x)
29 > (allow_empty)
30 > (depends foo))
31 > EOF
32
33 Build the package:
34
35 $ build_pkg foo
36
37 Verify the build ran by checking the trace for our marker command:
38
39 $ count_trace BUILDING_FOO_PACKAGE
40 1
41
42 Check that the files exist:
43
44 $ ls $(get_build_pkg_dir foo)/target/lib/foo | sort
45 META
46 link.txt
47 real.txt
48
49 The symlink has been resolved to a regular file (hardlink to the target):
50
51 $ dune_cmd stat kind $(get_build_pkg_dir foo)/target/lib/foo/link.txt
52 regular file
53
54 Check hardlink count. Files should have hardlinks > 1 indicating they are cached.
55 real.txt has 3 hardlinks: original, link.txt (resolved), and cache entry.
56
57 $ dune_cmd stat hardlinks $(get_build_pkg_dir foo)/target/lib/foo/real.txt
58 3
59 $ dune_cmd stat hardlinks $(get_build_pkg_dir foo)/target/lib/foo/META
60 2
61
62 Clean and rebuild to verify cache restore:
63
64 $ rm -rf _build
65 $ build_pkg foo
66
67 The build command should not be rerun since it will be restored from cache.
68
69 $ count_trace BUILDING_FOO_PACKAGE
70 0
71