blob: 0184c017d230410fc5e17b32fb04f7aa115acdd5 [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}" \
Gregory Meinke0766df42018-08-23 11:36:12 -060038 "Calculate reverse dependencies on changed ebuilds."
Thiago Goncales5ad4ca02013-07-12 10:55:11 -070039
40# The --board_root flag specifies the environment variables ROOT and PKGDIR.
41# This allows fetching and emerging of all packages to specified board_root.
42# Note that --board_root will setup the board normally in /build/$BOARD, if it's
43# not setup yet. It also expects the toolchain to already be installed in the
44# board_root. --usepkgonly and --norebuild are required, because building is not
45# supported when board_root is set.
46# enforce this)."
47DEFINE_string board_root "" \
48 "Emerge packages to board_root."
David James855afb72012-03-14 20:04:59 -070049
Mike Frysinger76452ba2012-09-13 22:45:34 -040050FLAGS_HELP="usage: $(basename $0) [flags] [packages]
David James855afb72012-03-14 20:04:59 -070051
52build_packages updates the set of binary packages needed by Chrome OS. It will
53cross compile all packages that have been updated into the given target's root
54and build binary packages as a side-effect. The output packages will be picked
55up by the build_image script to put together a bootable Chrome OS image.
56
Mike Frysinger76452ba2012-09-13 22:45:34 -040057If [packages] are specified, only build those specific packages (and any
58dependencies they might need).
59
David James855afb72012-03-14 20:04:59 -070060For the fastest builds, use --nowithautotest --noworkon.
61"
62show_help_if_requested "$@"
63
64# The following options are advanced options, only available to those willing
65# to read the source code. They are not shown in help output, since they are
66# not needed for the typical developer workflow.
Ryan Cuieb4595f2012-12-17 14:28:42 -080067DEFINE_string accept_licenses "" \
68 "Licenses to append to the accept list."
David James855afb72012-03-14 20:04:59 -070069DEFINE_integer jobs -1 \
70 "How many packages to build in parallel at maximum."
71DEFINE_boolean norebuild "${FLAGS_FALSE}" \
72 "Don't automatically rebuild dependencies."
Mike Frysinger839e82a2012-03-01 14:22:10 -050073DEFINE_boolean skip_chroot_upgrade "${FLAGS_FALSE}" \
74 "Don't run the chroot upgrade automatically; use with care."
David James855afb72012-03-14 20:04:59 -070075DEFINE_boolean skip_toolchain_update "${FLAGS_FALSE}" \
76 "Don't update toolchain automatically."
77DEFINE_boolean withdev "${FLAGS_TRUE}" \
78 "Build useful developer friendly utilities."
79DEFINE_boolean withdebug "${FLAGS_TRUE}" \
80 "Build debug versions of Chromium-OS-specific packages."
81DEFINE_boolean withfactory "${FLAGS_TRUE}" \
82 "Build factory installer."
83DEFINE_boolean withtest "${FLAGS_TRUE}" \
84 "Build packages required for testing."
Hidehiko Abe7a41d342017-03-29 21:19:16 +090085DEFINE_boolean chrome_binhost_only "${FLAGS_FALSE}" \
David James0ae653d2013-07-03 15:59:29 -070086 "Only fetch packages from the Chrome binhost."
Aviv Keshet8aa379b2016-02-29 10:00:05 -080087DEFINE_boolean buildretry "${FLAGS_TRUE}" \
88 "Retry failed packages."
Brian Harringcb782242011-12-13 19:48:44 -080089
David James17c622a2012-03-07 09:34:08 -080090# The --reuse_pkgs_from_local_boards flag tells Portage to share binary
91# packages between boards that are built locally, so that the total time
92# required to build several boards is reduced. This flag is only useful
93# when you are not able to use remote binary packages, since remote binary
94# packages are usually more up to date than anything you have locally.
Hidehiko Abe7a41d342017-03-29 21:19:16 +090095DEFINE_boolean reuse_pkgs_from_local_boards "${FLAGS_FALSE}" \
David James17c622a2012-03-07 09:34:08 -080096 "Bootstrap from local packages instead of remote packages."
97
Hidehiko Abe7a41d342017-03-29 21:19:16 +090098# --run_goma option is designed to be used on bots.
99# If you're trying to build pacakges with goma in your local dev env, this is
100# *not* the option you're looking for. Please see comments below.
101# This option; 1) starts goma, 2) builds packages (expecting that goma is
102# used), then 3) stops goma explicitly.
103# 3) is a request from the goma team, so that stats/logs can be taken.
104# Note: GOMA_DIR and GOMA_SERVICE_ACCOUNT_JSON_FILE are expected to be passed
105# via env var.
106#
107# In local dev env cases, compiler_proxy is expected to keep running.
108# In such a case;
109# $ python ${GOMA_DIR}/goma_ctl.py ensure_start
110# $ ./build_packages (... and options without --run_goma ...)
111# is an expected commandline sequence. If you set --run_goma flag while
112# compiler_proxy is already running, the existing compiler_proxy will be
113# stopped.
114DEFINE_boolean run_goma "${FLAGS_FALSE}" \
115 "If set to true, (re)starts goma, builds packages, and then stops goma."
116
Brian Harringcb782242011-12-13 19:48:44 -0800117# Parse command line
Brian Harringcb782242011-12-13 19:48:44 -0800118FLAGS "$@" || exit 1
119eval set -- "${FLAGS_ARGV}"
Brian Harringcb782242011-12-13 19:48:44 -0800120
121# Die on any errors.
Brian Harring7f175a52012-03-02 05:37:00 -0800122switch_to_strict_mode
Brian Harringcb782242011-12-13 19:48:44 -0800123
124# Right now build_packages has to be run from scripts/
125. ${SRC_ROOT}/third_party/chromiumos-overlay/chromeos/config/chromeos_version.sh
126
127if [[ -z "${FLAGS_board}" ]]; then
128 echo "Error: --board is required."
129 exit 1
130fi
131
Mike Frysinger4114c792012-09-13 22:33:12 -0400132# Before we can run any tools, we need to update chroot or setup_board.
133UPDATE_ARGS=()
Ryan Cuieb4595f2012-12-17 14:28:42 -0800134if [[ -n ${FLAGS_accept_licenses} ]]; then
135 UPDATE_ARGS+=( --accept_licenses "${FLAGS_accept_licenses}" )
136fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400137if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then
138 UPDATE_ARGS+=( --usepkg )
139else
140 UPDATE_ARGS+=( --nousepkg )
141fi
142if [[ "${FLAGS_jobs}" -ne -1 ]]; then
143 UPDATE_ARGS+=( --jobs=${FLAGS_jobs} )
144fi
David James0ae653d2013-07-03 15:59:29 -0700145if [ "${FLAGS_chrome_binhost_only}" -eq "${FLAGS_TRUE}" ]; then
146 UPDATE_ARGS+=( --chrome_binhost_only )
147fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400148if [ "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ]; then
149 UPDATE_ARGS+=( --reuse_pkgs_from_local_boards )
150fi
151if [ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_TRUE}" ]; then
152 UPDATE_ARGS+=( --skip_toolchain_update )
153fi
154if [ "${FLAGS_skip_chroot_upgrade}" -eq "${FLAGS_TRUE}" ]; then
155 UPDATE_ARGS+=( --skip_chroot_upgrade )
156fi
Thiago Goncales5ad4ca02013-07-12 10:55:11 -0700157if [[ ${FLAGS_unpackonly} -eq ${FLAGS_TRUE} ]]; then
158 UPDATE_ARGS+=( --skip_board_pkg_init )
159fi
Bertrand SIMONNET10ede912014-10-09 16:21:13 -0700160if [[ -n ${FLAGS_board_root} ]]; then
161 UPDATE_ARGS+=( --board_root "${FLAGS_board_root}" )
162fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400163
164"${SCRIPTS_DIR}"/setup_board --quiet --board=${FLAGS_board} "${UPDATE_ARGS[@]}"
165
Chris Masonebbccc242014-02-08 16:23:53 -0800166sudo_clear_shadow_locks "/build/${FLAGS_board}"
167
Mike Frysinger4114c792012-09-13 22:33:12 -0400168# Setup all the emerge command/flags.
David James886f2c32014-02-26 20:38:04 -0800169EMERGE_FLAGS=( -uDNv --backtrack=30 --select --newrepo )
Mike Frysinger4114c792012-09-13 22:33:12 -0400170
Bertrand SIMONNET4dda4f52015-03-19 13:40:58 -0700171EMERGE_CMD=(
172 "${CHROMITE_BIN}/parallel_emerge"
173 --board=${FLAGS_board}
174)
175
Brian Harring3d01db22012-12-15 21:09:03 -0800176if [[ "${FLAGS_fetchonly}" -eq "${FLAGS_TRUE}" ]]; then
Brian Harring17c1fe82012-12-05 21:12:31 -0800177 EMERGE_CMD+=( --fetchonly )
178fi
Aviv Keshet8aa379b2016-02-29 10:00:05 -0800179if [[ "${FLAGS_unpackonly}" -eq "${FLAGS_TRUE}" ]]; then
Thiago Goncales5ad4ca02013-07-12 10:55:11 -0700180 EMERGE_CMD+=( --unpackonly )
181fi
Aviv Keshet8aa379b2016-02-29 10:00:05 -0800182if [[ "${FLAGS_buildretry}" -eq "${FLAGS_FALSE}" ]]; then
183 EMERGE_CMD+=( --retries=0 )
184fi
Brian Harring17c1fe82012-12-05 21:12:31 -0800185
Mike Frysinger4114c792012-09-13 22:33:12 -0400186EMERGE_CMD+=( ${EXTRA_BOARD_FLAGS} )
Brian Harringcb782242011-12-13 19:48:44 -0800187
David James17c622a2012-03-07 09:34:08 -0800188if [[ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ||
Thiago Goncales5ad4ca02013-07-12 10:55:11 -0700189 "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ||
190 "${FLAGS_usepkgonly}" -eq "${FLAGS_TRUE}" ]]; then
Brian Harringcb782242011-12-13 19:48:44 -0800191 # Use binary packages. Include all build-time dependencies,
192 # so as to avoid unnecessary differences between source
193 # and binary builds.
Thiago Goncales5ad4ca02013-07-12 10:55:11 -0700194 EMERGE_FLAGS+=( --getbinpkg --with-bdeps y )
195 if [[ ${FLAGS_usepkgonly} -eq ${FLAGS_TRUE} ]]; then
196 EMERGE_FLAGS+=( --usepkgonly )
197 else
198 EMERGE_FLAGS+=( --usepkg )
199 fi
Brian Harringcb782242011-12-13 19:48:44 -0800200fi
201
202if [[ "${FLAGS_jobs}" -ne -1 ]]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400203 EMERGE_FLAGS+=( --jobs=${FLAGS_jobs} )
204fi
205
206if [[ "${FLAGS_norebuild}" -eq "${FLAGS_FALSE}" ]]; then
207 EMERGE_FLAGS+=( --rebuild-if-unbuilt )
208fi
Bertrand SIMONNET4dda4f52015-03-19 13:40:58 -0700209if [[ "${FLAGS_showoutput}" -eq "${FLAGS_TRUE}" ]]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400210 EMERGE_FLAGS+=( --show-output )
Brian Harringcb782242011-12-13 19:48:44 -0800211fi
212
213if [[ "${FLAGS_withdebug}" -eq "${FLAGS_FALSE}" ]]; then
214 export USE="${USE} -cros-debug"
215fi
216
Chris Ching4bc95a12016-11-22 13:44:13 -0700217# TODO Handle case where passed default value, but events not enabled
218if [[ "${FLAGS_eventfile}" != "${DEFAULT_EVENT_FILE}" ]]; then
219 FLAGS_withevents="${FLAGS_TRUE}"
220fi
221
222if [[ "${FLAGS_withevents}" -eq "${FLAGS_TRUE}" ]]; then
223 mkdir -p "$(dirname $FLAGS_eventfile)"
224 EMERGE_FLAGS+=( "--eventlogfile=${FLAGS_eventfile}" )
225fi
226
Mike Frysinger4114c792012-09-13 22:33:12 -0400227# Figure out which packages we should be building.
Mike Frysinger76452ba2012-09-13 22:45:34 -0400228PACKAGES=( "$@" )
Daniel Wangaf4d0012015-07-17 11:52:05 -0700229FORCE_LOCAL_BUILD_PKGS=()
Mike Frysinger76452ba2012-09-13 22:45:34 -0400230if [[ $# -eq 0 ]]; then
Mike Frysinger22621952014-04-01 17:41:20 -0400231 PACKAGES=( virtual/target-os )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400232 if [[ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]]; then
Mike Frysingerde399282014-04-15 18:26:04 -0400233 PACKAGES+=( virtual/target-os-dev )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400234 fi
235 if [[ "${FLAGS_withfactory}" -eq "${FLAGS_TRUE}" ]]; then
Hung-Te Lin9b43ced2016-01-14 20:29:47 +0800236 PACKAGES+=( virtual/target-os-factory )
237 PACKAGES+=( virtual/target-os-factory-shim )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400238 fi
239 if [[ "${FLAGS_withtest}" -eq "${FLAGS_TRUE}" ]]; then
Mike Frysinger52669432014-05-05 14:34:09 -0400240 PACKAGES+=( virtual/target-os-test )
Daniel Wangaf4d0012015-07-17 11:52:05 -0700241 # chromeos-ssh-testkeys may generate ssh keys if the right USE flag is set.
242 # We force rebuilding this package from source every time, so that
243 # consecutive builds don't share ssh keys.
244 FORCE_LOCAL_BUILD_PKGS+=( chromeos-base/chromeos-ssh-testkeys )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400245 fi
246 if [[ "${FLAGS_withautotest}" -eq "${FLAGS_TRUE}" ]]; then
247 PACKAGES+=( chromeos-base/autotest-all )
248 fi
Brian Harringcb782242011-12-13 19:48:44 -0800249fi
250
251# Verify that all packages can be emerged from scratch, without any
252# backtracking. Only print the output if this step fails.
Mike Frysinger76452ba2012-09-13 22:45:34 -0400253info "Checking package dependencies are correct: ${PACKAGES[*]}"
David Jamesab9ca212012-11-06 11:06:07 -0800254if ! OUTPUT=$(emerge-${FLAGS_board} -pe --backtrack=0 \
255 "${PACKAGES[@]}" 2>&1); then
Brian Harringcb782242011-12-13 19:48:44 -0800256 printf "%s\n" "${OUTPUT}"
Brian Harring7f175a52012-03-02 05:37:00 -0800257 die_notrace "emerge detected broken ebuilds. See error message above."
Brian Harringcb782242011-12-13 19:48:44 -0800258fi
259
Mike Frysinger4114c792012-09-13 22:33:12 -0400260# Build cros_workon packages when they are changed.
261CROS_WORKON_PKGS=()
262if [ "${FLAGS_noworkon}" -eq "${FLAGS_FALSE}" ]; then
263 LIST_MODIFIED_PACKAGES="${CHROMITE_BIN}/cros_list_modified_packages"
Jason D. Clinton321e2f82017-08-09 16:21:23 -0600264 MODIFIED_PACKAGES=( $("${LIST_MODIFIED_PACKAGES}" --board=${FLAGS_board}) )
Gregory Meinke7851ece2018-05-09 13:34:06 -0600265 info "cros_workon modified packages '${MODIFIED_PACKAGES[*]}' detected"
Jason D. Clinton321e2f82017-08-09 16:21:23 -0600266 CROS_WORKON_PKGS+=( "${MODIFIED_PACKAGES[@]}" )
Mike Frysinger4114c792012-09-13 22:33:12 -0400267
David James4941c6b2014-02-03 16:24:59 -0800268 # TODO(anush): Make chrome a fake cros-workon package.
269 if [[ -n "${CHROME_ORIGIN}" ]]; then
270 CROS_WORKON_PKGS+=( chromeos-base/chromeos-chrome )
271 fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400272fi
273
Daniel Wangaf4d0012015-07-17 11:52:05 -0700274# cros_workon packages always have to be rebuilt.
Daniel Wang491f42a2015-08-20 12:29:59 -0700275FORCE_LOCAL_BUILD_PKGS+=( "${CROS_WORKON_PKGS[@]}" )
Daniel Wangaf4d0012015-07-17 11:52:05 -0700276
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600277if [[ -n "${FLAGS_board_root}" ]]; then
278 export ROOT="${FLAGS_board_root}"
279 export PORTAGE_CONFIGROOT="${ROOT}"
280 export SYSROOT="${ROOT}"
281 export PKGDIR="${ROOT}"/packages
282fi
283
284# Temporarily modify the emerge flags so we can calculate the revdeps
285# on the modified packages.
Gregory Meinke0766df42018-08-23 11:36:12 -0600286if [[ "${FLAGS_withrevdeps}" -eq "${FLAGS_TRUE}" ]]; then
Yves Arrouyec16e45e2018-08-31 08:37:15 -0700287 info "starting reverse dependency calculations ..."
Gregory Meinke0766df42018-08-23 11:36:12 -0600288 SIM_EMERGE_FLAGS=( "${EMERGE_FLAGS[@]}" --pretend --columns )
Gregory Meinkeee71dd12018-07-09 12:42:25 -0600289
Gregory Meinke0766df42018-08-23 11:36:12 -0600290 if [[ ${#PACKAGES[@]} -gt 0 ]]; then
291 SIM_EMERGE_FLAGS+=(
292 --reinstall-atoms="${PACKAGES[*]}"
293 --usepkg-exclude="${PACKAGES[*]}"
294 )
295 fi
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600296
Gregory Meinke0766df42018-08-23 11:36:12 -0600297 # Calculate only the ebuild changes from the emerge simulation ignoring
298 # the virtual packages and the forced rebuild of autotest-all package.
299 BASE_INSTALL_PKGS=( $( \
300 sudo -E "${EMERGE_CMD[@]}" "${SIM_EMERGE_FLAGS[@]}" "${PACKAGES[@]}" | \
301 sed -n -E '/^\[ebuild /{s:^[^]]+\] +::;s: .*::;p}' | \
302 grep -v -e '^virtual/' -e '^chromeos-base/autotest-all' | sort -u ) )
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600303
Gregory Meinke0766df42018-08-23 11:36:12 -0600304 MOD_PKGS=()
305 if [[ "${#BASE_INSTALL_PKGS[@]}" -gt 0 ]]; then
306 info "New packages being installed: ${BASE_INSTALL_PKGS[*]}."
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600307 # Convert specific versions into base package names
308 MOD_PKGS+=( $(\
Gregory Meinke0766df42018-08-23 11:36:12 -0600309 equery-${FLAGS_board} list -p -o --format='$category/$name' \
310 "${BASE_INSTALL_PKGS[@]}" | sort -u ) )
Gregory Meinkeee71dd12018-07-09 12:42:25 -0600311 # Remove Chrome as rebuilding it is expensive and almost never makes sense
Gregory Meinke0766df42018-08-23 11:36:12 -0600312 MOD_PKGS=( $(printf '%s\n' "${MOD_PKGS[@]}" | \
313 grep -v 'chromeos-base/chromeos-chrome') )
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600314 fi
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600315
Gregory Meinke0766df42018-08-23 11:36:12 -0600316 FORCE_LOCAL_BUILD_PKGS+=( "${MOD_PKGS[@]}" )
317
318 if [[ "${#MOD_PKGS[@]}" -gt 0 ]]; then
319 info "calculating reverse dependencies on packages: ${MOD_PKGS[*]}"
320 REV_DEPS=( $(\
321 equery-${FLAGS_board} -q depends --indirect "${MOD_PKGS[@]}" |\
322 awk '{print $1}' | grep -v ^virtual/ | sort -u) )
323 if [[ "${#REV_DEPS[@]}" -gt 0 ]]; then
324 # Convert specific versions into base package names
325 RMOD_PKGS=( $(\
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600326 equery-${FLAGS_board} -q list -p -o --format='$category/$name' \
Gregory Meinke0766df42018-08-23 11:36:12 -0600327 "${REV_DEPS[@]}" | sort -u ) )
328 # Remove Chrome as rebuilding it is expensive and almost never makes sense
329 RMOD_PKGS=( $(printf '%s\n' "${RMOD_PKGS[@]}" | \
330 grep -v 'chromeos-base/chromeos-chrome') )
331 info "final reverse dependencies that will be rebuilt: ${RMOD_PKGS[*]}"
332 FORCE_LOCAL_BUILD_PKGS+=( "${RMOD_PKGS[@]}" )
333 fi
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600334 fi
Gregory Meinke0766df42018-08-23 11:36:12 -0600335fi # end FLAGS_withrevdeps
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600336
Daniel Wangaf4d0012015-07-17 11:52:05 -0700337if [[ ${#FORCE_LOCAL_BUILD_PKGS[@]} -gt 0 ]]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400338 EMERGE_FLAGS+=(
Daniel Wangaf4d0012015-07-17 11:52:05 -0700339 --reinstall-atoms="${FORCE_LOCAL_BUILD_PKGS[*]}"
340 --usepkg-exclude="${FORCE_LOCAL_BUILD_PKGS[*]}"
Mike Frysinger4114c792012-09-13 22:33:12 -0400341 )
David James710a7d12011-12-21 15:57:02 -0800342fi
Matt Tennant298f61a2012-06-25 21:54:33 -0700343
344# Prepare tmp file to capture emerge output from tee.
Hidehiko Abed9d6bfd2017-04-28 17:24:21 +0900345tmpfile=$(mktemp --tmpdir tmp.build_packages-emerge.XXXXXX)
Matt Tennant298f61a2012-06-25 21:54:33 -0700346trap "rm -f '${tmpfile}'" EXIT
347
Mike Frysinger76452ba2012-09-13 22:45:34 -0400348info "Merging board packages now"
Matt Tennant298f61a2012-06-25 21:54:33 -0700349(
Hidehiko Abe7a41d342017-03-29 21:19:16 +0900350 # Support goma on bots. This has to run in subshell, otherwise EXIT trap
351 # handler is overwritten.
352 if [[ "${FLAGS_run_goma}" -eq "${FLAGS_TRUE}" ]]; then
353 info "Starting goma compiler_proxy."
354 goma_ctl="${GOMA_DIR:-${HOME}/goma}/goma_ctl.py"
355 "${goma_ctl}" restart
Hidehiko Abe2aa41ae2017-05-16 18:31:00 +0900356 trap "'${goma_ctl}' stop" EXIT
Hidehiko Abe7a41d342017-03-29 21:19:16 +0900357 fi
358
Matt Tennant298f61a2012-06-25 21:54:33 -0700359 set -o pipefail
Mike Frysinger4114c792012-09-13 22:33:12 -0400360 sudo -E "${EMERGE_CMD[@]}" "${EMERGE_FLAGS[@]}" "${PACKAGES[@]}" | \
Matt Tennant298f61a2012-06-25 21:54:33 -0700361 tee "${tmpfile}"
362)
363
364# Extract total package count from emerge output.
365package_count=$(awk '$0 ~ /^Total: [0-9]+ packages/ { print $2 }' "${tmpfile}")
366rm "${tmpfile}"
367trap - EXIT
Brian Harringcb782242011-12-13 19:48:44 -0800368
369echo "Builds complete"
Bertrand SIMONNETc7a46e22014-12-11 15:58:11 -0800370
371if [[ ${FLAGS_withdebugsymbols} -eq ${FLAGS_TRUE} ]]; then
372 info "fetching the debug symbols"
Mike Frysinger66accd22017-09-13 03:50:30 -0400373 sudo -E "${CHROMITE_BIN}/cros_install_debug_syms" \
Bertrand SIMONNETc7a46e22014-12-11 15:58:11 -0800374 "--board=${FLAGS_board}" "--all"
375fi
376
Matt Tennant298f61a2012-06-25 21:54:33 -0700377EXTRA_COMMAND_STATS[package_count]=${package_count}
378command_completed
Brian Harringcb782242011-12-13 19:48:44 -0800379echo "Done"