aboutsummaryrefslogtreecommitdiff
path: root/tcwg-buildfarm-startcontainer.yaml
blob: 136370224cebea1a5ec927801805376d061b9c03 (plain)
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
- job:
    name: tcwg-buildfarm-startcontainer
    project-type: matrix
    defaults: global
    properties:
        - authorization:
            anonymous:
                - job-read
                - job-extended-read
            linaro:
                - job-build
                - job-cancel
        - build-discarder:
            days-to-keep: 30
            num-to-keep: 100
    parameters:
        - string:
            name: override
            default: ''
            description: 'Versions of components to build; e.g. binutils=binutils-gdb.git/linaro_binutils-2_25-branch gcc=gcc.git~linaro/gcc-5-branch glibc=glibc.git~release/2.21/master'
        - string:
            name: host_x86_64_languages
            default: 'default'
            description: 'Languages to build for x86_64-hosted toolchains, e.g., "c,c++" or "all" or "default"'
        - string:
            name: host_aarchXX_languages
            default: 'c,c++'
            description: 'Languages to build for AArchXX-hosted toolchains, e.g., "c,c++" or "all" or "default"'
        - string:
            name: runtests
            default: 'x86_64-host'
            description: 'Run toolchain testsuites: "yes", "no", "x86_64-host"'
        - bool:
            name: try_bootstrap
            default: 'true'
            description: 'Attempt to bootstrap GCC for compatible host and target combinations'
        - string:
            name: host_x86_64_excludecheck
            default: 'gdb'
            description: 'Do not run "make check" on these components on x86_64'
        - string:
            name: host_aarchXX_excludecheck
            default: 'gcc'
            description: 'Do not run "make check" on these components on AArchXX'
        - string:
            name: extraconfig
            default: ''
            description: 'Extra configuration files, syntax tool=path'
        - bool:
            name: rebuild
            default: true
            description: 'Rebuild the toolchain even if results are already on logserver'
        - string:
            name: log_name
            default: '${JOB_NAME}-${BUILD_NUMBER}/${builder_type}.$target'
            description: 'Logname directory on logserver'
        - bool:
            name: dont_fail
            default: false
            description: 'Do not fail the build'
        - string:
            name: log_server
            default: dev-01.tcwglab:/home/tcwg-buildslave/logs
            description: 'Log_Server'
        - string:
            name: targets
            default: 'cross_main cross_aux native_x86'
            description: 'Which target toolchains to build: cross_main cross_aux native_x86 native_aarch32 native_aarch64'
        - string:
            name: abe_branch
            default: refs/remotes/origin/stable
            description: 'ABE revision to test'
        - string:
            name: scripts_branch
            default: master
            description: 'Scripts branch to use'
        - string:
            name: build_container_type
            default: 'default'
            description: 'Type of container to use on the builder: docker, schroot, none, default. "default" means the script choose depending on the builder type'
        - string:
            name: build_container_distro
            default: 'trusty'
            description: 'Distro to use on the builder with non-default container type: trusty, xenial.'
        - string:
            name: displaytag
            default: 'manual'
            description: 'Tag to display in the Jenkins console, so that the build name is more helpful'
    disabled: true
    node: tcwg-x86_64-build
    child-workspace: $target
    concurrent: true
    display-name: 'TCWG DEAD ZZZ BuildFarm Start container'
    scm:
        - git:
            url: https://git-us.linaro.org/toolchain/abe.git
            refspec: +refs/changes/*:refs/remotes/changes/*
            branches:
                - $abe_branch
            skip-tag: true
            shallow-clone: true
            wipe-workspace: true
    axes:
        - axis:
            type: slave
            name: label
            values:
                - tcwg-x86_64-build
                - tcwg-x86_32-build
                - tcwg-tx1_64-build
                - tcwg-tx1_32-build
                - tcwg-tk1_32-build
                - tcwg-apm_64-build
                - tcwg-apm_32-build
        - axis:
            type: user-defined
            name: target
            values:
                - aarch64-linux-gnu
                - armv8l-linux-gnueabihf
                - arm-linux-gnueabi
                - arm-linux-gnueabihf
                - armeb-linux-gnueabihf
                - aarch64-none-elf
                - aarch64_be-none-elf
                - native
    execution-strategy:
        combination-filter: |
            label=="tcwg-x86_64-build" || target=="native"
        sequential: false
    wrappers:
        - timeout:
            timeout: 600
        - timestamps
        - ssh-agent-credentials:
            # tcwg-buildslave user id
            users:
                - 'e0958a95-204f-4c14-a66c-5e2be6c5d50a'
        - build-name:
            name: '#${BUILD_NUMBER}-${displaytag}'
    builders:
        - shell: |
            #!/bin/bash

            set -ex

            mkdir -p artifacts/

            git clone -b $scripts_branch --depth 1 https://git-us.linaro.org/toolchain/jenkins-scripts

            case ${label} in
                tcwg-x86_64-build)
                    builder_arch=amd64
                    builder_type=x86_64
                    ;;
                tcwg-x86_32-build)
                    builder_arch=i386
                    builder_type=i686
                    ;;
                tcwg-tx1_64-build)
                    builder_arch=arm64
                    builder_type=aarch64
                    ;;
                tcwg-tx1_32-build)
                    builder_arch=armhf
                    builder_type=armv8
                    ;;
                tcwg-tk1_32-build)
                    builder_arch=armhf
                    builder_type=armv7
                    ;;
                tcwg-apm_64-build)
                    builder_arch=arm64
                    builder_type=aarch64-apm
                    ;;
                tcwg-apm_32-build)
                    builder_arch=armhf
                    builder_type=armv8-apm
                    ;;
                *) echo "ERROR: Unsupported slave: $slave"; exit 1 ;;
            esac

            case "$target--${builder_arch}" in
                native--arm64) target_kind=native_aarch64 ;;
                native--armhf) target_kind=native_aarch32 ;;
                native--amd64|native--i386) target_kind=native_x86 ;;
                armeb-linux-gnueabihf--*|*-none-elf--*) target_kind=cross_aux ;;
                *-linux-gnu*--*) target_kind=cross_main ;;
                *) echo "ERROR: Cannot handle target: $target"; exit 1 ;;
            esac

            if ! echo "$targets" | grep -q "$target_kind"; then
                echo "NOTE: Skipping target $target because $target_kind is not in list: $targets"
                # Create at least an (empty) artifact so that Jenkins does not complain
                echo > artifacts/target-skipped.txt
                exit 0
            fi

            # Select container type. If the user chose a non-default
            # value, then use it whatever the builder type
            if [ "x${build_container_type}" = "xdefault" ]; then
                case ${builder_arch} in
                    amd64|i386|arm64|armhf)
                        build_container_type=docker
                        build_container_distro=trusty
                        ;;
                    *) echo "ERROR: Unsupported builder_arch: ${builder_arch}"; exit 1 ;;
                esac
            fi

            # Start build container
            builder=$(./jenkins-scripts/nodename2hostname.sh $NODE_NAME)
            bash -x ./jenkins-scripts/start-container-${build_container_type}.sh --arch ${builder_arch} --distro ${build_container_distro} --session-host ${builder} > build-container.sh

            # Define CONTAINER, CONTAINER_CLEANUP, session_host and session_port
            . ./build-container.sh
            BUILD_CONTAINER="${CONTAINER}"
            BUILD_CONTAINER_CLEANUP="${CONTAINER_CLEANUP}"

            # Make sure to cleanup build container if something goes
            # wrong when preparing the test environment
            if [ x"${BUILD_CONTAINER_CLEANUP}" != x ]; then
                CONTAINERS_CLEANUP="${BUILD_CONTAINER_CLEANUP}"
                trap "${CONTAINERS_CLEANUP}" EXIT
            fi

            case "${target_kind}-$runtests-${builder_arch}" in
                "cross_main"-"yes"-*|"cross_main"-"x86_64-host"-"amd64"|"cross_main"-"x86_64-host"-"i386")
                    case "$target" in
                        aarch64*) test_container_arch=arm64 ;;
                        armv8*) test_container_arch=armv8hf ;;
                        arm*) test_container_arch=armhf ;;
                        *) echo "ERROR: Wrong target $target"; exit 1 ;;
                    esac

                    if echo "$override" | grep -q -e "--extraconfigdir ../config/gcc5" \
                            || true \
                                && [ x"$target" = x"aarch64-linux-gnu" ]; then
                        # Sanitizers in GCC-5 and GCC-6 toolchains for
                        # aarch64-linux-gnu don't support 48-bit VA.
                        # Therefore don't run them on Xenial tester: do
                        # not start a docker container here, and use abe's
                        # legacy schroot support on older tester boards
                        # (tcwg-apm-0[34])
                        :
                    else

                        # AArch32 and AArch64 test boards are currently:
                        # tcwg-tk1-0[34]: AArch32 (armv7)
                        # tcwg-tx1-0[34]: AArch32 (armv8) and AArch64
                        case ${test_container_arch} in
                            armhf)
                                tester_labels="tcwg-tk1_32-test"
                                ;;
                            armv8hf)
                                tester_labels="tcwg-tx1_32-test"
                                test_container_arch=armhf
                                ;;
                            arm64)
                                tester_labels="tcwg-tx1_64-test"
                                ;;
                        esac
                        testers=$(
                            for label in $tester_labels; do
                                wget -O - https://ci.linaro.org/label/$label/api/json?pretty=true 2>/dev/null | grep nodeName | cut -d: -f 2 | sed -e 's/"//g' -e "s/\$/.tcwglab/"
                            done)
                        tester_min_load_name=""
                        tester_min_load_value="999"
                        for tester in $testers; do
                            load_value=$(docker -H $tester:2375 ps | wc -l)
                            if [ $load_value -lt $tester_min_load_value ]; then
                                tester_min_load_name=$tester
                                tester_min_load_value=$load_value
                            fi
                        done
                        if [ x"$tester_min_load_name" = x"" ]; then
                            echo "ERROR: Cannot find tester for $test_container_arch"
                            exit 1
                        fi
                        tester=$tester_min_load_name
                        # For the moment, support only docker containers on the tester machine
                        bash -x ./jenkins-scripts/start-container-docker.sh --arch ${test_container_arch} --distro trusty --session-host ${tester} --task test > test-container.sh
                    fi
                    ;;
            esac

            TEST_CONTAINER=
            TEST_CONTAINER_CLEANUP=
            test_session_host=
            test_session_port=
            # If we use a remote tester machine, tell jenkins.sh how
            # to override abe's default
            if [ -f test-container.sh ]; then
                . ./test-container.sh
                TEST_CONTAINER="${CONTAINER}"
                TEST_CONTAINER_CLEANUP="${CONTAINER_CLEANUP}"
                test_session_host=${session_host}
                test_session_port=${session_port}
                echo "${test_session_host}:${test_session_port}" | tee $WORKSPACE/test-container.data

                if [ x"${CONTAINERS_CLEANUP}" != x ]; then
                    CONTAINERS_CLEANUP="${CONTAINERS_CLEANUP} ; ${TEST_CONTAINER_CLEANUP}"
                else
                    CONTAINERS_CLEANUP="${TEST_CONTAINER_CLEANUP}"
                fi
                if [ x"${SSH_AGENT_CLEANUP}" = x ]; then
                    trap "${CONTAINERS_CLEANUP}" EXIT
                else
                    trap "${CONTAINERS_CLEANUP} ; eval \`${SSH_AGENT_CLEANUP}\`" EXIT
                fi

                runtests_opt="--runtests --testcontainerfile $WORKSPACE/test-container.data"
            else
                case "$target_kind-$runtests-${builder_arch}" in
                    *-"yes"-*|*-"x86_64-host"-"amd64"|*-"x86_64-host"-"i386")
                        runtests_opt="--runtests"
                        ;;
                    *)
                        runtests_opt=""
                        ;;
                esac
            fi

            ${BUILD_CONTAINER} 'echo "Build session is up; ulimit config:"; ulimit -a'

            case ${builder_arch} in
                amd64|i386) languages="$host_x86_64_languages" ;;
                *) languages="$host_aarchXX_languages" ;;
            esac

            if $try_bootstrap; then
                bootstrap="--bootstrap"
            else
                bootstrap=""
            fi

            if [ x"$log_name" != x"" ]; then
                eval "logname_opt=\"--logname $log_name\""
            fi

            if $rebuild; then
                norebuild=""
            else
                norebuild="--norebuild"
            fi

            case ${builder_arch} in
                amd64|i386) excludecheck="$host_x86_64_excludecheck" ;;
                *) excludecheck="$host_aarchXX_excludecheck" ;;
            esac

            excludecheck_opt=""
            for testsuite in $excludecheck; do
                excludecheck_opt="$excludecheck_opt --excludecheck $testsuite"
            done

            # If there were extraconfig options, extract the
            # corresponding repo
            if test -n "$extraconfig" ; then
                git clone http://git.linaro.org/toolchain/abe-extraconfigs.git
            fi

            extraconfig_opt=""
            for config in $extraconfig; do
                case ${extraconfig} in
                    *=*)
                        tool=${extraconfig%=*}
                        value=${extraconfig#*=}
                        ;;
                    *)
                        echo ERROR: wrong extraconfig: $extraconfig
                        exit 1
                        ;;
                esac
                extraconfig_opt="${extraconfig_opt} --extraconfig $tool=$PWD/abe-extraconfigs/$value"
            done

            result="0"

            ${BUILD_CONTAINER} "cd ${WORKSPACE} && bash -x ${WORKSPACE}/jenkins-scripts/jenkins.sh --workspace ${WORKSPACE} --abedir ${WORKSPACE} --target ${target} --override \"$override\" --languages ${languages} $bootstrap $runtests_opt $excludecheck_opt ${extraconfig_opt} --logserver $log_server $logname_opt $norebuild" || result=$?

            # If we actually built a toolchain, save its manifest.
            # If the build was a no-op (results already present on log_server),
            # copy the existing ones.
            if [ -d _build/builds ]; then
                manifest="`find _build/builds/ -name destdir -prune -o -name \*manifest.txt -print`"
            else
                manifest=""
            fi
            if [ x"${manifest}" != x ]; then
                cp ${manifest} artifacts/
            else
                # We need to do the same name expansion as jenkins.sh
                eval dir="$log_name"
                scp "$log_server/$dir/*manifest.txt" artifacts/
            fi

            # Save logs and their directory structure
            rsync -a --exclude="/logs/" --include="*/" --include="*.log" --include="*.err" --include="*.out" --include="*.txt" --exclude="*" --prune-empty-dirs ./ ./logs/
            if ! tar -I pxz -cf ./artifacts/logs.tar.xz ./logs/ >/dev/null 2>&1; then
                # PXZ can [rarely] fail due to high RAM usage, so fallback to normal XZ.
                rm -f ./artifacts/logs.tar.xz
                tar -cJf ./artifacts/logs.tar.xz ./logs/
            fi

            echo "Result of jenkins.sh: $result"
            if $dont_fail; then
                result="0"
            fi
            exit $result
    publishers:
        - archive:
            artifacts: 'artifacts/*'
            latest-only: false