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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
#!/bin/bash
# Pretty name for PROJECT's version
#rr[PROJECT_version]
# PROJECT's git url
#rr[PROJECT_url]
# PROJECT's git branch or SHA1 revision parsable by git rev-parse.
#rr[PROJECT_branch]
# PROJECT's git SHA1 revision. These are mostly used in manifests.
#rr[PROJECT_rev]
# Baseline branch name for current configuration. These branches are
# present in all above git repos.
#rr[baseline_branch]="linaro-local/ci/CONFIGURATION"
# PROJECT that we are testing in this build. Use ${rr[current_branch]} for
# this project, and ${rr[baseline_branch]} for all other projects.
#rr[current_project]="$current_project"
# Git branch or SHA1 revision of ${rr[current_project]} to test.
#rr[current_branch]="$current_branch"
# Run mode: bisect or non-bisect. In bisect mode we do a couple things
# slightly differently (e.g., don't touch repo in clone_repo() ).
#rr[mode]="$mode"
# Ignore failures in check_regression, which forces update_baseline().
#rr[reset_baseline]="$reset_baseline"
# Target architecture to build for: arm or aarch64.
#rr[target]="$target"
# Top-level artifacts directory.
#rr[top_artifacts]="$top_artifacts"
# Reset artifacts to an empty state. ${rr[top_artifacts]}/results is the most
# important artifact, since it records the metric of how successful the build
# is.
reset_artifacts ()
{
(
set -euf -o pipefail
# Clean ${rr[top_artifacts]} but preserve
# - ${rr[top_artifacts]}/console.log and $run_step_artifacts/console.log, which
# are being written to by run_step().
# - ${rr[top_artifacts]}/jenkins/*, which is cleaned by tcwg_kernel.yaml.
fresh_dir $run_step_top_artifacts \
$run_step_top_artifacts/console.log \
$run_step_artifacts/console.log \
"$run_step_top_artifacts/jenkins/*"
local single_branch=${rr[baseline_branch]}
# Clone base-artifacts so that run_step can rsync artifacts for skipped
# steps.
# base-artifacts repo is big and changes all the time, so we
# fetch only the $baseline_branch, instead of all branches.
rr[base-artifacts_rev]="${rr[base-artifacts_rev]-${rr[baseline_branch]}}"
clone_or_update_repo base-artifacts ${rr[base-artifacts_rev]} https://git-us.linaro.org/toolchain/ci/base-artifacts.git auto $single_branch
cat <<EOF | manifest_out
rr[base-artifacts_rev]=$(git -C base-artifacts rev-parse HEAD)
EOF
)
}
# Clone repository for $project
# $1: Repo / project name
clone_repo ()
{
(
set -euf -o pipefail
local project="$1"
if [ x"${rr[mode]}" = x"bisect" ]; then
# Cleanup current checkout in bisect mode.
git_clean "$project"
return 0
fi
local branch
# Select the branch to build.
# ${rr[current_branch]} specifies branch for ${rr[current_project]},
# and everything else uses baseline branch.
if [ x"$project" = x"${rr[current_project]}" ]; then
if [ x"${rr[current_branch]}" = x"default" ]; then
branch=${rr[${current_project}_branch]}
elif [ x"${rr[current_branch]}" = x"baseline" ]; then
branch="refs/remotes/baseline/${rr[baseline_branch]}"
else
branch=${rr[current_branch]}
fi
else
branch="refs/remotes/baseline/${rr[baseline_branch]}"
fi
branch="${rr[${project}_rev]-$branch}"
# Decide on whether to use read-only or read-write mode for
# refs/remotes/baseline. We use read-only wherever possible to allow
# developers without ssh keys on Linaro git servers to reproduce builds
# in --mode "baseline".
local read_only="true"
if [ x"$project" = x"${rr[current_project]}" -a \
x"${rr[mode]}" = x"jenkins-full" ]; then
read_only=false
fi
# Clone origin remote
clone_or_update_repo_no_checkout $project ${rr[${project}_url]} auto "" > /dev/null
# Add baseline remote
git_init_linaro_local_remote $project baseline $read_only
# Checkout, now that we have both origin and baseline remotes ready.
clone_or_update_repo $project $branch ${rr[${project}_url]} > /dev/null
local cur_rev
cur_rev=$(git -C $project rev-parse HEAD)
cat <<EOF | manifest_out
rr[${project}_rev]=$cur_rev
EOF
if [ x"$project" = x"${rr[current_project]}" ]; then
local baseline_rev
baseline_rev=$(git_rev_parse_long $project ${rr[baseline_branch]} baseline)
# Prepare for failure. If build fails we will bisect sha1 for
# ${rr[current_branch]} and sha1 for ${rr[baseline_branch]}.
cat > ${rr[top_artifacts]}/trigger-bisect-on-failure <<EOF
current_project=${rr[current_project]}
baseline_rev=$baseline_rev
bad_rev=$cur_rev
EOF
git -C $project rev-list --count HEAD ^$baseline_rev > ${rr[top_artifacts]}/distance-to-baseline
fi
)
}
# Prepare ABE tree for [partial] GNU builds
prepare_abe ()
{
(
set -euf -o pipefail
clone_or_update_repo abe tested https://git-us.linaro.org/toolchain/abe.git > /dev/null
cd abe
# Add ccache wrappers.
rm -rf $(pwd)/bin
mkdir $(pwd)/bin
cat > $(pwd)/bin/gcc <<EOF
#!/bin/sh
exec ccache /usr/bin/gcc "\$@"
EOF
chmod +x $(pwd)/bin/gcc
cat > $(pwd)/bin/g++ <<EOF
#!/bin/sh
exec ccache /usr/bin/g++ "\$@"
EOF
chmod +x $(pwd)/bin/g++
export PATH=$(pwd)/bin:$PATH
./configure --with-git-reference-dir=/home/tcwg-buildslave/snapshots-ref
)
}
# Build ABE component
# $1: Component -- ABE component to build.
build_abe ()
{
(
set -euf -o pipefail
local component="$1"
local project stage
case "$component" in
stage1)
project=gcc
stage="--stage 1"
;;
stage2)
project=gcc
stage="--stage 2"
;;
*)
project=$component
stage=""
;;
esac
clone_repo $project
# Don't use ABE's repo clone functions and setup abe/snapshots/ directory
# to have the right entries.
local git_dir git_path
git_dir="$(basename ${rr[${project}_url]})"
git_path="abe/snapshots/$git_dir"
rm -rf $git_path $git_path~master
ln -s $(pwd)/$project $git_path
ln -s $(pwd)/$project $git_path~master
cd abe
local gnu_target
gnu_target=$(print_gnu_target ${rr[target]})
# Remove previous build directories and .stamp files.
# We rely on ccache for fast rebuilds.
set +f; rm -rf builds/x86_64-unknown-linux-gnu/$gnu_target/$git_dir~master*; set -f
export PATH=$(pwd)/bin:$PATH
if [ x"$component" != x"stage2" ]; then
# TODO: Fix install_sysroot logic in ABE.
# ABE tries to install sysroot even for partial builds, e.g.,
# with "--build binutils". Workaround by patching ABE.
sed -i -e "s/do_install_sysroot/:/" lib/control.sh
else
git checkout -- lib/control.sh
fi
ccache -z
# Run "./abe.sh --build $project".
./abe.sh \
--build $project \
--target $gnu_target \
--extraconfigdir config/master \
--disable update \
$project=${rr[${project}_url]}~master \
$stage
ccache -s
)
}
# Build LLVM
build_llvm ()
{
(
set -euf -o pipefail
clone_repo llvm
# Copy only components from the monorepo that are required for kernel build
rsync -a --del --exclude /tools/clang llvm/llvm/ llvm-src/
rsync -a --del llvm/clang/ llvm-src/tools/clang/
# Setup ccache and ninja wrappers.
rm -rf $(pwd)/bin
mkdir $(pwd)/bin
cat > $(pwd)/bin/cc <<EOF
#!/bin/sh
exec ccache /usr/bin/gcc "\$@"
EOF
chmod +x $(pwd)/bin/cc
cat > $(pwd)/bin/c++ <<EOF
#!/bin/sh
exec ccache /usr/bin/g++ "\$@"
EOF
chmod +x $(pwd)/bin/c++
if [ -f /usr/local/bin/ninja.bin ]; then
# Use ninja configuration from llvm buildbots to avoid running out of RAM.
cat > $(pwd)/bin/ninja <<EOF
#!/bin/sh
exec /usr/local/bin/ninja.bin -m 30 -M 50 -D 5000 "\$@"
EOF
chmod +x $(pwd)/bin/ninja
fi
export PATH=$(pwd)/bin:$PATH
# Remove stale build directories. We rely on ccache for fast rebuilds.
rm -rf llvm-build llvm-install
mkdir -p llvm-build
cd llvm-build
cmake -G Ninja ../llvm-src -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=True -DCMAKE_INSTALL_PREFIX=../llvm-install -DLLVM_TARGETS_TO_BUILD=$(print_llvm_target ${rr[target]})
ccache -z
ninja
ninja install
ccache -s
)
}
# Check if current build regressed compared to the baseline
# (unless ${rr[reset_baseline]} is set).
check_regression ()
{
(
set -euf -o pipefail
if ! ${rr[reset_baseline]} && ! no_regression_p; then
# Fail.
false
fi
)
}
# Commit current result and artifacts to the baseline repository
update_baseline ()
{
(
set -euf -o pipefail
local amend=""
local prev_head=""
# We discard baseline entries for results worse or same than
# the current one, but keep entries for results that are better
# (so that we have a record of pending regressions).
while no_regression_p; do
if git -C base-artifacts rev-parse HEAD^ >/dev/null 2>&1; then
prev_head=$(git -C base-artifacts rev-parse HEAD)
git -C base-artifacts reset --hard HEAD^
else
# We got to the beginning of git history, so amend the current
# commit. The initial state of baseline is "empty" branch,
# which we treat as worst possible in no_regression_p().
amend="--amend"
prev_head=""
break
fi
done
# For every regression we want to keep artifacts for the first-bad
# build, so discard one less than needed.
if [ x"$prev_head" != x"" ]; then
git -C base-artifacts reset --hard $prev_head
fi
# Rsync current artifacts.
# !!! From this point on, logs and other artifacts won't be included
# in base-artifacts.git repo (though they will be uploaded to jenkins).
rsync -a --del --exclude /.git ${rr[top_artifacts]}/ base-artifacts/
local build_rev
build_rev=$(git -C ${rr[current_project]} rev-parse HEAD)
cd base-artifacts
git add .
git commit $amend -m "${rr[current_project]}-$build_rev: $(tail -n1 ${rr[top_artifacts]}/results)
$(cat ${rr[top_artifacts]}/results)"
)
}
# Push to ${rr[current_project]} baseline branch and to base-artifacts repo.
push_baseline ()
{
(
set -euf -o pipefail
git_init_linaro_local_remote base-artifacts baseline false
git_push base-artifacts baseline ${rr[baseline_branch]}
git_push ${rr[current_project]} baseline ${rr[baseline_branch]}
)
}
|