| OLD | NEW |
| (Empty) |
| 1 #!/bin/bash | |
| 2 # Copyright (c) 2012 The Chromium 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. | |
| 5 # | |
| 6 # Bash functions used by buildbot annotator scripts for the android | |
| 7 # build of chromium. Executing this script should not perform actions | |
| 8 # other than setting variables and defining of functions. | |
| 9 | |
| 10 # Number of jobs on the compile line; e.g. make -j"${JOBS}" | |
| 11 JOBS="${JOBS:-4}" | |
| 12 | |
| 13 # Clobber build? Overridden by bots with BUILDBOT_CLOBBER. | |
| 14 NEED_CLOBBER="${NEED_CLOBBER:-0}" | |
| 15 | |
| 16 | |
| 17 # Parse named arguments passed into the annotator script | |
| 18 # and assign them global variable names. | |
| 19 function bb_parse_args { | |
| 20 while [[ $1 ]]; do | |
| 21 case "$1" in | |
| 22 --factory-properties=*) | |
| 23 FACTORY_PROPERTIES="$(echo "$1" | sed 's/^[^=]*=//')" | |
| 24 BUILDTYPE=$(bb_get_json_prop "$FACTORY_PROPERTIES" target) | |
| 25 ;; | |
| 26 --build-properties=*) | |
| 27 BUILD_PROPERTIES="$(echo "$1" | sed 's/^[^=]*=//')" | |
| 28 ;; | |
| 29 *) | |
| 30 echo "@@@STEP_WARNINGS@@@" | |
| 31 echo "Warning, unparsed input argument: '$1'" | |
| 32 ;; | |
| 33 esac | |
| 34 shift | |
| 35 done | |
| 36 } | |
| 37 | |
| 38 # Function to force-green a bot. | |
| 39 function bb_force_bot_green_and_exit { | |
| 40 echo "@@@BUILD_STEP Bot forced green.@@@" | |
| 41 exit 0 | |
| 42 } | |
| 43 | |
| 44 function bb_run_gclient_hooks { | |
| 45 gclient runhooks | |
| 46 } | |
| 47 | |
| 48 # Basic setup for all bots to run after a source tree checkout. | |
| 49 # Args: | |
| 50 # $1: source root. | |
| 51 # $2 and beyond: key value pairs which are parsed by bb_parse_args. | |
| 52 function bb_baseline_setup { | |
| 53 echo "@@@BUILD_STEP Environment setup@@@" | |
| 54 SRC_ROOT="$1" | |
| 55 # Remove SRC_ROOT param | |
| 56 shift | |
| 57 | |
| 58 bb_parse_args "$@" | |
| 59 | |
| 60 cd $SRC_ROOT | |
| 61 if [ ! "$BUILDBOT_CLOBBER" = "" ]; then | |
| 62 NEED_CLOBBER=1 | |
| 63 fi | |
| 64 | |
| 65 export GOMA_DIR=/b/build/goma | |
| 66 | |
| 67 local BUILDTOOL=$(bb_get_json_prop "$FACTORY_PROPERTIES" buildtool) | |
| 68 if [ $BUILDTOOL = "ninja" ]; then | |
| 69 export GYP_GENERATORS=ninja | |
| 70 fi | |
| 71 | |
| 72 . build/android/envsetup.sh | |
| 73 | |
| 74 if [ "$NEED_CLOBBER" -eq 1 ]; then | |
| 75 echo "@@@BUILD_STEP Clobber@@@" | |
| 76 # Sdk key expires, delete android folder. | |
| 77 # crbug.com/145860 | |
| 78 rm -rf ~/.android | |
| 79 rm -rf "${SRC_ROOT}"/out | |
| 80 if [ -e "${SRC_ROOT}"/out ] ; then | |
| 81 echo "Clobber appeared to fail? ${SRC_ROOT}/out still exists." | |
| 82 echo "@@@STEP_WARNINGS@@@" | |
| 83 fi | |
| 84 fi | |
| 85 | |
| 86 # Should be called only after envsetup is done. | |
| 87 bb_run_gclient_hooks | |
| 88 } | |
| 89 | |
| 90 | |
| 91 # Setup goma. Used internally to buildbot_functions.sh. | |
| 92 function bb_setup_goma_internal { | |
| 93 export GOMA_API_KEY_FILE=${GOMA_DIR}/goma.key | |
| 94 export GOMA_COMPILER_PROXY_DAEMON_MODE=true | |
| 95 export GOMA_COMPILER_PROXY_RPC_TIMEOUT_SECS=300 | |
| 96 | |
| 97 echo "Starting goma" | |
| 98 ${GOMA_DIR}/goma_ctl.sh ensure_start | |
| 99 trap bb_stop_goma_internal SIGHUP SIGINT SIGTERM | |
| 100 } | |
| 101 | |
| 102 # Stop goma. | |
| 103 function bb_stop_goma_internal { | |
| 104 echo "Stopping goma" | |
| 105 ${GOMA_DIR}/goma_ctl.sh stop | |
| 106 } | |
| 107 | |
| 108 # $@: make args. | |
| 109 # Use goma if possible; degrades to non-Goma if needed. | |
| 110 function bb_goma_make { | |
| 111 if [ "${GOMA_DIR}" = "" ]; then | |
| 112 make -j${JOBS} "$@" | |
| 113 return | |
| 114 fi | |
| 115 | |
| 116 HOST_CC=$GOMA_DIR/gcc | |
| 117 HOST_CXX=$GOMA_DIR/g++ | |
| 118 TARGET_CC=$(/bin/ls $ANDROID_TOOLCHAIN/*-gcc | head -n1) | |
| 119 TARGET_CXX=$(/bin/ls $ANDROID_TOOLCHAIN/*-g++ | head -n1) | |
| 120 TARGET_CC="$GOMA_DIR/gomacc $TARGET_CC" | |
| 121 TARGET_CXX="$GOMA_DIR/gomacc $TARGET_CXX" | |
| 122 COMMON_JAVAC="$GOMA_DIR/gomacc /usr/bin/javac -J-Xmx512M \ | |
| 123 -target 1.5 -Xmaxerrs 9999999" | |
| 124 | |
| 125 command make \ | |
| 126 -j100 \ | |
| 127 -l20 \ | |
| 128 HOST_CC="$HOST_CC" \ | |
| 129 HOST_CXX="$HOST_CXX" \ | |
| 130 TARGET_CC="$TARGET_CC" \ | |
| 131 TARGET_CXX="$TARGET_CXX" \ | |
| 132 CC.host="$HOST_CC" \ | |
| 133 CXX.host="$HOST_CXX" \ | |
| 134 CC.target="$TARGET_CC" \ | |
| 135 CXX.target="$TARGET_CXX" \ | |
| 136 LINK.target="$TARGET_CXX" \ | |
| 137 COMMON_JAVAC="$COMMON_JAVAC" \ | |
| 138 BUILDTYPE="$BUILDTYPE" \ | |
| 139 "$@" | |
| 140 | |
| 141 local make_exit_code=$? | |
| 142 return $make_exit_code | |
| 143 } | |
| 144 | |
| 145 # Build using ninja. | |
| 146 function bb_goma_ninja { | |
| 147 echo "Using ninja to build." | |
| 148 local TARGET=$1 | |
| 149 ninja -C out/$BUILDTYPE -j120 -l20 $TARGET | |
| 150 } | |
| 151 | |
| 152 # Compile step | |
| 153 function bb_compile { | |
| 154 # This must be named 'compile', not 'Compile', for CQ interaction. | |
| 155 # Talk to maruel for details. | |
| 156 echo "@@@BUILD_STEP compile@@@" | |
| 157 | |
| 158 bb_setup_goma_internal | |
| 159 | |
| 160 BUILDTOOL=$(bb_get_json_prop "$FACTORY_PROPERTIES" buildtool) | |
| 161 if [ $BUILDTOOL = "ninja" ]; then | |
| 162 bb_goma_ninja All | |
| 163 else | |
| 164 bb_goma_make | |
| 165 fi | |
| 166 | |
| 167 bb_stop_goma_internal | |
| 168 } | |
| 169 | |
| 170 # Experimental compile step; does not turn the tree red if it fails. | |
| 171 function bb_compile_experimental { | |
| 172 # Linking DumpRenderTree appears to hang forever? | |
| 173 EXPERIMENTAL_TARGETS="android_experimental" | |
| 174 for target in ${EXPERIMENTAL_TARGETS} ; do | |
| 175 echo "@@@BUILD_STEP Experimental Compile $target @@@" | |
| 176 set +e | |
| 177 if [ $BUILDTOOL = "ninja" ]; then | |
| 178 bb_goma_ninja "${target}" | |
| 179 else | |
| 180 bb_goma_make -k "${target}" | |
| 181 fi | |
| 182 if [ $? -ne 0 ] ; then | |
| 183 echo "@@@STEP_WARNINGS@@@" | |
| 184 fi | |
| 185 set -e | |
| 186 done | |
| 187 } | |
| 188 | |
| 189 # Run tests on an emulator. | |
| 190 function bb_run_tests_emulator { | |
| 191 echo "@@@BUILD_STEP Run Tests on an Emulator@@@" | |
| 192 build/android/run_tests.py -e --xvfb --verbose | |
| 193 } | |
| 194 | |
| 195 # Run tests on an actual device. (Better have one plugged in!) | |
| 196 function bb_run_unit_tests { | |
| 197 python build/android/device_status_check.py | |
| 198 local LOGCAT_DUMP_DIR="$CHROME_SRC/out/logcat" | |
| 199 rm -rf "$LOGCAT_DUMP_DIR" | |
| 200 python build/android/adb_logcat_monitor.py "$LOGCAT_DUMP_DIR" & | |
| 201 | |
| 202 build/android/run_tests.py --xvfb --verbose | |
| 203 | |
| 204 echo "@@@BUILD_STEP Logcat dump@@@" | |
| 205 python build/android/adb_logcat_printer.py "$LOGCAT_DUMP_DIR" | |
| 206 } | |
| 207 | |
| 208 # Run instrumentation test. | |
| 209 # Args: | |
| 210 # $1: TEST_APK. | |
| 211 # $2: EXTRA_FLAGS to be passed to run_instrumentation_tests.py. | |
| 212 function bb_run_instrumentation_test { | |
| 213 local TEST_APK=${1} | |
| 214 local EXTRA_FLAGS=${2} | |
| 215 local INSTRUMENTATION_FLAGS="-vvv" | |
| 216 INSTRUMENTATION_FLAGS+=" --test-apk ${TEST_APK}" | |
| 217 INSTRUMENTATION_FLAGS+=" ${EXTRA_FLAGS}" | |
| 218 build/android/run_instrumentation_tests.py ${INSTRUMENTATION_FLAGS} | |
| 219 } | |
| 220 | |
| 221 # Run content shell instrumentation test on device. | |
| 222 function bb_run_instrumentation_tests { | |
| 223 build/android/adb_install_content_shell | |
| 224 local TEST_APK="content_shell_test/ContentShellTest-debug" | |
| 225 # Use -I to install the test apk only on the first run. | |
| 226 # TODO(bulach): remove the second once we have a Smoke test. | |
| 227 bb_run_instrumentation_test ${TEST_APK} "-I -A Smoke" | |
| 228 bb_run_instrumentation_test ${TEST_APK} "-I -A SmallTest" | |
| 229 bb_run_instrumentation_test ${TEST_APK} "-A MediumTest" | |
| 230 bb_run_instrumentation_test ${TEST_APK} "-A LargeTest" | |
| 231 } | |
| 232 | |
| 233 # Zip and archive a build. | |
| 234 function bb_zip_build { | |
| 235 echo "@@@BUILD_STEP Zip build@@@" | |
| 236 python ../../../../scripts/slave/zip_build.py \ | |
| 237 --src-dir "$SRC_ROOT" \ | |
| 238 --exclude-files "lib.target" \ | |
| 239 --factory-properties "$FACTORY_PROPERTIES" \ | |
| 240 --build-properties "$BUILD_PROPERTIES" | |
| 241 } | |
| 242 | |
| 243 # Download and extract a build. | |
| 244 function bb_extract_build { | |
| 245 echo "@@@BUILD_STEP Download and extract build@@@" | |
| 246 if [[ -z $FACTORY_PROPERTIES || -z $BUILD_PROPERTIES ]]; then | |
| 247 return 1 | |
| 248 fi | |
| 249 | |
| 250 # When extract_build.py downloads an unversioned build it | |
| 251 # issues a warning by exiting with large numbered return code | |
| 252 # When it fails to download it build, it exits with return | |
| 253 # code 1. We disable halt on error mode and return normally | |
| 254 # unless the python tool returns 1. | |
| 255 ( | |
| 256 set +e | |
| 257 python ../../../../scripts/slave/extract_build.py \ | |
| 258 --build-dir "$SRC_ROOT" \ | |
| 259 --build-output-dir "out" \ | |
| 260 --factory-properties "$FACTORY_PROPERTIES" \ | |
| 261 --build-properties "$BUILD_PROPERTIES" | |
| 262 local extract_exit_code=$? | |
| 263 if (( $extract_exit_code > 1 )); then | |
| 264 echo "@@@STEP_WARNINGS@@@" | |
| 265 return | |
| 266 fi | |
| 267 return $extract_exit_code | |
| 268 ) | |
| 269 } | |
| 270 | |
| 271 # Reboot all phones and wait for them to start back up | |
| 272 # Does not break build if a phone fails to restart | |
| 273 function bb_reboot_phones { | |
| 274 echo "@@@BUILD_STEP Rebooting phones@@@" | |
| 275 ( | |
| 276 set +e | |
| 277 cd $CHROME_SRC/build/android/pylib; | |
| 278 for DEVICE in $(adb_get_devices); do | |
| 279 python -c "import android_commands;\ | |
| 280 android_commands.AndroidCommands(device='$DEVICE').Reboot(True)" & | |
| 281 done | |
| 282 wait | |
| 283 ) | |
| 284 } | |
| 285 | |
| 286 # Runs the license checker for the WebView build. | |
| 287 function bb_check_webview_licenses { | |
| 288 echo "@@@BUILD_STEP Check licenses for WebView@@@" | |
| 289 ( | |
| 290 set +e | |
| 291 cd "${SRC_ROOT}" | |
| 292 python android_webview/tools/webview_licenses.py scan | |
| 293 local license_exit_code=$? | |
| 294 if [[ license_exit_code -ne 0 ]]; then | |
| 295 echo "@@@STEP_FAILURE@@@" | |
| 296 fi | |
| 297 return $license_exit_code | |
| 298 ) | |
| 299 } | |
| 300 | |
| 301 # Retrieve a packed json property using python | |
| 302 function bb_get_json_prop { | |
| 303 local JSON="$1" | |
| 304 local PROP="$2" | |
| 305 | |
| 306 python -c "import json; print json.loads('$JSON').get('$PROP')" | |
| 307 } | |
| OLD | NEW |