blob: 70cc2ba88bef4169a3405fc0a18072e4a60de7eb [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."
Mike Frysingerf4711422019-11-13 18:04:31 -050021DEFINE_boolean workon "${FLAGS_TRUE}" \
22 "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."
Bertrand SIMONNET2f6aaf22015-02-09 15:49:05 -080027DEFINE_boolean withdebugsymbols "${FLAGS_FALSE}" \
Bertrand SIMONNETc7a46e22014-12-11 15:58:11 -080028 "Install the debug symbols for all packages"
Chris Ching4bc95a12016-11-22 13:44:13 -070029DEFINE_boolean withevents "${FLAGS_FALSE}" \
30 "Generate events during parallel_emerge step"
31DEFINE_string eventfile "${DEFAULT_EVENT_FILE}" \
32 "Define the file that event logs will be written."
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -060033DEFINE_boolean withrevdeps "${FLAGS_TRUE}" \
Gregory Meinke0766df42018-08-23 11:36:12 -060034 "Calculate reverse dependencies on changed ebuilds."
Mike Frysinger38653b02019-10-04 13:56:29 -040035DEFINE_boolean autosetgov "${FLAGS_FALSE}" \
36 "Automatically set cpu governor to 'performance'."
Chris McDonald5405a802019-11-12 13:58:38 -070037DEFINE_boolean use_any_chrome "${FLAGS_TRUE}" \
38 "Use any Chrome prebuilt available, even if the prebuilt doesn't match exactly."
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"
David James855afb72012-03-14 20:04:59 -070062
63# The following options are advanced options, only available to those willing
64# to read the source code. They are not shown in help output, since they are
65# not needed for the typical developer workflow.
Ryan Cuieb4595f2012-12-17 14:28:42 -080066DEFINE_string accept_licenses "" \
67 "Licenses to append to the accept list."
David James855afb72012-03-14 20:04:59 -070068DEFINE_integer jobs -1 \
69 "How many packages to build in parallel at maximum."
70DEFINE_boolean norebuild "${FLAGS_FALSE}" \
71 "Don't automatically rebuild dependencies."
Mike Frysinger839e82a2012-03-01 14:22:10 -050072DEFINE_boolean skip_chroot_upgrade "${FLAGS_FALSE}" \
73 "Don't run the chroot upgrade automatically; use with care."
David James855afb72012-03-14 20:04:59 -070074DEFINE_boolean skip_toolchain_update "${FLAGS_FALSE}" \
75 "Don't update toolchain automatically."
76DEFINE_boolean withdev "${FLAGS_TRUE}" \
77 "Build useful developer friendly utilities."
78DEFINE_boolean withdebug "${FLAGS_TRUE}" \
79 "Build debug versions of Chromium-OS-specific packages."
80DEFINE_boolean withfactory "${FLAGS_TRUE}" \
81 "Build factory installer."
82DEFINE_boolean withtest "${FLAGS_TRUE}" \
83 "Build packages required for testing."
Aviv Keshet8aa379b2016-02-29 10:00:05 -080084DEFINE_boolean buildretry "${FLAGS_TRUE}" \
85 "Retry failed packages."
Brian Harringcb782242011-12-13 19:48:44 -080086
David James17c622a2012-03-07 09:34:08 -080087# The --reuse_pkgs_from_local_boards flag tells Portage to share binary
88# packages between boards that are built locally, so that the total time
89# required to build several boards is reduced. This flag is only useful
90# when you are not able to use remote binary packages, since remote binary
91# packages are usually more up to date than anything you have locally.
Hidehiko Abe7a41d342017-03-29 21:19:16 +090092DEFINE_boolean reuse_pkgs_from_local_boards "${FLAGS_FALSE}" \
David James17c622a2012-03-07 09:34:08 -080093 "Bootstrap from local packages instead of remote packages."
94
Hidehiko Abe7a41d342017-03-29 21:19:16 +090095# --run_goma option is designed to be used on bots.
96# If you're trying to build pacakges with goma in your local dev env, this is
97# *not* the option you're looking for. Please see comments below.
98# This option; 1) starts goma, 2) builds packages (expecting that goma is
99# used), then 3) stops goma explicitly.
100# 3) is a request from the goma team, so that stats/logs can be taken.
101# Note: GOMA_DIR and GOMA_SERVICE_ACCOUNT_JSON_FILE are expected to be passed
102# via env var.
103#
104# In local dev env cases, compiler_proxy is expected to keep running.
105# In such a case;
106# $ python ${GOMA_DIR}/goma_ctl.py ensure_start
107# $ ./build_packages (... and options without --run_goma ...)
108# is an expected commandline sequence. If you set --run_goma flag while
109# compiler_proxy is already running, the existing compiler_proxy will be
110# stopped.
111DEFINE_boolean run_goma "${FLAGS_FALSE}" \
112 "If set to true, (re)starts goma, builds packages, and then stops goma."
113
Brian Harringcb782242011-12-13 19:48:44 -0800114# Parse command line
Brian Harringcb782242011-12-13 19:48:44 -0800115FLAGS "$@" || exit 1
116eval set -- "${FLAGS_ARGV}"
Brian Harringcb782242011-12-13 19:48:44 -0800117
118# Die on any errors.
Brian Harring7f175a52012-03-02 05:37:00 -0800119switch_to_strict_mode
Brian Harringcb782242011-12-13 19:48:44 -0800120
Alex Klein12b97722019-12-09 14:25:33 -0700121# This is a temporary measure to help the goma team check the configs while
122# they transition their backend service.
123# TODO(crbug.com/1032290): Delete after the goma RBE transition is complete.
124if [[ "${FLAGS_run_goma}" -eq "${FLAGS_TRUE}" ]]; then
125 info "Environment:"
126 env
127 info "End Environment."
128fi
129
Brian Harringcb782242011-12-13 19:48:44 -0800130# Right now build_packages has to be run from scripts/
131. ${SRC_ROOT}/third_party/chromiumos-overlay/chromeos/config/chromeos_version.sh
132
Mike Frysinger38653b02019-10-04 13:56:29 -0400133# On some systems, powersave can take a long time to ramp up. Inform the user
134# so they can get faster builds. https://crbug.com/1008932
135if grep -qs powersave \
136 /sys/devices/system/cpu/cpufreq/policy*/scaling_governor; then
137 # Make sure we can actually support "performance".
138 if grep -qs performance \
139 /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors; then
140 if [[ "${FLAGS_autosetgov}" -eq "${FLAGS_TRUE}" ]]; then
141 info "Temporarily setting cpu governor to 'performance'"
142 trap "sudo cpupower -c all frequency-set -g powersave >&/dev/null" EXIT
143 sudo cpupower -c all frequency-set -g performance >&/dev/null
144 else
145 warn "Current CPU governor set to 'powersave' which can slow down builds."
146 warn "Use --autosetgov to automatically (and temporarily) switch to" \
147 "'performance'."
148 fi
149 fi
150fi
151
Brian Harringcb782242011-12-13 19:48:44 -0800152if [[ -z "${FLAGS_board}" ]]; then
153 echo "Error: --board is required."
154 exit 1
155fi
156
Mike Frysinger4114c792012-09-13 22:33:12 -0400157# Before we can run any tools, we need to update chroot or setup_board.
158UPDATE_ARGS=()
Ryan Cuieb4595f2012-12-17 14:28:42 -0800159if [[ -n ${FLAGS_accept_licenses} ]]; then
Alex Kleind65766f2019-01-11 14:57:34 -0700160 UPDATE_ARGS+=( --accept-licenses "${FLAGS_accept_licenses}" )
Ryan Cuieb4595f2012-12-17 14:28:42 -0800161fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400162if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then
163 UPDATE_ARGS+=( --usepkg )
164else
165 UPDATE_ARGS+=( --nousepkg )
166fi
167if [[ "${FLAGS_jobs}" -ne -1 ]]; then
168 UPDATE_ARGS+=( --jobs=${FLAGS_jobs} )
169fi
170if [ "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ]; then
Alex Kleind65766f2019-01-11 14:57:34 -0700171 UPDATE_ARGS+=( --reuse-pkgs-from-local-boards )
Mike Frysinger4114c792012-09-13 22:33:12 -0400172fi
173if [ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_TRUE}" ]; then
Alex Kleind65766f2019-01-11 14:57:34 -0700174 UPDATE_ARGS+=( --skip-toolchain-update )
Mike Frysinger4114c792012-09-13 22:33:12 -0400175fi
176if [ "${FLAGS_skip_chroot_upgrade}" -eq "${FLAGS_TRUE}" ]; then
Alex Kleind65766f2019-01-11 14:57:34 -0700177 UPDATE_ARGS+=( --skip-chroot-upgrade )
Mike Frysinger4114c792012-09-13 22:33:12 -0400178fi
Bertrand SIMONNET10ede912014-10-09 16:21:13 -0700179if [[ -n ${FLAGS_board_root} ]]; then
Alex Kleind65766f2019-01-11 14:57:34 -0700180 UPDATE_ARGS+=( --board-root "${FLAGS_board_root}" )
Bertrand SIMONNET10ede912014-10-09 16:21:13 -0700181fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400182
Alex Kleind65766f2019-01-11 14:57:34 -0700183setup_board --quiet --board=${FLAGS_board} "${UPDATE_ARGS[@]}"
Mike Frysinger4114c792012-09-13 22:33:12 -0400184
Chris Masonebbccc242014-02-08 16:23:53 -0800185sudo_clear_shadow_locks "/build/${FLAGS_board}"
Ned Nguyen9af21f52019-04-05 11:30:52 -0600186PORTAGE_BINHOST=$(portageq-${FLAGS_board} envvar 'PORTAGE_BINHOST')
187info "PORTAGE_BINHOST: ${PORTAGE_BINHOST}"
188
Chris Masonebbccc242014-02-08 16:23:53 -0800189
Mike Frysinger4114c792012-09-13 22:33:12 -0400190# Setup all the emerge command/flags.
Mike Frysinger697ab962019-11-04 20:02:43 -0500191EMERGE_FLAGS=( -uDNv --backtrack=30 --newrepo )
Mike Frysinger4114c792012-09-13 22:33:12 -0400192
Bertrand SIMONNET4dda4f52015-03-19 13:40:58 -0700193EMERGE_CMD=(
194 "${CHROMITE_BIN}/parallel_emerge"
195 --board=${FLAGS_board}
196)
197
Chris McDonald5405a802019-11-12 13:58:38 -0700198if [[ "${FLAGS_use_any_chrome}" -eq "${FLAGS_TRUE}" ]]; then
199 EMERGE_CMD+=( "--force-remote-binary=chromeos-base/chromeos-chrome" )
200fi
201
Aviv Keshet8aa379b2016-02-29 10:00:05 -0800202if [[ "${FLAGS_buildretry}" -eq "${FLAGS_FALSE}" ]]; then
203 EMERGE_CMD+=( --retries=0 )
204fi
Brian Harring17c1fe82012-12-05 21:12:31 -0800205
Mike Frysinger4114c792012-09-13 22:33:12 -0400206EMERGE_CMD+=( ${EXTRA_BOARD_FLAGS} )
Brian Harringcb782242011-12-13 19:48:44 -0800207
David James17c622a2012-03-07 09:34:08 -0800208if [[ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ||
Thiago Goncales5ad4ca02013-07-12 10:55:11 -0700209 "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ||
210 "${FLAGS_usepkgonly}" -eq "${FLAGS_TRUE}" ]]; then
Brian Harringcb782242011-12-13 19:48:44 -0800211 # Use binary packages. Include all build-time dependencies,
212 # so as to avoid unnecessary differences between source
213 # and binary builds.
Thiago Goncales5ad4ca02013-07-12 10:55:11 -0700214 EMERGE_FLAGS+=( --getbinpkg --with-bdeps y )
215 if [[ ${FLAGS_usepkgonly} -eq ${FLAGS_TRUE} ]]; then
216 EMERGE_FLAGS+=( --usepkgonly )
217 else
218 EMERGE_FLAGS+=( --usepkg )
219 fi
Brian Harringcb782242011-12-13 19:48:44 -0800220fi
221
222if [[ "${FLAGS_jobs}" -ne -1 ]]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400223 EMERGE_FLAGS+=( --jobs=${FLAGS_jobs} )
224fi
225
226if [[ "${FLAGS_norebuild}" -eq "${FLAGS_FALSE}" ]]; then
Chris McDonald00dcd722019-10-17 13:53:28 -0600227 EMERGE_FLAGS+=( --rebuild-if-new-rev )
Mike Frysinger4114c792012-09-13 22:33:12 -0400228fi
Bertrand SIMONNET4dda4f52015-03-19 13:40:58 -0700229if [[ "${FLAGS_showoutput}" -eq "${FLAGS_TRUE}" ]]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400230 EMERGE_FLAGS+=( --show-output )
Brian Harringcb782242011-12-13 19:48:44 -0800231fi
232
233if [[ "${FLAGS_withdebug}" -eq "${FLAGS_FALSE}" ]]; then
234 export USE="${USE} -cros-debug"
235fi
236
Chris Ching4bc95a12016-11-22 13:44:13 -0700237# TODO Handle case where passed default value, but events not enabled
238if [[ "${FLAGS_eventfile}" != "${DEFAULT_EVENT_FILE}" ]]; then
239 FLAGS_withevents="${FLAGS_TRUE}"
240fi
241
242if [[ "${FLAGS_withevents}" -eq "${FLAGS_TRUE}" ]]; then
243 mkdir -p "$(dirname $FLAGS_eventfile)"
244 EMERGE_FLAGS+=( "--eventlogfile=${FLAGS_eventfile}" )
245fi
246
Mike Frysinger4114c792012-09-13 22:33:12 -0400247# Figure out which packages we should be building.
Mike Frysinger76452ba2012-09-13 22:45:34 -0400248PACKAGES=( "$@" )
Daniel Wangaf4d0012015-07-17 11:52:05 -0700249FORCE_LOCAL_BUILD_PKGS=()
Mike Frysinger76452ba2012-09-13 22:45:34 -0400250if [[ $# -eq 0 ]]; then
Mike Frysinger22621952014-04-01 17:41:20 -0400251 PACKAGES=( virtual/target-os )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400252 if [[ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]]; then
Mike Frysingerde399282014-04-15 18:26:04 -0400253 PACKAGES+=( virtual/target-os-dev )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400254 fi
255 if [[ "${FLAGS_withfactory}" -eq "${FLAGS_TRUE}" ]]; then
Hung-Te Lin9b43ced2016-01-14 20:29:47 +0800256 PACKAGES+=( virtual/target-os-factory )
257 PACKAGES+=( virtual/target-os-factory-shim )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400258 fi
259 if [[ "${FLAGS_withtest}" -eq "${FLAGS_TRUE}" ]]; then
Mike Frysinger52669432014-05-05 14:34:09 -0400260 PACKAGES+=( virtual/target-os-test )
Daniel Wangaf4d0012015-07-17 11:52:05 -0700261 # chromeos-ssh-testkeys may generate ssh keys if the right USE flag is set.
262 # We force rebuilding this package from source every time, so that
263 # consecutive builds don't share ssh keys.
264 FORCE_LOCAL_BUILD_PKGS+=( chromeos-base/chromeos-ssh-testkeys )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400265 fi
266 if [[ "${FLAGS_withautotest}" -eq "${FLAGS_TRUE}" ]]; then
267 PACKAGES+=( chromeos-base/autotest-all )
268 fi
Brian Harringcb782242011-12-13 19:48:44 -0800269fi
270
Chris McDonaldac5d8632019-10-23 15:55:45 -0600271info "Rebuilding Portage cache"
272# Before running any emerge operations, regenerate the Portage dependency cache
273# in parallel.
Mike Frysinger61157612019-08-17 13:29:28 -0400274"${EMERGE_CMD[@]}" --regen --quiet
Chris McDonaldac5d8632019-10-23 15:55:45 -0600275
Brian Harringcb782242011-12-13 19:48:44 -0800276# Verify that all packages can be emerged from scratch, without any
277# backtracking. Only print the output if this step fails.
Mike Frysinger76452ba2012-09-13 22:45:34 -0400278info "Checking package dependencies are correct: ${PACKAGES[*]}"
David Jamesab9ca212012-11-06 11:06:07 -0800279if ! OUTPUT=$(emerge-${FLAGS_board} -pe --backtrack=0 \
280 "${PACKAGES[@]}" 2>&1); then
Brian Harringcb782242011-12-13 19:48:44 -0800281 printf "%s\n" "${OUTPUT}"
Brian Harring7f175a52012-03-02 05:37:00 -0800282 die_notrace "emerge detected broken ebuilds. See error message above."
Brian Harringcb782242011-12-13 19:48:44 -0800283fi
284
Mike Frysinger4114c792012-09-13 22:33:12 -0400285# Build cros_workon packages when they are changed.
286CROS_WORKON_PKGS=()
Mike Frysingerf4711422019-11-13 18:04:31 -0500287if [ "${FLAGS_workon}" -eq "${FLAGS_TRUE}" ]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400288 LIST_MODIFIED_PACKAGES="${CHROMITE_BIN}/cros_list_modified_packages"
Jason D. Clinton321e2f82017-08-09 16:21:23 -0600289 MODIFIED_PACKAGES=( $("${LIST_MODIFIED_PACKAGES}" --board=${FLAGS_board}) )
Gregory Meinke7851ece2018-05-09 13:34:06 -0600290 info "cros_workon modified packages '${MODIFIED_PACKAGES[*]}' detected"
Jason D. Clinton321e2f82017-08-09 16:21:23 -0600291 CROS_WORKON_PKGS+=( "${MODIFIED_PACKAGES[@]}" )
Mike Frysinger4114c792012-09-13 22:33:12 -0400292
David James4941c6b2014-02-03 16:24:59 -0800293 # TODO(anush): Make chrome a fake cros-workon package.
294 if [[ -n "${CHROME_ORIGIN}" ]]; then
295 CROS_WORKON_PKGS+=( chromeos-base/chromeos-chrome )
296 fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400297fi
298
Daniel Wangaf4d0012015-07-17 11:52:05 -0700299# cros_workon packages always have to be rebuilt.
Daniel Wang491f42a2015-08-20 12:29:59 -0700300FORCE_LOCAL_BUILD_PKGS+=( "${CROS_WORKON_PKGS[@]}" )
Daniel Wangaf4d0012015-07-17 11:52:05 -0700301
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600302if [[ -n "${FLAGS_board_root}" ]]; then
303 export ROOT="${FLAGS_board_root}"
304 export PORTAGE_CONFIGROOT="${ROOT}"
305 export SYSROOT="${ROOT}"
306 export PKGDIR="${ROOT}"/packages
307fi
308
309# Temporarily modify the emerge flags so we can calculate the revdeps
310# on the modified packages.
Gregory Meinke0766df42018-08-23 11:36:12 -0600311if [[ "${FLAGS_withrevdeps}" -eq "${FLAGS_TRUE}" ]]; then
Yves Arrouyec16e45e2018-08-31 08:37:15 -0700312 info "starting reverse dependency calculations ..."
Gregory Meinke0766df42018-08-23 11:36:12 -0600313 SIM_EMERGE_FLAGS=( "${EMERGE_FLAGS[@]}" --pretend --columns )
Gregory Meinkeee71dd12018-07-09 12:42:25 -0600314
Gregory Meinke0766df42018-08-23 11:36:12 -0600315 if [[ ${#PACKAGES[@]} -gt 0 ]]; then
316 SIM_EMERGE_FLAGS+=(
317 --reinstall-atoms="${PACKAGES[*]}"
318 --usepkg-exclude="${PACKAGES[*]}"
319 )
320 fi
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600321
Gregory Meinke0766df42018-08-23 11:36:12 -0600322 # Calculate only the ebuild changes from the emerge simulation ignoring
323 # the virtual packages and the forced rebuild of autotest-all package.
324 BASE_INSTALL_PKGS=( $( \
325 sudo -E "${EMERGE_CMD[@]}" "${SIM_EMERGE_FLAGS[@]}" "${PACKAGES[@]}" | \
326 sed -n -E '/^\[ebuild /{s:^[^]]+\] +::;s: .*::;p}' | \
327 grep -v -e '^virtual/' -e '^chromeos-base/autotest-all' | sort -u ) )
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600328
Gregory Meinke0766df42018-08-23 11:36:12 -0600329 MOD_PKGS=()
330 if [[ "${#BASE_INSTALL_PKGS[@]}" -gt 0 ]]; then
331 info "New packages being installed: ${BASE_INSTALL_PKGS[*]}."
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600332 # Convert specific versions into base package names
333 MOD_PKGS+=( $(\
Gregory Meinke0766df42018-08-23 11:36:12 -0600334 equery-${FLAGS_board} list -p -o --format='$category/$name' \
335 "${BASE_INSTALL_PKGS[@]}" | sort -u ) )
Mike Frysinger5a11e872018-09-05 16:29:02 -0400336 # Remove Chrome as rebuilding it is expensive and almost never makes sense.
337 # Ignore grep exit status in case chromeos-chrome is the only package.
Gregory Meinke0766df42018-08-23 11:36:12 -0600338 MOD_PKGS=( $(printf '%s\n' "${MOD_PKGS[@]}" | \
Mike Frysinger5a11e872018-09-05 16:29:02 -0400339 grep -v 'chromeos-base/chromeos-chrome' || :) )
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600340 fi
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600341
Gregory Meinke0766df42018-08-23 11:36:12 -0600342 FORCE_LOCAL_BUILD_PKGS+=( "${MOD_PKGS[@]}" )
343
344 if [[ "${#MOD_PKGS[@]}" -gt 0 ]]; then
345 info "calculating reverse dependencies on packages: ${MOD_PKGS[*]}"
346 REV_DEPS=( $(\
347 equery-${FLAGS_board} -q depends --indirect "${MOD_PKGS[@]}" |\
348 awk '{print $1}' | grep -v ^virtual/ | sort -u) )
349 if [[ "${#REV_DEPS[@]}" -gt 0 ]]; then
350 # Convert specific versions into base package names
351 RMOD_PKGS=( $(\
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600352 equery-${FLAGS_board} -q list -p -o --format='$category/$name' \
Gregory Meinke0766df42018-08-23 11:36:12 -0600353 "${REV_DEPS[@]}" | sort -u ) )
Mike Frysinger5a11e872018-09-05 16:29:02 -0400354 # Remove Chrome as rebuilding it is expensive and almost never makes
355 # sense. Ignore grep exit status in case chromeos-chrome is the only
356 # package.
Gregory Meinke0766df42018-08-23 11:36:12 -0600357 RMOD_PKGS=( $(printf '%s\n' "${RMOD_PKGS[@]}" | \
Mike Frysinger5a11e872018-09-05 16:29:02 -0400358 grep -v 'chromeos-base/chromeos-chrome' || :) )
Gregory Meinke0766df42018-08-23 11:36:12 -0600359 info "final reverse dependencies that will be rebuilt: ${RMOD_PKGS[*]}"
360 FORCE_LOCAL_BUILD_PKGS+=( "${RMOD_PKGS[@]}" )
361 fi
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600362 fi
Gregory Meinke0766df42018-08-23 11:36:12 -0600363fi # end FLAGS_withrevdeps
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600364
Daniel Wangaf4d0012015-07-17 11:52:05 -0700365if [[ ${#FORCE_LOCAL_BUILD_PKGS[@]} -gt 0 ]]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400366 EMERGE_FLAGS+=(
Daniel Wangaf4d0012015-07-17 11:52:05 -0700367 --reinstall-atoms="${FORCE_LOCAL_BUILD_PKGS[*]}"
368 --usepkg-exclude="${FORCE_LOCAL_BUILD_PKGS[*]}"
Mike Frysinger4114c792012-09-13 22:33:12 -0400369 )
David James710a7d12011-12-21 15:57:02 -0800370fi
Matt Tennant298f61a2012-06-25 21:54:33 -0700371
Mike Frysinger76452ba2012-09-13 22:45:34 -0400372info "Merging board packages now"
Matt Tennant298f61a2012-06-25 21:54:33 -0700373(
Hidehiko Abe7a41d342017-03-29 21:19:16 +0900374 # Support goma on bots. This has to run in subshell, otherwise EXIT trap
375 # handler is overwritten.
376 if [[ "${FLAGS_run_goma}" -eq "${FLAGS_TRUE}" ]]; then
377 info "Starting goma compiler_proxy."
378 goma_ctl="${GOMA_DIR:-${HOME}/goma}/goma_ctl.py"
Mike Frysingeraa84e432019-09-24 14:06:27 -0400379 # TODO(crbug.com/1007384): Stop forcing Python 2.
380 EPYTHON="python2" "${goma_ctl}" restart
381 trap "EPYTHON=python2 '${goma_ctl}' stop" EXIT
Hidehiko Abe7a41d342017-03-29 21:19:16 +0900382 fi
383
Chris McDonald3b359902019-08-12 13:02:12 -0600384 sudo -E "${EMERGE_CMD[@]}" "${EMERGE_FLAGS[@]}" "${PACKAGES[@]}"
Matt Tennant298f61a2012-06-25 21:54:33 -0700385)
386
Brian Harringcb782242011-12-13 19:48:44 -0800387echo "Builds complete"
Bertrand SIMONNETc7a46e22014-12-11 15:58:11 -0800388
389if [[ ${FLAGS_withdebugsymbols} -eq ${FLAGS_TRUE} ]]; then
390 info "fetching the debug symbols"
Mike Frysinger66accd22017-09-13 03:50:30 -0400391 sudo -E "${CHROMITE_BIN}/cros_install_debug_syms" \
Bertrand SIMONNETc7a46e22014-12-11 15:58:11 -0800392 "--board=${FLAGS_board}" "--all"
393fi
394
Matt Tennant298f61a2012-06-25 21:54:33 -0700395command_completed
Brian Harringcb782242011-12-13 19:48:44 -0800396echo "Done"