blob: e194a5e1b82318572961e191fbd4de8557a78f27 [file] [log] [blame]
Brian Harringcb782242011-12-13 19:48:44 -08001#!/bin/bash
2
3# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
David James0b1baf62012-03-15 09:26:23 -07007. "$(dirname "$0")/common.sh" || exit 1
Brian Harringcb782242011-12-13 19:48:44 -08008
9# Script must run inside the chroot
10restart_in_chroot_if_needed "$@"
11
Zdenek Behan05780782012-05-18 03:07:28 +020012assert_not_root_user
13
David James855afb72012-03-14 20:04:59 -070014# Developer-visible flags.
Brian Harringcb782242011-12-13 19:48:44 -080015DEFINE_string board "${DEFAULT_BOARD}" \
16 "The board to build packages for."
Brian Harringcb782242011-12-13 19:48:44 -080017DEFINE_boolean usepkg "${FLAGS_TRUE}" \
18 "Use binary packages to bootstrap when possible."
Thiago Goncales5ad4ca02013-07-12 10:55:11 -070019DEFINE_boolean usepkgonly "${FLAGS_FALSE}" \
20 "Only use binary packages to bootstrap; abort if any are missing."
Brian Harringcb782242011-12-13 19:48:44 -080021DEFINE_boolean noworkon "${FLAGS_FALSE}" \
22 "Don't force-build workon packages."
David James855afb72012-03-14 20:04:59 -070023DEFINE_boolean showoutput "${FLAGS_FALSE}" \
24 "Show all output from parallel_emerge."
25DEFINE_boolean withautotest "${FLAGS_TRUE}" \
26 "Build autotest client code."
Brian Harring17c1fe82012-12-05 21:12:31 -080027DEFINE_boolean fetchonly "${FLAGS_FALSE}" \
28 "Don't build anything, instead only fetch what is needed."
Thiago Goncales5ad4ca02013-07-12 10:55:11 -070029DEFINE_boolean unpackonly "${FLAGS_FALSE}" \
30 "Don't build anything; instead only fetch and unpack what is needed."
Bertrand SIMONNET2f6aaf22015-02-09 15:49:05 -080031DEFINE_boolean withdebugsymbols "${FLAGS_FALSE}" \
Bertrand SIMONNETc7a46e22014-12-11 15:58:11 -080032 "Install the debug symbols for all packages"
Chris Ching4bc95a12016-11-22 13:44:13 -070033DEFINE_boolean withevents "${FLAGS_FALSE}" \
34 "Generate events during parallel_emerge step"
35DEFINE_string eventfile "${DEFAULT_EVENT_FILE}" \
36 "Define the file that event logs will be written."
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -060037DEFINE_boolean withrevdeps "${FLAGS_TRUE}" \
38 "Generate install plan filename if not provided to calc reverse deps."
39DEFINE_string save_install_plan "" \
40 "Save install plan filename for correct reverse dependency calculation."
Thiago Goncales5ad4ca02013-07-12 10:55:11 -070041
42# The --board_root flag specifies the environment variables ROOT and PKGDIR.
43# This allows fetching and emerging of all packages to specified board_root.
44# Note that --board_root will setup the board normally in /build/$BOARD, if it's
45# not setup yet. It also expects the toolchain to already be installed in the
46# board_root. --usepkgonly and --norebuild are required, because building is not
47# supported when board_root is set.
48# enforce this)."
49DEFINE_string board_root "" \
50 "Emerge packages to board_root."
David James855afb72012-03-14 20:04:59 -070051
Mike Frysinger76452ba2012-09-13 22:45:34 -040052FLAGS_HELP="usage: $(basename $0) [flags] [packages]
David James855afb72012-03-14 20:04:59 -070053
54build_packages updates the set of binary packages needed by Chrome OS. It will
55cross compile all packages that have been updated into the given target's root
56and build binary packages as a side-effect. The output packages will be picked
57up by the build_image script to put together a bootable Chrome OS image.
58
Mike Frysinger76452ba2012-09-13 22:45:34 -040059If [packages] are specified, only build those specific packages (and any
60dependencies they might need).
61
David James855afb72012-03-14 20:04:59 -070062For the fastest builds, use --nowithautotest --noworkon.
63"
64show_help_if_requested "$@"
65
66# The following options are advanced options, only available to those willing
67# to read the source code. They are not shown in help output, since they are
68# not needed for the typical developer workflow.
Ryan Cuieb4595f2012-12-17 14:28:42 -080069DEFINE_string accept_licenses "" \
70 "Licenses to append to the accept list."
David James855afb72012-03-14 20:04:59 -070071DEFINE_integer jobs -1 \
72 "How many packages to build in parallel at maximum."
73DEFINE_boolean norebuild "${FLAGS_FALSE}" \
74 "Don't automatically rebuild dependencies."
Mike Frysinger839e82a2012-03-01 14:22:10 -050075DEFINE_boolean skip_chroot_upgrade "${FLAGS_FALSE}" \
76 "Don't run the chroot upgrade automatically; use with care."
David James855afb72012-03-14 20:04:59 -070077DEFINE_boolean skip_toolchain_update "${FLAGS_FALSE}" \
78 "Don't update toolchain automatically."
79DEFINE_boolean withdev "${FLAGS_TRUE}" \
80 "Build useful developer friendly utilities."
81DEFINE_boolean withdebug "${FLAGS_TRUE}" \
82 "Build debug versions of Chromium-OS-specific packages."
83DEFINE_boolean withfactory "${FLAGS_TRUE}" \
84 "Build factory installer."
85DEFINE_boolean withtest "${FLAGS_TRUE}" \
86 "Build packages required for testing."
Hidehiko Abe7a41d342017-03-29 21:19:16 +090087DEFINE_boolean chrome_binhost_only "${FLAGS_FALSE}" \
David James0ae653d2013-07-03 15:59:29 -070088 "Only fetch packages from the Chrome binhost."
Aviv Keshet8aa379b2016-02-29 10:00:05 -080089DEFINE_boolean buildretry "${FLAGS_TRUE}" \
90 "Retry failed packages."
Brian Harringcb782242011-12-13 19:48:44 -080091
David James17c622a2012-03-07 09:34:08 -080092# The --reuse_pkgs_from_local_boards flag tells Portage to share binary
93# packages between boards that are built locally, so that the total time
94# required to build several boards is reduced. This flag is only useful
95# when you are not able to use remote binary packages, since remote binary
96# packages are usually more up to date than anything you have locally.
Hidehiko Abe7a41d342017-03-29 21:19:16 +090097DEFINE_boolean reuse_pkgs_from_local_boards "${FLAGS_FALSE}" \
David James17c622a2012-03-07 09:34:08 -080098 "Bootstrap from local packages instead of remote packages."
99
Hidehiko Abe7a41d342017-03-29 21:19:16 +0900100# --run_goma option is designed to be used on bots.
101# If you're trying to build pacakges with goma in your local dev env, this is
102# *not* the option you're looking for. Please see comments below.
103# This option; 1) starts goma, 2) builds packages (expecting that goma is
104# used), then 3) stops goma explicitly.
105# 3) is a request from the goma team, so that stats/logs can be taken.
106# Note: GOMA_DIR and GOMA_SERVICE_ACCOUNT_JSON_FILE are expected to be passed
107# via env var.
108#
109# In local dev env cases, compiler_proxy is expected to keep running.
110# In such a case;
111# $ python ${GOMA_DIR}/goma_ctl.py ensure_start
112# $ ./build_packages (... and options without --run_goma ...)
113# is an expected commandline sequence. If you set --run_goma flag while
114# compiler_proxy is already running, the existing compiler_proxy will be
115# stopped.
116DEFINE_boolean run_goma "${FLAGS_FALSE}" \
117 "If set to true, (re)starts goma, builds packages, and then stops goma."
118
Brian Harringcb782242011-12-13 19:48:44 -0800119# Parse command line
Brian Harringcb782242011-12-13 19:48:44 -0800120FLAGS "$@" || exit 1
121eval set -- "${FLAGS_ARGV}"
Brian Harringcb782242011-12-13 19:48:44 -0800122
123# Die on any errors.
Brian Harring7f175a52012-03-02 05:37:00 -0800124switch_to_strict_mode
Brian Harringcb782242011-12-13 19:48:44 -0800125
126# Right now build_packages has to be run from scripts/
127. ${SRC_ROOT}/third_party/chromiumos-overlay/chromeos/config/chromeos_version.sh
128
129if [[ -z "${FLAGS_board}" ]]; then
130 echo "Error: --board is required."
131 exit 1
132fi
133
Mike Frysinger4114c792012-09-13 22:33:12 -0400134# Before we can run any tools, we need to update chroot or setup_board.
135UPDATE_ARGS=()
Ryan Cuieb4595f2012-12-17 14:28:42 -0800136if [[ -n ${FLAGS_accept_licenses} ]]; then
137 UPDATE_ARGS+=( --accept_licenses "${FLAGS_accept_licenses}" )
138fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400139if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then
140 UPDATE_ARGS+=( --usepkg )
141else
142 UPDATE_ARGS+=( --nousepkg )
143fi
144if [[ "${FLAGS_jobs}" -ne -1 ]]; then
145 UPDATE_ARGS+=( --jobs=${FLAGS_jobs} )
146fi
David James0ae653d2013-07-03 15:59:29 -0700147if [ "${FLAGS_chrome_binhost_only}" -eq "${FLAGS_TRUE}" ]; then
148 UPDATE_ARGS+=( --chrome_binhost_only )
149fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400150if [ "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ]; then
151 UPDATE_ARGS+=( --reuse_pkgs_from_local_boards )
152fi
153if [ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_TRUE}" ]; then
154 UPDATE_ARGS+=( --skip_toolchain_update )
155fi
156if [ "${FLAGS_skip_chroot_upgrade}" -eq "${FLAGS_TRUE}" ]; then
157 UPDATE_ARGS+=( --skip_chroot_upgrade )
158fi
Thiago Goncales5ad4ca02013-07-12 10:55:11 -0700159if [[ ${FLAGS_unpackonly} -eq ${FLAGS_TRUE} ]]; then
160 UPDATE_ARGS+=( --skip_board_pkg_init )
161fi
Bertrand SIMONNET10ede912014-10-09 16:21:13 -0700162if [[ -n ${FLAGS_board_root} ]]; then
163 UPDATE_ARGS+=( --board_root "${FLAGS_board_root}" )
164fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400165
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600166if [[ -z "${FLAGS_save_install_plan}" ]]; then
167 if [[ "${FLAGS_withrevdeps}" -eq "${FLAGS_TRUE}" ]]; then
168 # No explicit install plan filename (cbuildbot generated)
169 # so generate a temporary filename and reset the flag.
170 FLAGS_save_install_plan=$(mktemp)
171 fi
172fi
173info "saving install plan to ${FLAGS_save_install_plan}"
174if [[ -n "${FLAGS_save_install_plan}" ]]; then
175 UPDATE_ARGS+=( --save_install_plan="${FLAGS_save_install_plan}" )
176fi
177
Mike Frysinger4114c792012-09-13 22:33:12 -0400178"${SCRIPTS_DIR}"/setup_board --quiet --board=${FLAGS_board} "${UPDATE_ARGS[@]}"
179
Chris Masonebbccc242014-02-08 16:23:53 -0800180sudo_clear_shadow_locks "/build/${FLAGS_board}"
181
Mike Frysinger4114c792012-09-13 22:33:12 -0400182# Setup all the emerge command/flags.
David James886f2c32014-02-26 20:38:04 -0800183EMERGE_FLAGS=( -uDNv --backtrack=30 --select --newrepo )
Mike Frysinger4114c792012-09-13 22:33:12 -0400184
Bertrand SIMONNET4dda4f52015-03-19 13:40:58 -0700185EMERGE_CMD=(
186 "${CHROMITE_BIN}/parallel_emerge"
187 --board=${FLAGS_board}
188)
189
Brian Harring3d01db22012-12-15 21:09:03 -0800190if [[ "${FLAGS_fetchonly}" -eq "${FLAGS_TRUE}" ]]; then
Brian Harring17c1fe82012-12-05 21:12:31 -0800191 EMERGE_CMD+=( --fetchonly )
192fi
Aviv Keshet8aa379b2016-02-29 10:00:05 -0800193if [[ "${FLAGS_unpackonly}" -eq "${FLAGS_TRUE}" ]]; then
Thiago Goncales5ad4ca02013-07-12 10:55:11 -0700194 EMERGE_CMD+=( --unpackonly )
195fi
Aviv Keshet8aa379b2016-02-29 10:00:05 -0800196if [[ "${FLAGS_buildretry}" -eq "${FLAGS_FALSE}" ]]; then
197 EMERGE_CMD+=( --retries=0 )
198fi
Brian Harring17c1fe82012-12-05 21:12:31 -0800199
Mike Frysinger4114c792012-09-13 22:33:12 -0400200EMERGE_CMD+=( ${EXTRA_BOARD_FLAGS} )
Brian Harringcb782242011-12-13 19:48:44 -0800201
David James17c622a2012-03-07 09:34:08 -0800202if [[ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ||
Thiago Goncales5ad4ca02013-07-12 10:55:11 -0700203 "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ||
204 "${FLAGS_usepkgonly}" -eq "${FLAGS_TRUE}" ]]; then
Brian Harringcb782242011-12-13 19:48:44 -0800205 # Use binary packages. Include all build-time dependencies,
206 # so as to avoid unnecessary differences between source
207 # and binary builds.
Thiago Goncales5ad4ca02013-07-12 10:55:11 -0700208 EMERGE_FLAGS+=( --getbinpkg --with-bdeps y )
209 if [[ ${FLAGS_usepkgonly} -eq ${FLAGS_TRUE} ]]; then
210 EMERGE_FLAGS+=( --usepkgonly )
211 else
212 EMERGE_FLAGS+=( --usepkg )
213 fi
Brian Harringcb782242011-12-13 19:48:44 -0800214fi
215
216if [[ "${FLAGS_jobs}" -ne -1 ]]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400217 EMERGE_FLAGS+=( --jobs=${FLAGS_jobs} )
218fi
219
220if [[ "${FLAGS_norebuild}" -eq "${FLAGS_FALSE}" ]]; then
221 EMERGE_FLAGS+=( --rebuild-if-unbuilt )
222fi
Bertrand SIMONNET4dda4f52015-03-19 13:40:58 -0700223if [[ "${FLAGS_showoutput}" -eq "${FLAGS_TRUE}" ]]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400224 EMERGE_FLAGS+=( --show-output )
Brian Harringcb782242011-12-13 19:48:44 -0800225fi
226
227if [[ "${FLAGS_withdebug}" -eq "${FLAGS_FALSE}" ]]; then
228 export USE="${USE} -cros-debug"
229fi
230
Chris Ching4bc95a12016-11-22 13:44:13 -0700231# TODO Handle case where passed default value, but events not enabled
232if [[ "${FLAGS_eventfile}" != "${DEFAULT_EVENT_FILE}" ]]; then
233 FLAGS_withevents="${FLAGS_TRUE}"
234fi
235
236if [[ "${FLAGS_withevents}" -eq "${FLAGS_TRUE}" ]]; then
237 mkdir -p "$(dirname $FLAGS_eventfile)"
238 EMERGE_FLAGS+=( "--eventlogfile=${FLAGS_eventfile}" )
239fi
240
Mike Frysinger4114c792012-09-13 22:33:12 -0400241# Figure out which packages we should be building.
Mike Frysinger76452ba2012-09-13 22:45:34 -0400242PACKAGES=( "$@" )
Daniel Wangaf4d0012015-07-17 11:52:05 -0700243FORCE_LOCAL_BUILD_PKGS=()
Mike Frysinger76452ba2012-09-13 22:45:34 -0400244if [[ $# -eq 0 ]]; then
Mike Frysinger22621952014-04-01 17:41:20 -0400245 PACKAGES=( virtual/target-os )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400246 if [[ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]]; then
Mike Frysingerde399282014-04-15 18:26:04 -0400247 PACKAGES+=( virtual/target-os-dev )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400248 fi
249 if [[ "${FLAGS_withfactory}" -eq "${FLAGS_TRUE}" ]]; then
Hung-Te Lin9b43ced2016-01-14 20:29:47 +0800250 PACKAGES+=( virtual/target-os-factory )
251 PACKAGES+=( virtual/target-os-factory-shim )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400252 fi
253 if [[ "${FLAGS_withtest}" -eq "${FLAGS_TRUE}" ]]; then
Mike Frysinger52669432014-05-05 14:34:09 -0400254 PACKAGES+=( virtual/target-os-test )
Daniel Wangaf4d0012015-07-17 11:52:05 -0700255 # chromeos-ssh-testkeys may generate ssh keys if the right USE flag is set.
256 # We force rebuilding this package from source every time, so that
257 # consecutive builds don't share ssh keys.
258 FORCE_LOCAL_BUILD_PKGS+=( chromeos-base/chromeos-ssh-testkeys )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400259 fi
260 if [[ "${FLAGS_withautotest}" -eq "${FLAGS_TRUE}" ]]; then
261 PACKAGES+=( chromeos-base/autotest-all )
262 fi
Brian Harringcb782242011-12-13 19:48:44 -0800263fi
264
265# Verify that all packages can be emerged from scratch, without any
266# backtracking. Only print the output if this step fails.
Mike Frysinger76452ba2012-09-13 22:45:34 -0400267info "Checking package dependencies are correct: ${PACKAGES[*]}"
David Jamesab9ca212012-11-06 11:06:07 -0800268if ! OUTPUT=$(emerge-${FLAGS_board} -pe --backtrack=0 \
269 "${PACKAGES[@]}" 2>&1); then
Brian Harringcb782242011-12-13 19:48:44 -0800270 printf "%s\n" "${OUTPUT}"
Brian Harring7f175a52012-03-02 05:37:00 -0800271 die_notrace "emerge detected broken ebuilds. See error message above."
Brian Harringcb782242011-12-13 19:48:44 -0800272fi
273
Mike Frysinger4114c792012-09-13 22:33:12 -0400274# Build cros_workon packages when they are changed.
275CROS_WORKON_PKGS=()
276if [ "${FLAGS_noworkon}" -eq "${FLAGS_FALSE}" ]; then
277 LIST_MODIFIED_PACKAGES="${CHROMITE_BIN}/cros_list_modified_packages"
Jason D. Clinton321e2f82017-08-09 16:21:23 -0600278 MODIFIED_PACKAGES=( $("${LIST_MODIFIED_PACKAGES}" --board=${FLAGS_board}) )
Gregory Meinke7851ece2018-05-09 13:34:06 -0600279 info "cros_workon modified packages '${MODIFIED_PACKAGES[*]}' detected"
Jason D. Clinton321e2f82017-08-09 16:21:23 -0600280 CROS_WORKON_PKGS+=( "${MODIFIED_PACKAGES[@]}" )
Mike Frysinger4114c792012-09-13 22:33:12 -0400281
David James4941c6b2014-02-03 16:24:59 -0800282 # TODO(anush): Make chrome a fake cros-workon package.
283 if [[ -n "${CHROME_ORIGIN}" ]]; then
284 CROS_WORKON_PKGS+=( chromeos-base/chromeos-chrome )
285 fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400286fi
287
Daniel Wangaf4d0012015-07-17 11:52:05 -0700288# cros_workon packages always have to be rebuilt.
Daniel Wang491f42a2015-08-20 12:29:59 -0700289FORCE_LOCAL_BUILD_PKGS+=( "${CROS_WORKON_PKGS[@]}" )
Daniel Wangaf4d0012015-07-17 11:52:05 -0700290
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600291if [[ -n "${FLAGS_board_root}" ]]; then
292 export ROOT="${FLAGS_board_root}"
293 export PORTAGE_CONFIGROOT="${ROOT}"
294 export SYSROOT="${ROOT}"
295 export PKGDIR="${ROOT}"/packages
296fi
297
298# Temporarily modify the emerge flags so we can calculate the revdeps
299# on the modified packages.
300SIM_EMERGE_FLAGS=( "${EMERGE_FLAGS[@]}" )
301if [[ ${#PACKAGES[@]} -gt 0 ]]; then
302 SIM_EMERGE_FLAGS+=(
303 --reinstall-atoms="${PACKAGES[*]}"
304 --usepkg-exclude="${PACKAGES[*]}"
305 )
306fi
307
308sudo -E "${EMERGE_CMD[@]}" "${SIM_EMERGE_FLAGS[@]}" --pretend "${PACKAGES[@]}"
309
310MOD_PKGS=()
311if [[ -n "${FLAGS_save_install_plan}" ]]; then
312 [ -f ${FLAGS_save_install_plan} ] \
313 || die "${FLAGS_save_install_plan} does not exist"
314 readarray NEW_DEPS < ${FLAGS_save_install_plan}
315 if [[ ${#NEW_DEPS[@]} -gt 0 ]]; then
316 # Convert specific versions into base package names
317 MOD_PKGS+=( $(\
318 equery-${FLAGS_board} list -p -o --format='$category/$name' \
319 ${NEW_DEPS[*]}) )
320 fi
321 FORCE_LOCAL_BUILD_PKGS+=( ${MOD_PKGS[@]} )
322fi
323
324if [[ ${#MOD_PKGS[@]} -gt 0 ]]; then
325 info "calculating reverse dependencies on packages: ${MOD_PKGS[*]}"
326 REV_DEPS=( $(\
327 equery-${FLAGS_board} -q depends --indirect ${MOD_PKGS[@]} |\
328 awk '{print $1}' | grep -v ^virtual/ | sort -u) )
329 if [[ ${#REV_DEPS[@]} -gt 0 ]]; then
330 # Convert specific versions into base package names
331 RMOD_PKGS=( $(\
332 equery-${FLAGS_board} -q list -p -o --format='$category/$name' \
333 ${REV_DEPS[*]}) )
334 # Remove Chrome as rebuilding it is expensive and almost never makes sense
335 RMOD_PKGS=( $( echo "${RMOD_PKGS[*]}" |\
336 sed -e 's/chromeos-base\/chromeos-chrome[^ ]*//' ) )
337 info "final reverse dependencies that will be rebuilt: ${RMOD_PKGS[*]}"
338 FORCE_LOCAL_BUILD_PKGS+=( ${RMOD_PKGS[@]} )
339 fi
340fi
341
Daniel Wangaf4d0012015-07-17 11:52:05 -0700342if [[ ${#FORCE_LOCAL_BUILD_PKGS[@]} -gt 0 ]]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400343 EMERGE_FLAGS+=(
Daniel Wangaf4d0012015-07-17 11:52:05 -0700344 --reinstall-atoms="${FORCE_LOCAL_BUILD_PKGS[*]}"
345 --usepkg-exclude="${FORCE_LOCAL_BUILD_PKGS[*]}"
Mike Frysinger4114c792012-09-13 22:33:12 -0400346 )
David James710a7d12011-12-21 15:57:02 -0800347fi
Matt Tennant298f61a2012-06-25 21:54:33 -0700348
349# Prepare tmp file to capture emerge output from tee.
Hidehiko Abed9d6bfd2017-04-28 17:24:21 +0900350tmpfile=$(mktemp --tmpdir tmp.build_packages-emerge.XXXXXX)
Matt Tennant298f61a2012-06-25 21:54:33 -0700351trap "rm -f '${tmpfile}'" EXIT
352
Mike Frysinger76452ba2012-09-13 22:45:34 -0400353info "Merging board packages now"
Matt Tennant298f61a2012-06-25 21:54:33 -0700354(
Hidehiko Abe7a41d342017-03-29 21:19:16 +0900355 # Support goma on bots. This has to run in subshell, otherwise EXIT trap
356 # handler is overwritten.
357 if [[ "${FLAGS_run_goma}" -eq "${FLAGS_TRUE}" ]]; then
358 info "Starting goma compiler_proxy."
359 goma_ctl="${GOMA_DIR:-${HOME}/goma}/goma_ctl.py"
360 "${goma_ctl}" restart
Hidehiko Abe2aa41ae2017-05-16 18:31:00 +0900361 trap "'${goma_ctl}' stop" EXIT
Hidehiko Abe7a41d342017-03-29 21:19:16 +0900362 fi
363
Matt Tennant298f61a2012-06-25 21:54:33 -0700364 set -o pipefail
Mike Frysinger4114c792012-09-13 22:33:12 -0400365 sudo -E "${EMERGE_CMD[@]}" "${EMERGE_FLAGS[@]}" "${PACKAGES[@]}" | \
Matt Tennant298f61a2012-06-25 21:54:33 -0700366 tee "${tmpfile}"
367)
368
369# Extract total package count from emerge output.
370package_count=$(awk '$0 ~ /^Total: [0-9]+ packages/ { print $2 }' "${tmpfile}")
371rm "${tmpfile}"
372trap - EXIT
Brian Harringcb782242011-12-13 19:48:44 -0800373
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600374if [[ -n "${FLAGS_save_install_plan}" ]]; then
375 sudo -E rm ${FLAGS_save_install_plan}
376fi
377
Brian Harringcb782242011-12-13 19:48:44 -0800378echo "Builds complete"
Bertrand SIMONNETc7a46e22014-12-11 15:58:11 -0800379
380if [[ ${FLAGS_withdebugsymbols} -eq ${FLAGS_TRUE} ]]; then
381 info "fetching the debug symbols"
Mike Frysinger66accd22017-09-13 03:50:30 -0400382 sudo -E "${CHROMITE_BIN}/cros_install_debug_syms" \
Bertrand SIMONNETc7a46e22014-12-11 15:58:11 -0800383 "--board=${FLAGS_board}" "--all"
384fi
385
Matt Tennant298f61a2012-06-25 21:54:33 -0700386EXTRA_COMMAND_STATS[package_count]=${package_count}
387command_completed
Brian Harringcb782242011-12-13 19:48:44 -0800388echo "Done"