-
Notifications
You must be signed in to change notification settings - Fork 66
/
build-new-version.sh
executable file
·346 lines (285 loc) · 8.43 KB
/
build-new-version.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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#!/bin/bash
#
# This script can be run to add a new version of rust to those supported
# in the project. It automates away some of the tedium of working
# through checksum failures one-by-one.
set -e
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TARGET_VERSION="$1"
if [ -z "$TARGET_VERSION" ]; then
>&2 echo "Must specify a target version as first argument"
exit 1
fi
# if NIGHTLY_DATE is empty, it should download latest nightly version
NIGHTLY_DATE="$2"
CHANNEL_FILE="channel-rust-$TARGET_VERSION.toml"
TMPDIR=`mktemp -p "$PWD" -d`
cd "$TMPDIR"
TARGET_TRIPLES=(
aarch64-unknown-linux-gnu
aarch64-unknown-linux-musl
arm-unknown-linux-gnueabi
arm-unknown-linux-gnueabihf
armv5te-unknown-linux-gnueabi
armv5te-unknown-linux-musleabi
armv7-unknown-linux-gnueabihf
armv7-unknown-linux-musleabihf
i686-unknown-linux-gnu
powerpc-unknown-linux-gnu
x86_64-unknown-linux-gnu
riscv64gc-unknown-linux-gnu
thumbv7neon-unknown-linux-gnueabihf
)
RUSTC_TRIPLES=(
aarch64-unknown-linux-gnu
arm-unknown-linux-gnueabi
arm-unknown-linux-gnueabihf
armv7-unknown-linux-gnueabihf
i686-unknown-linux-gnu
x86_64-unknown-linux-gnu
)
is_nightly() {
if [ x"$TARGET_VERSION" == x"nightly" -a "$NIGHTLY_DATE" ]; then
true
else
false
fi
}
download() {
echo "download $@"
curl --fail -# -O $@
}
dlfile() {
component="$1"
triple="$2"
if is_nightly; then
download "https://static.rust-lang.org/dist/$NIGHTLY_DATE/$component-$TARGET_VERSION-$triple.tar.gz"
else
download "https://static.rust-lang.org/dist/$component-$TARGET_VERSION-$triple.tar.gz"
fi
}
get_md5sum() {
md5sum "$1" | cut -d ' ' -f1
}
get_sha256sum() {
sha256sum "$1" | cut -d ' ' -f1
}
get_rust_md5sum() {
component="$1"
triple="$2"
get_md5sum "$component-$TARGET_VERSION-$triple.tar.gz"
}
get_rust_sha256sum() {
component="$1"
triple="$2"
get_sha256sum "$component-$TARGET_VERSION-$triple.tar.gz"
}
cargo_url() {
local triple="$1"
grep -A 3 "^\[pkg.cargo.target.$triple\]" "$CHANNEL_FILE" | \
grep '^url =' | \
cut -d '=' -f2 | \
tr -d '[" ]'
}
cargo_version() {
cargo_url x86_64-unknown-linux-gnu | rev | cut -d'/' -f2 | rev | tr -d '-'
}
cargo_filename() {
local triple="$1"
cargo_url "$triple" | rev | cut -d'/' -f1 | rev
}
download_files() {
if is_nightly; then
download "https://static.rust-lang.org/dist/$NIGHTLY_DATE/$CHANNEL_FILE"
else
download "https://static.rust-lang.org/dist/$CHANNEL_FILE"
fi
# cargo for each supported host triple
for triple in "${RUSTC_TRIPLES[@]}"; do
download "$(cargo_url "$triple")"
done
# rustc
for triple in "${RUSTC_TRIPLES[@]}"; do
dlfile rustc "$triple"
done
# rust-std
for triple in "${TARGET_TRIPLES[@]}"; do
dlfile rust-std "$triple"
done
}
CARGO_APACHE_EXPECTED="71b224ca933f0676e26d5c2e2271331c"
CARGO_MIT_EXPECTED="b377b220f43d747efdec40d69fcaa69d"
check_cargo_license() {
for triple in "${RUSTC_TRIPLES[@]}"; do
cargofile=$(cargo_filename "$triple")
cargodir=$(basename "$cargofile" .tar.gz)
tar -zxf "$cargofile" "$cargodir"/LICENSE-APACHE
apache_md5sum="$( md5sum "$cargodir"/LICENSE-APACHE | cut -d ' ' -f1 )"
tar -zxf "$cargofile" "$cargodir"/LICENSE-MIT
mit_md5sum="$( md5sum "$cargodir"/LICENSE-MIT | cut -d ' ' -f1 )"
if [ "$apache_md5sum" != "$CARGO_APACHE_EXPECTED" ]; then
echo "ERROR: Apache license file hash has changed for $cargofile"
echo " Actual: $apache_md5sum"
echo " Expected: $CARGO_APACHE_EXPECTED"
exit 1
elif [ "$mit_md5sum" != "$CARGO_MIT_EXPECTED" ]; then
echo "ERROR: MIT license file hash has changed for $cargofile"
echo " Actual: $mit_md5sum"
echo " Expected: $CARGO_MIT_EXPECTED"
exit 1
fi
done
}
write_get_by_triple() {
cat <<EOF >>${RUST_BIN_RECIPE}
def get_by_triple(hashes, triple):
try:
return hashes[triple]
except:
raise bb.parse.SkipRecipe("Unsupported triple: %s" % triple)
EOF
}
write_std_md5() {
cat <<EOF >>${RUST_BIN_RECIPE}
def rust_std_md5(triple):
HASHES = {
EOF
for triple in "${TARGET_TRIPLES[@]}"; do
echo >>"$RUST_BIN_RECIPE" " \"$triple\": \"$(get_rust_md5sum rust-std "$triple")\","
done
cat <<EOF >>${RUST_BIN_RECIPE}
}
return get_by_triple(HASHES, triple)
EOF
}
write_std_sha256() {
cat <<EOF >>${RUST_BIN_RECIPE}
def rust_std_sha256(triple):
HASHES = {
EOF
for triple in "${TARGET_TRIPLES[@]}"; do
echo >>"$RUST_BIN_RECIPE" " \"$triple\": \"$(get_rust_sha256sum rust-std "$triple")\","
done
cat <<EOF >>${RUST_BIN_RECIPE}
}
return get_by_triple(HASHES, triple)
EOF
}
write_rustc_md5() {
cat <<EOF >>${RUST_BIN_RECIPE}
def rustc_md5(triple):
HASHES = {
EOF
for triple in "${RUSTC_TRIPLES[@]}"; do
echo >>"$RUST_BIN_RECIPE" " \"$triple\": \"$(get_rust_md5sum rustc "$triple")\","
done
cat <<EOF >>${RUST_BIN_RECIPE}
}
return get_by_triple(HASHES, triple)
EOF
}
write_rustc_sha256() {
cat <<EOF >>${RUST_BIN_RECIPE}
def rustc_sha256(triple):
HASHES = {
EOF
for triple in "${RUSTC_TRIPLES[@]}"; do
echo >>"$RUST_BIN_RECIPE" " \"$triple\": \"$(get_rust_sha256sum rustc "$triple")\","
done
cat >>"$RUST_BIN_RECIPE" <<EOF
}
return get_by_triple(HASHES, triple)
EOF
}
copyright_md5sum=NULL
get_copyright_md5sum() {
for triple in "${RUSTC_TRIPLES[@]}"; do
echo $triple
rustcfile=rustc-${TARGET_VERSION}-${triple}
tar -zxvf $rustcfile.tar.gz ${rustcfile}/COPYRIGHT
copyright_md5sum="$( md5sum ${rustcfile}/COPYRIGHT | cut -d ' ' -f1 )"
echo $copyright_md5sum
break
done
}
write_final_contents() {
cat <<EOF >>${RUST_BIN_RECIPE}
LIC_FILES_CHKSUM = "file://COPYRIGHT;md5=${copyright_md5sum}"
require rust-bin-cross.inc
EOF
}
write_cargo_recipe() {
cat <<EOF >>${CARGO_BIN_RECIPE}
# Recipe for cargo $(cargo_version)
# This corresponds to rust release ${TARGET_VERSION}
def get_by_triple(hashes, triple):
try:
return hashes[triple]
except:
raise bb.parse.SkipRecipe("Unsupported triple: %s" % triple)
def cargo_md5(triple):
HASHES = {
EOF
for triple in "${RUSTC_TRIPLES[@]}"; do
echo >>"$CARGO_BIN_RECIPE" " \"$triple\": \"$(get_md5sum "$(cargo_filename "$triple")")\","
done
cat <<EOF >>${CARGO_BIN_RECIPE}
}
return get_by_triple(HASHES, triple)
def cargo_sha256(triple):
HASHES = {
EOF
for triple in "${RUSTC_TRIPLES[@]}"; do
echo >>"$CARGO_BIN_RECIPE" " \"$triple\": \"$(get_sha256sum "$(cargo_filename "$triple")")\","
done
cat <<EOF >>${CARGO_BIN_RECIPE}
}
return get_by_triple(HASHES, triple)
def cargo_url(triple):
URLS = {
EOF
for triple in "${RUSTC_TRIPLES[@]}"; do
echo >>"$CARGO_BIN_RECIPE" " \"$triple\": \"$(cargo_url "$triple")\","
done
cat <<EOF >>${CARGO_BIN_RECIPE}
}
return get_by_triple(URLS, triple)
EOF
if is_nightly; then
echo >> "$CARGO_BIN_RECIPE" "DEPENDS += \"rust-bin-cross-\${TARGET_ARCH} (= ${TARGET_VERSION}-${NIGHTLY_DATE})\""
else
echo >> "$CARGO_BIN_RECIPE" "DEPENDS += \"rust-bin-cross-\${TARGET_ARCH} (= ${TARGET_VERSION})\""
fi
cat <<EOF >>${CARGO_BIN_RECIPE}
LIC_FILES_CHKSUM = "\\
file://LICENSE-APACHE;md5=${CARGO_APACHE_EXPECTED} \\
file://LICENSE-MIT;md5=${CARGO_MIT_EXPECTED} \\
"
require cargo-bin-cross.inc
EOF
}
download_files
# validate extracted cargo license
check_cargo_license
if [ x"$TARGET_VERSION" == x"nightly" -a "$NIGHTLY_DATE" ]; then
RUST_BIN_RECIPE="$ROOT_DIR/recipes-devtools/rust/rust-bin-cross_${TARGET_VERSION}-${NIGHTLY_DATE}.bb"
CARGO_BIN_RECIPE="$ROOT_DIR/recipes-devtools/rust/cargo-bin-cross_${TARGET_VERSION}-${NIGHTLY_DATE}.bb"
else
RUST_BIN_RECIPE="$ROOT_DIR/recipes-devtools/rust/rust-bin-cross_$TARGET_VERSION.bb"
CARGO_BIN_RECIPE="$ROOT_DIR/recipes-devtools/rust/cargo-bin-cross_$TARGET_VERSION.bb"
fi
# create/clear files
echo "" >"$RUST_BIN_RECIPE"
echo "" >"$CARGO_BIN_RECIPE"
# write the rust recipe
write_get_by_triple
write_std_md5
write_std_sha256
write_rustc_md5
write_rustc_sha256
get_copyright_md5sum
write_final_contents
# write the cargo recipe
write_cargo_recipe
cd -
rm -rf "$TMPDIR"