-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pkg): Enable cache on fetch actions
This enables caching of downloaded files as part of the fetch action, if the file to be retrieved is retrieved via a cryptographic hash (and thus presumably the exact same as the first time it was downloaded). Signed-off-by: Marek Kubica <marek@tarides.com>
- Loading branch information
1 parent
5607dd9
commit dc495fa
Showing
4 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
Testing that files are only fetched once. | ||
|
||
$ . ./helpers.sh | ||
|
||
No need to set DUNE_CACHE (enabled by default) nor DUNE_CACHE_RULES as the | ||
fetch rules are always considered safe to cache, but we'll set a custom | ||
directory for the shared cache. | ||
|
||
$ export DUNE_CACHE_ROOT=$(pwd)/dune-cache | ||
$ unset DUNE_CACHE | ||
$ unset DUNE_CACHE_RULES | ||
|
||
Set up a project that depends on a package that is being downloaded | ||
|
||
$ make_lockdir | ||
$ echo "Contents" > tar-contents | ||
$ CONTENT_CHECKSUM=$(md5sum tar-contents | cut -f1 -d' ') | ||
$ tar cf test.tar tar-contents | ||
$ echo test.tar > fake-curls | ||
$ SRC_PORT=1 | ||
$ SRC_CHECKSUM=$(md5sum test.tar | cut -f1 -d' ') | ||
$ cat >dune.lock/test.pkg <<EOF | ||
> (version 0.0.1) | ||
> (source | ||
> (fetch | ||
> (url http://localhost:$SRC_PORT) | ||
> (checksum md5=$SRC_CHECKSUM))) | ||
> EOF | ||
$ cat > dune-project <<EOF | ||
> (lang dune 3.17) | ||
> (package (name my) (depends test) (allow_empty)) | ||
> EOF | ||
The first build should succeed, fetching the source, populating the cache and | ||
disabling the download of the source a second time. | ||
$ dune build | ||
Make sure that the file that was fetched is in the cache: | ||
$ find $DUNE_CACHE_ROOT/files -type f -exec md5sum {} \; | grep --quiet $CONTENT_CHECKSUM | ||
Cleaning the project to force rebuilding. If we attempt to build without the | ||
cache, it will fail, as the source is 404 now: | ||
$ dune clean | ||
$ export DUNE_CACHE=disabled | ||
$ dune build | ||
File "dune.lock/test.pkg", line 4, characters 9-27: | ||
4 | (url http://localhost:1) | ||
^^^^^^^^^^^^^^^^^^ | ||
Error: download failed with code 404 | ||
[1] | ||
However when enabling the cache again, the file that was fetched in the first | ||
build should be retrieved from the cache and the build succeed: | ||
$ dune clean | ||
$ export DUNE_CACHE=enabled | ||
$ dune build |