summaryrefslogtreecommitdiffstats
path: root/build/android/buildbot_functions.sh
blob: 2f64af23e2e2843bae1ac339a2095bad1542759e (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
#!/bin/bash
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Bash functions used by buildbot annotator scripts for the android
# build of chromium.  Executing this script should not perform actions
# other than setting variables and defining of functions.

# Number of jobs on the compile line; e.g.  make -j"${JOBS}"
JOBS="${JOBS:-4}"

# Clobber build?  Overridden by bots with BUILDBOT_CLOBBER.
NEED_CLOBBER="${NEED_CLOBBER:-0}"


# Parse named arguments passed into the annotator script
# and assign them global variable names.
function bb_parse_args {
  while [[ $1 ]]; do
    case "$1" in
      --factory-properties=*)
        FACTORY_PROPERTIES="$(echo "$1" | sed 's/^[^=]*=//')"
        ;;
      --build-properties=*)
        BUILD_PROPERTIES="$(echo "$1" | sed 's/^[^=]*=//')"
        ;;
      *)
        echo "@@@STEP_WARNINGS@@@"
        echo "Warning, unparsed input argument: '$1'"
        ;;
    esac
    shift
  done
}


# Setup environment for Android build.
# Called from bb_baseline_setup.
# Moved to top of file so it is easier to find.
function bb_setup_environment {
  export ANDROID_SDK_ROOT=/usr/local/google/android-sdk-linux
  export ANDROID_NDK_ROOT=/usr/local/google/android-ndk-r7
}

# Install the build deps by running
# build/install-build-deps-android-sdk.sh.  This may update local tools.
# $1: source root.
function bb_install_build_deps {
  echo "@@@BUILD_STEP install build deps android@@@"
  local script="$1/build/install-build-deps-android-sdk.sh"
  if [[ -f "$script" ]]; then
    "$script"
  else
    echo "@@@STEP_WARNINGS@@@"
    echo "Cannot find $script; why?"
  fi
}

# Function to force-green a bot.
function bb_force_bot_green_and_exit {
  echo "@@@BUILD_STEP Bot forced green.@@@"
  exit 0
}

function bb_run_gclient_hooks {
  echo "@@@BUILD_STEP runhooks android@@@"
  gclient runhooks
}

# Basic setup for all bots to run after a source tree checkout.
# Args:
#   $1: source root.
#   $2 and beyond: key value pairs which are parsed by bb_parse_args.
function bb_baseline_setup {
  echo "@@@BUILD_STEP Environment setup@@@"
  SRC_ROOT="$1"
  # Remove SRC_ROOT param
  shift

  bb_parse_args "$@"

  if [ ! -d "${SRC_ROOT}" ] ; then
    echo "Please specify a valid source root directory as an arg"
    echo '@@@STEP_FAILURE@@@'
    return 1
  fi
  cd $SRC_ROOT

  if [ ! -f build/android/envsetup.sh ] ; then
    echo "No envsetup.sh"
    echo "@@@STEP_FAILURE@@@"
    return 1
  fi

  bb_setup_environment

  for mandatory_directory in $(dirname "${ANDROID_SDK_ROOT}") \
    $(dirname "${ANDROID_NDK_ROOT}") ; do
    if [[ ! -d "${mandatory_directory}" ]]; then
      echo "Directory ${mandatory_directory} does not exist."
      echo "Build cannot continue."
      echo "@@@STEP_FAILURE@@@"
      return 1
    fi
  done

  if [ ! "$BUILDBOT_CLOBBER" = "" ]; then
    NEED_CLOBBER=1
  fi

  # Setting up a new bot?  Must do this before envsetup.sh
  if [ ! -d "${ANDROID_NDK_ROOT}" ] ; then
    bb_install_build_deps $SRC_ROOT
  fi

  . build/android/envsetup.sh

  if [ "$NEED_CLOBBER" -eq 1 ]; then
    echo "@@@BUILD_STEP Clobber@@@"
    rm -rf "${SRC_ROOT}"/out
    if [ -e "${SRC_ROOT}"/out ] ; then
      echo "Clobber appeared to fail?  ${SRC_ROOT}/out still exists."
      echo "@@@STEP_WARNINGS@@@"
    fi
  fi

  # Should be called only after envsetup is done.
  bb_run_gclient_hooks
}


# Setup goma.  Used internally to buildbot_functions.sh.
function bb_setup_goma_internal {

  # Quick bail if I messed things up and can't wait for the CQ to
  # flush out.
  # TODO(jrg): remove this condition when things are
  # proven stable (4/1/12 or so).
  if [ -f /usr/local/google/DISABLE_GOMA ]; then
    echo "@@@STEP_WARNINGS@@@"
    echo "Goma disabled with a local file"
    return
  fi

  goma_dir=${goma_dir:-/b/build/goma}
  if [ -f ${goma_dir}/goma.key ]; then
    export GOMA_API_KEY_FILE=${GOMA_DIR}/goma.key
  fi
  local goma_ctl=$(which goma_ctl.sh)
  if [ "${goma_ctl}" != "" ]; then
    local goma_dir=$(dirname ${goma_ctl})
  fi

  if [ ! -f ${goma_dir}/goma_ctl.sh ]; then
    echo "@@@STEP_WARNINGS@@@"
    echo "Goma not found on this machine; defaulting to make"
    return
  fi
  export GOMA_DIR=${goma_dir}
  echo "GOMA_DIR: " $GOMA_DIR

  export GOMA_COMPILER_PROXY_DAEMON_MODE=true
  export GOMA_COMPILER_PROXY_RPC_TIMEOUT_SECS=300
  export PATH=$GOMA_DIR:$PATH

  echo "Starting goma"
  if [ "$NEED_CLOBBER" -eq 1 ]; then
    ${GOMA_DIR}/goma_ctl.sh restart
  else
    ${GOMA_DIR}/goma_ctl.sh ensure_start
  fi
  trap bb_stop_goma_internal SIGHUP SIGINT SIGTERM
}

# Stop goma.
function bb_stop_goma_internal {
  echo "Stopping goma"
  ${GOMA_DIR}/goma_ctl.sh stop
}

# $@: make args.
# Use goma if possible; degrades to non-Goma if needed.
function bb_goma_make {
  bb_setup_goma_internal

  if [ "${GOMA_DIR}" = "" ]; then
    make -j${JOBS} "$@"
    return
  fi

  HOST_CC=$GOMA_DIR/gcc
  HOST_CXX=$GOMA_DIR/g++
  TARGET_CC=$(/bin/ls $ANDROID_TOOLCHAIN/*-gcc | head -n1)
  TARGET_CXX=$(/bin/ls $ANDROID_TOOLCHAIN/*-g++ | head -n1)
  TARGET_CC="$GOMA_DIR/gomacc $TARGET_CC"
  TARGET_CXX="$GOMA_DIR/gomacc $TARGET_CXX"
  COMMON_JAVAC="$GOMA_DIR/gomacc /usr/bin/javac -J-Xmx512M \
    -target 1.5 -Xmaxerrs 9999999"

  command make \
    -j100 \
    -l20 \
    HOST_CC="$HOST_CC" \
    HOST_CXX="$HOST_CXX" \
    TARGET_CC="$TARGET_CC" \
    TARGET_CXX="$TARGET_CXX" \
    CC.host="$HOST_CC" \
    CXX.host="$HOST_CXX" \
    CC.target="$TARGET_CC" \
    CXX.target="$TARGET_CXX" \
    LINK.target="$TARGET_CXX" \
    COMMON_JAVAC="$COMMON_JAVAC" \
    "$@"

  local make_exit_status=$?
  bb_stop_goma_internal
  return $make_exit_status
}

# Compile step
function bb_compile {
  # This must be named 'compile', not 'Compile', for CQ interaction.
  # Talk to maruel for details.
  echo "@@@BUILD_STEP compile@@@"
  bb_goma_make
}

# Experimental compile step; does not turn the tree red if it fails.
function bb_compile_experimental {
  # Linking DumpRenderTree appears to hang forever?
  EXPERIMENTAL_TARGETS="android_experimental"
  for target in ${EXPERIMENTAL_TARGETS} ; do
    echo "@@@BUILD_STEP Experimental Compile $target @@@"
    set +e
    bb_goma_make -k "${target}"
    if [ $? -ne 0 ] ; then
      echo "@@@STEP_WARNINGS@@@"
    fi
    set -e
  done
}

# Run tests on an emulator.
function bb_run_tests_emulator {
  echo "@@@BUILD_STEP Run Tests on an Emulator@@@"
  build/android/run_tests.py -e --xvfb --verbose
}

# Run tests on an actual device.  (Better have one plugged in!)
function bb_run_tests {
  python build/android/device_status_check.py
  echo "@@@BUILD_STEP Run Tests on actual hardware@@@"
  build/android/run_tests.py --xvfb --verbose
}

# Run simple content shell test on device.
function bb_run_content_shell_test {
  echo "@@@BUILD_STEP Run simple content shell test on actual hardware@@@"
  content/shell/android/simple_content_shell_test.sh \
    "${SRC_ROOT}"/out/Release/content_shell/ContentShell-debug.apk
}

# Run content shell instrumentation test on device.
function bb_run_content_shell_instrumentation_test {
  echo "@@@BUILD_STEP Run content shell instrumentation test on actual "\
       "hardware@@@"
  build/android/adb_install_content_shell
  build/android/run_instrumentation_tests.py -I \
      --test-apk content_shell_test/ContentShellTest-debug -vvv
}

# Zip and archive a build.
function bb_zip_build {
  echo "@@@BUILD_STEP Zip build@@@"
  python ../../../../scripts/slave/zip_build.py \
    --src-dir "$SRC_ROOT" \
    --exclude-files "lib.target" \
    --factory-properties "$FACTORY_PROPERTIES" \
    --build-properties "$BUILD_PROPERTIES"
}

# Download and extract a build.
function bb_extract_build {
  echo "@@@BUILD_STEP Download and extract build@@@"
  if [[ -z $FACTORY_PROPERTIES || -z $BUILD_PROPERTIES ]]; then
    return 1
  fi

  # When extract_build.py downloads an unversioned build it
  # issues a warning by exiting with large numbered return code
  # When it fails to download it build, it exits with return
  # code 1.  We disable halt on error mode and return normally
  # unless the python tool returns 1.
  (
  set +e
  python ../../../../scripts/slave/extract_build.py \
    --build-dir "$SRC_ROOT" \
    --build-output-dir "out" \
    --target Release \
    --factory-properties "$FACTORY_PROPERTIES" \
    --build-properties "$BUILD_PROPERTIES"
  extract_exitcode=$?
  if (( $extract_exitcode > 1 )); then
    echo "@@@STEP_WARNINGS@@@"
    return
  fi
  return $extract_exitcode
  )
}