-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy-repo
More file actions
executable file
Β·218 lines (203 loc) Β· 7.86 KB
/
deploy-repo
File metadata and controls
executable file
Β·218 lines (203 loc) Β· 7.86 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/env bash
#
dir="$(dirname $0)"
if [[ ! -d $dir/ocaml ]]; then
echo "Expect OCaml clone in $dir/ocaml" >&2
exit 1
#elif [[ -n "$(git -C "$dir/ocaml" status --porcelain)" ]]; then
# echo 'The ocaml working tree is not clean' >&2
# exit 1
fi
if [[ ! -d $dir/opam-repository ]]; then
echo "Expect opam-repository clone in $dir/opam-repository" >&2
exit 1
elif [[ -n "$(git -C "$dir/opam-repository" status --porcelain)" ]]; then
echo 'The opam-repository working tree is not clean' >&2
exit 1
fi
cd "$dir"
if ! git -C ocaml rev-parse --verify relocatable-locks &> /dev/null; then
if ! git -C ocaml rev-parse --verify origin/relocatable-locks &> /dev/null; then
echo "origin/relocatable-locks not found?!" >&2
exit 1
fi
fi
declare -A DATES
declare -A SHAS
if [[ -e sha-cache ]]; then
while read -r file sha; do
SHAS[$file]="$sha"
done < sha-cache
fi
function sha256-of
{
if [[ -z ${SHAS[$1]} ]]; then
SHAS[$1]="$(curl -Ls "$2" | sha256sum | cut -f1 -d' ')"
echo "$1 ${SHAS[$1]}" >> sha-cache
fi
echo "${SHAS[$1]}"
}
# These should reflect current reality - i.e. ocaml/opam-repository itself
declare -A TRUNKS=(\
['4.08.2']=1 ['4.09.2']=1 ['4.10.3']=1 \
['4.11.3']=1 ['4.12.2']=1 ['4.13.2']=1 \
['4.14.3']=1 \
['5.0.1']=1 ['5.1.2']=1 ['5.2.2']=1 \
['5.3.1']=1 ['5.4.0']=1 ['5.5.0']=1)
declare -A DEPLOYED
function deploy
{
lock="$(git -C ocaml rev-parse --short "$1" 2>/dev/null)"
contained="$(git -C ocaml branch relocatable-locks --contains "$lock" 2>/dev/null)"
if [[ -z $contained ]]; then
echo "Lock not found: $1" >&2
exit 1
fi
date=$(git -C ocaml log -1 --first-parent --date=format:%Y%m%d --format=%ad $1)
DATES[d$date]="$((${DATES[d$date]:-0}+1))"
process_sh_script="$(git -C ocaml show $1:branches | sed -ne 's/^opam-install-file //p')"
if [[ -n $process_sh_script ]]; then
process_sh_script="$(git -C ocaml log --format=%H -1 $process_sh_script -- tools/opam/process.sh)"
# Fallback for locks before process.sh was added to the opam-install-file branch
[[ -n $process_sh_script ]] || process_sh_script='a90cb3efd215c063961b33758edab60cb213f351'
process_sh_sha256="$(sha256-of $process_sh_script https://raw.githubusercontent.com/dra27/ocaml/$process_sh_script/tools/opam/process.sh)"
else
process_sh_sha256=''
fi
fault=0
built=0
while read -r branch sha; do
if [[ -n ${DEPLOYED[$sha]} ]]; then
continue
else
DEPLOYED[$sha]=1
built=1
fi
version="$(git -C ocaml show $sha:VERSION | sed -e '2,$d;1s/+.*//')"
release="${version%~*}"
echo " Create $version for $branch ($(git -C ocaml rev-parse --short $sha)) in $lock"
if [[ ! -e opam-repository/packages/ocaml/ocaml.$release ]]; then
echo "ocaml.$release doesn't exist"
fault=1
fi
if ((fault)); then
continue
fi
case $release in
4.08.*|4.09.*) template='4.08';;
4.10.*|4.11.*) template='4.10';;
4.12.*|4.13.*) template='4.12';;
4.14.*|5.0.*|5.1.*|5.2.*) template="${release%.*}";;
5.*.*) template='5.3';;
*) echo "Unexpected release: $release"; exit 1;;
esac
sha256="$(sha256-of $sha https://github.com/dra27/ocaml/archive/$sha.tar.gz)"
mkdir -p opam-repository/packages/relocatable-compiler/relocatable-compiler.$version.$date.${DATES[d$date]}
if [[ -z $process_sh_script ]]; then
transforms=(-e 's|sh.*process.*|./configure"|' \
-e 's/\$build//' \
-e '/compiler-cloning/d' \
-e '/^install:/s/".*/make "install"]/')
else
transforms=(-e '/\$build/d')
fi
if [[ ! -e opam-repository/packages/ocaml-base-compiler/ocaml-base-compiler.$version ]]; then
transforms+=(-e 's/\$legacy//')
else
transforms+=(-e '/\$legacy/d')
fi
if [[ $date -ge 20250211 ]]; then
transforms+=(-e '/docdir/a\ "--with-relative-libdir=../lib/ocaml" {os != "win32"}' \
-e '/docdir/a\ "--with-relative-libdir=..\\\\lib\\\\ocaml" {os = "win32"}')
else
transforms+=(-e '/docdir/a\ "--enable-relative"')
fi
if [[ $date -ge 20250202 ]]; then
transforms+=(-e '/docdir/a\ "--with-stublibs=../stublibs" {os != "win32"}' \
-e '/docdir/a\ "--with-stublibs=..\\\\stublibs" {os = "win32"}')
fi
transforms+=(-e '/docdir/a\ "--enable-runtime-search=always"')
if [[ $date -ge 20240924 ]]; then
transforms+=(-e '/docdir/a\ "--enable-runtime-search-target"')
fi
{
sed "${transforms[@]}" \
-e "s/\\\$version/$version/g" \
-e "s/\\\$release/$release/g" \
-e "s/\\\$lock/$lock/g" \
-e "s/\\\$branch/$branch/g" \
-e "s/\\\$sha256/$sha256/g" \
-e "s/\\\$sha/$sha/g" opam-repository/relocatable-compiler-$template
if [[ $date -lt 20250202 && -n ${TRUNKS[$release]} ]]; then
cat <<EOF
setenv: [
# The ocaml.$release package doesn't apply these, and this version of
# Relocatable OCaml doesn't support --with-stublibs
[CAML_LD_LIBRARY_PATH = "%{_:stubsdir}%"]
[CAML_LD_LIBRARY_PATH += "%{lib}%/stublibs"]
]
x-env-path-rewrite: [
[CAML_LD_LIBRARY_PATH (";" {os = "win32"} ":" {os != "win32"}) "target"]
]
EOF
fi
if [[ -n $process_sh_script ]]; then
cat <<EOF
extra-source "process.sh" {
src:
"https://raw.githubusercontent.com/dra27/ocaml/$process_sh_script/tools/opam/process.sh"
checksum: "sha256=$process_sh_sha256"
}
post-messages: [
"Thanks for trying Relocatable OCaml - sorry there seems to be a problem! π«£π
Please check https://github.com/dra27/relocatable/issues
" {failure}
"Thanks for trying Relocatable OCaml! π₯³ππ
Any problems, please check https://github.com/dra27/relocatable/issues
" {!failure}
"This switch had to be compiled from sources, but future switches with the π
same compiler version and configuration should assemble instantly." {!failure & !_:cloned & compiler-cloning:version != "disabled"}
"As requested, this switch was compiled from sources π΄" {!failure & compiler-cloning:version = "disabled"}
"Switch cloned by %{_:clone-mechanism}% from %{_:clone-source}% π¨" {!failure & _:cloned}
]
EOF
else
cat <<EOF
post-messages: [
"Thanks for trying Relocatable OCaml - sorry there seems to be a problem! π«£π
Relocatable OCaml $version.$date.${DATES[d$date]} is an archive version - please
try a more recent version.
" {failure}
"Thanks for trying Relocatable OCaml! π₯³ππ
This is an archive version from $date - the compiler is relocatable, but opam
doesn't support cloning it, so while you can rename local switches and so forth,
you won't see any speed-up in switch creation.
" {!failure}
]
EOF
fi
} > opam-repository/packages/relocatable-compiler/relocatable-compiler.$version.$date.${DATES[d$date]}/opam
git -C opam-repository add packages/relocatable-compiler/relocatable-compiler.$version.$date.${DATES[d$date]}/opam
done < <(git -C ocaml show $1:backports)
if ((fault)); then
exit 1
fi
if [[ $built -eq 1 ]]; then
commit_date="$(git -C ocaml log -1 --first-parent --format=%ad $1)"
GIT_COMMITTER_DATE="$commit_date" git -C opam-repository commit --date="$commit_date" -F - <<EOF
$(git -C ocaml log -1 --first-parent --format=%s $1)
Deploying $date.${DATES[d$date]} ($lock)
EOF
fi
}
# The ~1 is only while flambda bit sits temporarily - that'll need translating
# to something else when that's fixed!
git -C opam-repository checkout -B relocatable relocatable-draft~1
git -C opam-repository checkout relocatable-draft -- relocatable-\* >/dev/null
git -C opam-repository rm --cached relocatable-\* >/dev/null
commit_date="$(git -C opam-repository log -1 --format=%cd)"
GIT_COMMITTER_DATE="$commit_date" git -C opam-repository commit --amend -C HEAD >/dev/null
for lock in $(git -C ocaml log --format='%H' --first-parent origin/relocatable-locks --reverse | tail -n +2); do
deploy $lock
done
rm opam-repository/relocatable-compiler-*