-
Notifications
You must be signed in to change notification settings - Fork 7
/
fetch-jars
executable file
·126 lines (107 loc) · 3.56 KB
/
fetch-jars
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash
set -eu
# Usage: ./fetch-jars [rev-name] [--unstable] [--local] [--copper]
# If a revision is not specified, the script fetches the latest jars from the current branch,
# falling back to develop.
# If --unstable is specified, always fetch from commit artifacts on foundry.
# If --local is specified, only fetch jars from the local cache.
# If --copper is specified, only fetch the Copper jars.
# Parse command line argumants.
# Hacky, but getopts seems like overkill for this...
rev_name=""
for arg in "$@"; do
if [[ $arg != -* ]]; then
rev_name=$arg
break
fi
done
COMMIT_ARTIFACTS="https://foundry.remexre.xyz/commit-artifacts/"
args=$*
function has_jars {
if [[ $args == *--local* ]]; then
[[ -d "JARS-BAK/$1" ]]
else
wget --spider -q "$COMMIT_ARTIFACTS/$1"
fi
}
rev=""
# Look for jars in the specified revision
if [[ -n $rev_name ]]; then
rev=$(git rev-parse "$rev_name")
fi
# Get the hash of the latest commit on develop.
# This always gives the latest commit regardless of if the repo is up to date,
# and works in a Jenkins checkout.
DEVELOP=$(git ls-remote https://github.com/melt-umn/silver develop | cut -f1 | head -n1)
# Look for jars in the current commit and its parents.
# First, check that we are inside a git repo.
if [[ -z $rev ]] && git rev-parse --is-inside-work-tree 1> /dev/null 2> /dev/null; then
# Walk the history in topological order, fully exploring each chain of commits
# before newer commits from other merged chain.
for commit in $(git rev-list --topo-order HEAD "^$DEVELOP"); do
echo "Looking for jars from past commit $commit"
if has_jars "$commit"; then
echo "Found jars from past commit"
rev=$commit
break
fi
done
fi
# Figure out how to obtain the jars from the revision we chose.
if [[ $* == *--local* ]]; then
if [[ -z $rev ]]; then
echo "Failed to find local jars for the specified revision."
exit 1
fi
echo "Fetching local jars..."
LOCAL_STORE="JARS-BAK/$rev"
REMOTE_STORE=
JARS_BAK=
elif [[ $* != *--unstable* && $* != *--local* && (-z $rev || $rev == "$DEVELOP") ]]; then
echo "Fetching latest stable jars..."
LOCAL_STORE=/web/research/melt.cs.umn.edu/downloads/silver-dev/jars
REMOTE_STORE="https://melt.cs.umn.edu/downloads/silver-dev/jars"
JARS_BAK=JARS-BAK
else
git --no-pager show --quiet "$rev"
if ! has_jars "$rev"; then
echo "Cound not find jars for commit"
exit 1
fi
echo "Warning: Fetching unstable jars!"
LOCAL_STORE=
REMOTE_STORE="$COMMIT_ARTIFACTS/$rev"
JARS_BAK="JARS-BAK/$rev"
fi
if [[ $* == *--copper* ]]; then
# Only fetch the Copper jars, if requested
FILES="CopperCompiler.jar"
else
FILES="CopperCompiler.jar commonmark-0.17.1.jar silver.compiler.composed.Default.jar SilverRuntime.jar"
fi
mkdir -p jars
if [[ -n "$LOCAL_STORE" && -d $LOCAL_STORE ]]; then
# We have downloaded the jars before, just go copy them.
for file in $FILES; do
cp "$LOCAL_STORE/$file" jars/
done
else
# Download the jars.
# There's probably a better way to do this!
# Using -r causes lots of pointless downloads of variations of the index.html
# even if -A.jar is used they still get downloaded...
URLS=""
for file in $FILES; do
URLS="$URLS $REMOTE_STORE/$file"
done
# We're going to download them to here
mkdir -p "$JARS_BAK"
# -N Pay attention to timestamps, to avoid needless redownloads.
# -P jars/ Put the files in jars/
# -nv Don't be so verbose!
wget -N -P "$JARS_BAK/" -nv $URLS
# Always overwrite all the files in jars.
for file in $FILES; do
cp "$JARS_BAK/$file" jars/
done
fi