2 # Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
10 # Tell build.sh and test.sh that we're a bot.
11 export PNACL_BUILDBOT=true
12 # Make TC bots print all log output to console (this variable only affects
14 export PNACL_VERBOSE=true
16 # This affects trusted components of gyp and scons builds.
17 # The setting OPT reuslts in optimized/release trusted executables,
18 # the setting DEBUG results in unoptimized/debug trusted executables
20 # If true, terminate script when first scons error is encountered.
21 FAIL_FAST=${FAIL_FAST:-true}
22 # This remembers when any build steps failed, but we ended up continuing.
24 # For scons builds an empty target indicates all targets should be built.
25 # This does not run any tests, though.
26 # Large tests are not included in this group because they cannot be run
27 # in parallel (they can do things like bind to local TCP ports). Large
28 # tests are run separately in the functions below.
29 readonly SCONS_EVERYTHING=""
30 readonly SCONS_S_M="small_tests medium_tests"
31 readonly SCONS_S_M_IRT="small_tests_irt medium_tests_irt"
33 # This uses the newlib-based nonsfi_loader.
34 readonly SCONS_NONSFI_NEWLIB="\
37 # This uses the host-libc-based nonsfi_loader.
38 # Using skip_nonstable_bitcode=1 here disables the tests for zero-cost C++
39 # exception handling, which don't pass for Non-SFI mode yet because we
40 # don't build libgcc_eh for Non-SFI mode.
41 readonly SCONS_NONSFI="\
46 skip_nonstable_bitcode=1 \
47 use_newlib_nonsfi_loader=0"
49 # subset of tests used on toolchain builders
50 readonly SCONS_TC_TESTS="small_tests medium_tests"
52 readonly SCONS_COMMON="./scons --verbose bitcode=1"
53 readonly UP_DOWN_LOAD="buildbot/file_up_down_load.sh"
54 # This script is used by toolchain bots (i.e. tc-xxx functions)
55 readonly PNACL_BUILD="pnacl/build.sh"
56 readonly DRIVER_TESTS="pnacl/driver/tests/driver_tests.py"
59 tc-build-translator() {
60 echo @@@BUILD_STEP compile_translator@@@
61 ${PNACL_BUILD} translator-clean-all
62 ${PNACL_BUILD} translator-all
65 tc-prune-translator-pexes() {
66 echo @@@BUILD_STEP prune_translator_pexe@@@
67 ${PNACL_BUILD} translator-prune
70 tc-archive-translator() {
71 echo @@@BUILD_STEP archive_translator@@@
72 ${PNACL_BUILD} translator-tarball pnacl-translator.tgz
73 ${UP_DOWN_LOAD} UploadToolchainTarball ${BUILDBOT_GOT_REVISION} \
74 pnacl_translator pnacl-translator.tgz
76 echo @@@BUILD_STEP upload_translator_package_info@@@
77 ${NATIVE_PYTHON} build/package_version/package_version.py archive \
78 --archive-package=pnacl_translator \
79 pnacl-translator.tgz@https://storage.googleapis.com/nativeclient-archive2/toolchain/${BUILDBOT_GOT_REVISION}/naclsdk_pnacl_translator.tgz
81 ${NATIVE_PYTHON} build/package_version/package_version.py --annotate upload \
82 --upload-package=pnacl_translator --revision=${BUILDBOT_GOT_REVISION}
86 # extract the relevant scons flags for reporting
90 use_sandboxed_translator=1)
96 pnacl_generate_pexe=0)
109 # called when a scons invocation fails
112 echo "@@@STEP_FAILURE@@@"
113 if ${FAIL_FAST} ; then
114 echo "FAIL_FAST enabled"
119 # Clear out object, and temporary directories.
121 echo "@@@BUILD_STEP clobber@@@"
122 rm -rf scons-out ../xcodebuild ../out
125 # Generate filenames for arm bot uploads and downloads
127 echo -n "${BUILDBOT_BUILDERNAME}/${BUILDBOT_GOT_REVISION}"
130 NAME_ARM_DOWNLOAD() {
131 echo -n "${BUILDBOT_TRIGGERED_BY_BUILDERNAME}/${BUILDBOT_GOT_REVISION}"
134 NAME_ARM_TRY_UPLOAD() {
135 echo -n "${BUILDBOT_BUILDERNAME}/"
136 echo -n "${BUILDBOT_SLAVENAME}/"
137 echo -n "${BUILDBOT_BUILDNUMBER}"
139 NAME_ARM_TRY_DOWNLOAD() {
140 echo -n "${BUILDBOT_TRIGGERED_BY_BUILDERNAME}/"
141 echo -n "${BUILDBOT_TRIGGERED_BY_SLAVENAME}/"
142 echo -n "${BUILDBOT_TRIGGERED_BY_BUILDNUMBER}"
148 \( -name '*.o' -o -name '*.bc' -o -name 'test_results' \) \
149 -print0 | xargs -0 rm -rf
152 # Tar up the executables which are shipped to the arm HW bots
153 archive-for-hw-bots() {
157 echo "@@@BUILD_STEP tar_generated_binaries@@@"
160 # delete nexes from pexe mode directories to force translation
161 # TODO(dschuff) enable this once we can translate on the hw bots
162 #find scons-out/*pexe*/ -name '*.nexe' -print0 | xargs -0 rm -f
163 tar cvfz arm-scons.tgz scons-out/*arm*
165 echo "@@@BUILD_STEP archive_binaries@@@"
166 if [[ ${try} == "try" ]] ; then
167 ${UP_DOWN_LOAD} UploadArmBinariesForHWBotsTry ${name} arm-scons.tgz
169 ${UP_DOWN_LOAD} UploadArmBinariesForHWBots ${name} arm-scons.tgz
173 # Untar archived executables for HW bots
174 unarchive-for-hw-bots() {
178 echo "@@@BUILD_STEP fetch_binaries@@@"
179 if [[ ${try} == "try" ]] ; then
180 ${UP_DOWN_LOAD} DownloadArmBinariesForHWBotsTry ${name} arm-scons.tgz
182 ${UP_DOWN_LOAD} DownloadArmBinariesForHWBots ${name} arm-scons.tgz
185 echo "@@@BUILD_STEP untar_binaries@@@"
187 tar xvfz arm-scons.tgz --no-same-owner
190 # Build with gyp - this only exercises the trusted TC and hence this only
191 # makes sense to run for ARM.
193 local gypmode="Release"
194 if [ "${BUILD_MODE_HOST}" = "DEBUG" ] ; then
197 local toolchain_dir=native_client/toolchain/linux_x86/arm_trusted
198 local extra="-isystem ${toolchain_dir}/usr/include \
199 -Wl,-rpath-link=${toolchain_dir}/lib/arm-linux-gnueabihf \
200 -L${toolchain_dir}/lib \
201 -L${toolchain_dir}/lib/arm-linux-gnueabihf \
202 -L${toolchain_dir}/usr/lib \
203 -L${toolchain_dir}/usr/lib/arm-linux-gnueabihf"
204 # Setup environment for arm.
206 export AR=arm-linux-gnueabihf-ar
207 export AS=arm-linux-gnueabihf-as
208 export CC="arm-linux-gnueabihf-gcc ${extra} "
209 export CXX="arm-linux-gnueabihf-g++ ${extra} "
210 export LD="arm-linux-gnueabihf-g++ ${extra} "
211 export RANLIB=arm-linux-gnueabihf-ranlib
213 export GYP_DEFINES="target_arch=arm \
214 sysroot=${toolchain_dir} \
215 linux_use_tcmalloc=0 armv7=1 arm_thumb=1"
216 export GYP_GENERATORS=make
218 # NOTE: this step is also run implicitly as part of
219 # gclient runhooks --force
220 # it uses the exported env vars so we have to run it again
222 echo "@@@BUILD_STEP gyp_configure [${gypmode}]@@@"
224 native_client/build/gyp_nacl native_client/build/all.gyp
227 echo "@@@BUILD_STEP gyp_compile [${gypmode}]@@@"
228 make -C .. -k -j8 V=1 BUILDTYPE=${gypmode}
231 build-sbtc-prerequisites() {
233 # Sandboxed translators currently only require irt_core since they do not
235 ${SCONS_COMMON} platform=${platform} sel_ldr sel_universal irt_core
238 # Run a single invocation of scons as its own buildbot stage and handle errors
243 local info="$(relevant ${extra})"
244 # TODO(robertm): do we really need both nacl and nacl_irt_test
245 local mode="--mode=opt-host,nacl,nacl_irt_test"
246 if [ "${BUILD_MODE_HOST}" = "DEBUG" ] ; then
247 mode="--mode=dbg-host,nacl,nacl_irt_test"
250 # We truncate the test list ($test) because long BUILD_STEP strings cause
251 # Buildbot to fail (because the Buildbot master tries to use the string
253 echo "@@@BUILD_STEP scons-irt [${platform}] [${test:0:100}] [${info}]@@@"
254 ${SCONS_COMMON} ${extra} ${mode} platform=${platform} ${test} || handle-error
257 # Run a single invocation of scons as its own buildbot stage and handle errors
258 scons-stage-noirt() {
262 local info="$(relevant ${extra})"
263 local mode="--mode=opt-host,nacl"
264 if [ "${BUILD_MODE_HOST}" = "DEBUG" ] ; then
265 mode="--mode=dbg-host,nacl"
268 echo "@@@BUILD_STEP scons [${platform}] [${test}] [${info}]@@@"
269 ${SCONS_COMMON} ${extra} ${mode} platform=${platform} ${test} || handle-error
275 echo "@@@BUILD_STEP driver_tests ${arch}@@@"
276 ${DRIVER_TESTS} --platform="${arch}" || handle-error
280 # QEMU upload bot runs this function, and the hardware download bot runs
281 # mode-buildbot-arm-hw
282 mode-buildbot-arm() {
284 # "force_emulator=" disables use of QEMU, which enables building
285 # tests which don't work under QEMU.
286 local qemuflags="-j8 -k do_not_run_tests=1 force_emulator="
293 scons-stage-noirt "arm" "-j8" "run_hello_world_test"
295 # Don't run the rest of the tests on qemu, only build them.
296 # QEMU is too flaky for the main waterfall
298 # Normal pexe mode tests
299 scons-stage-noirt "arm" "${qemuflags}" "${SCONS_EVERYTHING}"
300 # This extra step is required to translate the pexes (because translation
301 # happens as part of CommandSelLdrTestNacl and not part of the
302 # build-everything step)
303 scons-stage-noirt "arm" "${qemuflags}" "${SCONS_S_M}"
304 # Large tests cannot be run in parallel
305 scons-stage-noirt "arm" "${qemuflags} -j1" "large_tests"
307 # also run some tests with the irt
308 scons-stage-irt "arm" "${qemuflags}" "${SCONS_S_M_IRT}"
310 # non-pexe-mode tests
311 scons-stage-noirt "arm" "${qemuflags} pnacl_generate_pexe=0" "nonpexe_tests"
313 build-sbtc-prerequisites "arm"
315 scons-stage-irt "arm" \
316 "${qemuflags} use_sandboxed_translator=1 translate_in_build_step=0" \
318 scons-stage-irt "arm" \
319 "${qemuflags} use_sandboxed_translator=1 translate_fast=1 \
320 translate_in_build_step=0" \
324 scons-stage-irt "arm" "${qemuflags}" "${SCONS_NONSFI_NEWLIB}"
325 scons-stage-irt "arm" "${qemuflags}" "${SCONS_NONSFI}"
328 mode-buildbot-arm-hw() {
330 local hwflags="-j2 -k naclsdk_validate=0 built_elsewhere=1"
332 scons-stage-noirt "arm" "${hwflags}" "${SCONS_S_M}"
333 # Large tests cannot be run in parallel
334 scons-stage-noirt "arm" "${hwflags} -j1" "large_tests"
336 # also run some tests with the irt
337 scons-stage-irt "arm" "${hwflags}" "${SCONS_S_M_IRT}"
339 scons-stage-noirt "arm" "${hwflags} pnacl_generate_pexe=0" "nonpexe_tests"
340 scons-stage-irt "arm" \
341 "${hwflags} use_sandboxed_translator=1 translate_in_build_step=0" \
343 scons-stage-irt "arm" \
344 "${hwflags} use_sandboxed_translator=1 translate_fast=1 \
345 translate_in_build_step=0" \
349 scons-stage-irt "arm" "${hwflags}" "${SCONS_NONSFI_NEWLIB}"
350 scons-stage-irt "arm" "${hwflags}" "${SCONS_NONSFI}"
355 # TODO(dschuff): move the gyp build to buildbot_pnacl.py
358 buildbot/buildbot_pnacl.py opt arm pnacl
361 mode-buildbot-arm-dbg() {
362 BUILD_MODE_HOST=DEDUG
364 archive-for-hw-bots $(NAME_ARM_UPLOAD) regular
367 mode-buildbot-arm-opt() {
369 archive-for-hw-bots $(NAME_ARM_UPLOAD) regular
372 mode-buildbot-arm-try() {
374 archive-for-hw-bots $(NAME_ARM_TRY_UPLOAD) try
377 # NOTE: the hw bots are too slow to build stuff on so we just
378 # use pre-built executables
379 mode-buildbot-arm-hw-dbg() {
380 BUILD_MODE_HOST=DEDUG
381 unarchive-for-hw-bots $(NAME_ARM_DOWNLOAD) regular
385 mode-buildbot-arm-hw-opt() {
386 unarchive-for-hw-bots $(NAME_ARM_DOWNLOAD) regular
390 mode-buildbot-arm-hw-try() {
391 unarchive-for-hw-bots $(NAME_ARM_TRY_DOWNLOAD) try
395 # These 2 functions are also suitable for local TC sanity testing.
399 local label="pnacl_newlib_dir=toolchain/${PNACL_TOOLCHAIN_DIR}"
400 local scons_flags="-k skip_trusted_tests=1 -j8 ${label}"
403 for arch in x86-32 x86-64 arm; do
404 driver-tests "${arch}"
407 # All the SCons tests (the same ones run by the main waterfall bot)
408 for arch in 32 64 arm; do
409 buildbot/buildbot_pnacl.py opt "${arch}" pnacl
412 # Run the GCC torture tests just for x86-32. Testing a single
413 # architecture gives good coverage without taking too long. We
414 # don't test x86-64 here because some of the torture tests fail on
415 # the x86-64 toolchain trybot (though not the buildbots, apparently
416 # due to a hardware difference:
417 # https://code.google.com/p/nativeclient/issues/detail?id=3697).
419 # Build the SDK libs first so that linking will succeed.
420 echo "@@@BUILD_STEP sdk libs @@@"
422 ./scons --verbose platform=x86-32 -j8 sel_ldr irt_core
424 echo "@@@BUILD_STEP torture_tests x86-32 @@@"
425 tools/toolchain_tester/torture_test.py pnacl x86-32 --verbose \
426 --concurrency=8 || handle-error
431 local scons_flags="-k skip_trusted_tests=1"
433 driver-tests "${arch}"
435 scons-stage-noirt "${arch}" "${scons_flags} -j8" "${SCONS_TC_TESTS}"
436 # Large tests cannot be run in parallel
437 scons-stage-noirt "${arch}" "${scons_flags} -j1" "large_tests"
438 scons-stage-noirt "${arch}" "${scons_flags} -j8 pnacl_generate_pexe=0" \
442 mode-buildbot-tc-x8664-linux() {
445 export PNACL_TOOLCHAIN_DIR=linux_x86/pnacl_newlib
446 export PNACL_PRUNE=true
449 if ! ${is_try} ; then
450 tc-prune-translator-pexes
451 tc-archive-translator
453 HOST_ARCH=x86_64 tc-tests-all ${is_try}
456 mode-buildbot-tc-x8632-linux() {
459 export PNACL_TOOLCHAIN_DIR=linux_x86/pnacl_newlib
461 # For now, just use this bot to test a pure 32 bit build.
462 HOST_ARCH=x86_32 tc-tests-fast "x86-32"
466 ######################################################################
467 # On Windows, this script is invoked from a batch file.
468 # The inherited PWD environmental variable is a Windows-style path.
469 # This can cause problems with pwd and bash. This line fixes it.
472 # Script assumed to be run in native_client/
473 if [[ $(pwd) != */native_client ]]; then
474 echo "ERROR: must be run in native_client!"
479 if [[ $# -eq 0 ]] ; then
480 echo "you must specify a mode on the commandline:"
484 if [ "$(type -t $1)" != "function" ]; then
486 echo "ERROR: unknown mode '$1'." >&2
492 if [[ ${RETCODE} != 0 ]]; then
493 echo "@@@BUILD_STEP summary@@@"
494 echo There were failed stages.