forked from leanprover-community/mathlib3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch_olean_cache.sh
executable file
·46 lines (39 loc) · 1.48 KB
/
fetch_olean_cache.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
set -e
set -x
archive_url="https://oleanstorage.azureedge.net/mathlib/"
# GIT_HISTORY_DEPTH is set in .github/workflows/build.yml
for new_git_sha in $(git log -$GIT_HISTORY_DEPTH --first-parent --pretty=format:%H)
do
if curl -sfI "$archive_url$new_git_sha.tar.gz" ; then
echo "found ancestor Git sha: $new_git_sha"
break
fi
new_git_sha=""
done
# exit if there were no successful requests
[ "$new_git_sha" != "" ] || exit 0
curl "$archive_url$new_git_sha.tar.gz" | tar xz src
# Extracting the archive overwrites all .lean files, which is fine if we
# downloaded an "equivalent" cache. However, since we might be using an older
# cache, we must revert any changes made to the .lean files.
#
# The following commands don't make any changes to ignored files, so the .olean
# files should be OK.
git reset --hard HEAD
git clean -f -d
# A list of directories containing .olean files. We are being conservative to
# avoid traversing irrelevant directories and affecting directories we do not
# want changed (e.g. $root/.git).
dirs="src"
# Delete every <path>.olean without a matching <path>.lean.
# n.b. this for loop will break if there are filenames with spaces
for olean_file in `find $dirs -name "*.olean"`
do
lean_file=${olean_file/%.olean/.lean}
if [ ! -e $lean_file ]; then
rm $olean_file
fi
done
# Delete all empty directories. An empty directory may have been created if it
# does not contain any .lean files and all of its .olean files were deleted.
find $dirs -type d -empty -delete