blob: 51773d46b57fcefbfa727df7d7caf85a9efe22fe [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
121# Right now build_packages has to be run from scripts/
122. ${SRC_ROOT}/third_party/chromiumos-overlay/chromeos/config/chromeos_version.sh
123
Mike Frysinger38653b02019-10-04 13:56:29 -0400124# On some systems, powersave can take a long time to ramp up. Inform the user
125# so they can get faster builds. https://crbug.com/1008932
126if grep -qs powersave \
127 /sys/devices/system/cpu/cpufreq/policy*/scaling_governor; then
128 # Make sure we can actually support "performance".
129 if grep -qs performance \
130 /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors; then
131 if [[ "${FLAGS_autosetgov}" -eq "${FLAGS_TRUE}" ]]; then
132 info "Temporarily setting cpu governor to 'performance'"
133 trap "sudo cpupower -c all frequency-set -g powersave >&/dev/null" EXIT
134 sudo cpupower -c all frequency-set -g performance >&/dev/null
135 else
136 warn "Current CPU governor set to 'powersave' which can slow down builds."
137 warn "Use --autosetgov to automatically (and temporarily) switch to" \
138 "'performance'."
139 fi
140 fi
141fi
142
Brian Harringcb782242011-12-13 19:48:44 -0800143if [[ -z "${FLAGS_board}" ]]; then
144 echo "Error: --board is required."
145 exit 1
146fi
147
Mike Frysinger4114c792012-09-13 22:33:12 -0400148# Before we can run any tools, we need to update chroot or setup_board.
149UPDATE_ARGS=()
Ryan Cuieb4595f2012-12-17 14:28:42 -0800150if [[ -n ${FLAGS_accept_licenses} ]]; then
Alex Kleind65766f2019-01-11 14:57:34 -0700151 UPDATE_ARGS+=( --accept-licenses "${FLAGS_accept_licenses}" )
Ryan Cuieb4595f2012-12-17 14:28:42 -0800152fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400153if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then
154 UPDATE_ARGS+=( --usepkg )
155else
156 UPDATE_ARGS+=( --nousepkg )
157fi
158if [[ "${FLAGS_jobs}" -ne -1 ]]; then
159 UPDATE_ARGS+=( --jobs=${FLAGS_jobs} )
160fi
161if [ "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ]; then
Alex Kleind65766f2019-01-11 14:57:34 -0700162 UPDATE_ARGS+=( --reuse-pkgs-from-local-boards )
Mike Frysinger4114c792012-09-13 22:33:12 -0400163fi
164if [ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_TRUE}" ]; then
Alex Kleind65766f2019-01-11 14:57:34 -0700165 UPDATE_ARGS+=( --skip-toolchain-update )
Mike Frysinger4114c792012-09-13 22:33:12 -0400166fi
167if [ "${FLAGS_skip_chroot_upgrade}" -eq "${FLAGS_TRUE}" ]; then
Alex Kleind65766f2019-01-11 14:57:34 -0700168 UPDATE_ARGS+=( --skip-chroot-upgrade )
Mike Frysinger4114c792012-09-13 22:33:12 -0400169fi
Bertrand SIMONNET10ede912014-10-09 16:21:13 -0700170if [[ -n ${FLAGS_board_root} ]]; then
Alex Kleind65766f2019-01-11 14:57:34 -0700171 UPDATE_ARGS+=( --board-root "${FLAGS_board_root}" )
Bertrand SIMONNET10ede912014-10-09 16:21:13 -0700172fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400173
Alex Kleind65766f2019-01-11 14:57:34 -0700174setup_board --quiet --board=${FLAGS_board} "${UPDATE_ARGS[@]}"
Mike Frysinger4114c792012-09-13 22:33:12 -0400175
Chris Masonebbccc242014-02-08 16:23:53 -0800176sudo_clear_shadow_locks "/build/${FLAGS_board}"
Ned Nguyen9af21f52019-04-05 11:30:52 -0600177PORTAGE_BINHOST=$(portageq-${FLAGS_board} envvar 'PORTAGE_BINHOST')
178info "PORTAGE_BINHOST: ${PORTAGE_BINHOST}"
179
Chris Masonebbccc242014-02-08 16:23:53 -0800180
Mike Frysinger4114c792012-09-13 22:33:12 -0400181# Setup all the emerge command/flags.
Mike Frysinger697ab962019-11-04 20:02:43 -0500182EMERGE_FLAGS=( -uDNv --backtrack=30 --newrepo )
Mike Frysinger4114c792012-09-13 22:33:12 -0400183
Bertrand SIMONNET4dda4f52015-03-19 13:40:58 -0700184EMERGE_CMD=(
185 "${CHROMITE_BIN}/parallel_emerge"
186 --board=${FLAGS_board}
187)
188
Chris McDonald5405a802019-11-12 13:58:38 -0700189if [[ "${FLAGS_use_any_chrome}" -eq "${FLAGS_TRUE}" ]]; then
190 EMERGE_CMD+=( "--force-remote-binary=chromeos-base/chromeos-chrome" )
191fi
192
Aviv Keshet8aa379b2016-02-29 10:00:05 -0800193if [[ "${FLAGS_buildretry}" -eq "${FLAGS_FALSE}" ]]; then
194 EMERGE_CMD+=( --retries=0 )
195fi
Brian Harring17c1fe82012-12-05 21:12:31 -0800196
Mike Frysinger4114c792012-09-13 22:33:12 -0400197EMERGE_CMD+=( ${EXTRA_BOARD_FLAGS} )
Brian Harringcb782242011-12-13 19:48:44 -0800198
David James17c622a2012-03-07 09:34:08 -0800199if [[ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ||
Thiago Goncales5ad4ca02013-07-12 10:55:11 -0700200 "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ||
201 "${FLAGS_usepkgonly}" -eq "${FLAGS_TRUE}" ]]; then
Brian Harringcb782242011-12-13 19:48:44 -0800202 # Use binary packages. Include all build-time dependencies,
203 # so as to avoid unnecessary differences between source
204 # and binary builds.
Thiago Goncales5ad4ca02013-07-12 10:55:11 -0700205 EMERGE_FLAGS+=( --getbinpkg --with-bdeps y )
206 if [[ ${FLAGS_usepkgonly} -eq ${FLAGS_TRUE} ]]; then
207 EMERGE_FLAGS+=( --usepkgonly )
208 else
209 EMERGE_FLAGS+=( --usepkg )
210 fi
Brian Harringcb782242011-12-13 19:48:44 -0800211fi
212
213if [[ "${FLAGS_jobs}" -ne -1 ]]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400214 EMERGE_FLAGS+=( --jobs=${FLAGS_jobs} )
215fi
216
217if [[ "${FLAGS_norebuild}" -eq "${FLAGS_FALSE}" ]]; then
Chris McDonald00dcd722019-10-17 13:53:28 -0600218 EMERGE_FLAGS+=( --rebuild-if-new-rev )
Mike Frysinger4114c792012-09-13 22:33:12 -0400219fi
Bertrand SIMONNET4dda4f52015-03-19 13:40:58 -0700220if [[ "${FLAGS_showoutput}" -eq "${FLAGS_TRUE}" ]]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400221 EMERGE_FLAGS+=( --show-output )
Brian Harringcb782242011-12-13 19:48:44 -0800222fi
223
224if [[ "${FLAGS_withdebug}" -eq "${FLAGS_FALSE}" ]]; then
225 export USE="${USE} -cros-debug"
226fi
227
Chris Ching4bc95a12016-11-22 13:44:13 -0700228# TODO Handle case where passed default value, but events not enabled
229if [[ "${FLAGS_eventfile}" != "${DEFAULT_EVENT_FILE}" ]]; then
230 FLAGS_withevents="${FLAGS_TRUE}"
231fi
232
233if [[ "${FLAGS_withevents}" -eq "${FLAGS_TRUE}" ]]; then
234 mkdir -p "$(dirname $FLAGS_eventfile)"
235 EMERGE_FLAGS+=( "--eventlogfile=${FLAGS_eventfile}" )
236fi
237
Mike Frysinger4114c792012-09-13 22:33:12 -0400238# Figure out which packages we should be building.
Mike Frysinger76452ba2012-09-13 22:45:34 -0400239PACKAGES=( "$@" )
Daniel Wangaf4d0012015-07-17 11:52:05 -0700240FORCE_LOCAL_BUILD_PKGS=()
Mike Frysinger76452ba2012-09-13 22:45:34 -0400241if [[ $# -eq 0 ]]; then
Mike Frysinger22621952014-04-01 17:41:20 -0400242 PACKAGES=( virtual/target-os )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400243 if [[ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]]; then
Mike Frysingerde399282014-04-15 18:26:04 -0400244 PACKAGES+=( virtual/target-os-dev )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400245 fi
246 if [[ "${FLAGS_withfactory}" -eq "${FLAGS_TRUE}" ]]; then
Hung-Te Lin9b43ced2016-01-14 20:29:47 +0800247 PACKAGES+=( virtual/target-os-factory )
248 PACKAGES+=( virtual/target-os-factory-shim )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400249 fi
250 if [[ "${FLAGS_withtest}" -eq "${FLAGS_TRUE}" ]]; then
Mike Frysinger52669432014-05-05 14:34:09 -0400251 PACKAGES+=( virtual/target-os-test )
Daniel Wangaf4d0012015-07-17 11:52:05 -0700252 # chromeos-ssh-testkeys may generate ssh keys if the right USE flag is set.
253 # We force rebuilding this package from source every time, so that
254 # consecutive builds don't share ssh keys.
255 FORCE_LOCAL_BUILD_PKGS+=( chromeos-base/chromeos-ssh-testkeys )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400256 fi
257 if [[ "${FLAGS_withautotest}" -eq "${FLAGS_TRUE}" ]]; then
258 PACKAGES+=( chromeos-base/autotest-all )
259 fi
Brian Harringcb782242011-12-13 19:48:44 -0800260fi
261
Chris McDonaldac5d8632019-10-23 15:55:45 -0600262info "Rebuilding Portage cache"
263# Before running any emerge operations, regenerate the Portage dependency cache
264# in parallel.
Mike Frysinger61157612019-08-17 13:29:28 -0400265"${EMERGE_CMD[@]}" --regen --quiet
Chris McDonaldac5d8632019-10-23 15:55:45 -0600266
Brian Harringcb782242011-12-13 19:48:44 -0800267# Verify that all packages can be emerged from scratch, without any
268# backtracking. Only print the output if this step fails.
Mike Frysinger76452ba2012-09-13 22:45:34 -0400269info "Checking package dependencies are correct: ${PACKAGES[*]}"
David Jamesab9ca212012-11-06 11:06:07 -0800270if ! OUTPUT=$(emerge-${FLAGS_board} -pe --backtrack=0 \
271 "${PACKAGES[@]}" 2>&1); then
Brian Harringcb782242011-12-13 19:48:44 -0800272 printf "%s\n" "${OUTPUT}"
Brian Harring7f175a52012-03-02 05:37:00 -0800273 die_notrace "emerge detected broken ebuilds. See error message above."
Brian Harringcb782242011-12-13 19:48:44 -0800274fi
275
Mike Frysinger4114c792012-09-13 22:33:12 -0400276# Build cros_workon packages when they are changed.
277CROS_WORKON_PKGS=()
Mike Frysingerf4711422019-11-13 18:04:31 -0500278if [ "${FLAGS_workon}" -eq "${FLAGS_TRUE}" ]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400279 LIST_MODIFIED_PACKAGES="${CHROMITE_BIN}/cros_list_modified_packages"
Jason D. Clinton321e2f82017-08-09 16:21:23 -0600280 MODIFIED_PACKAGES=( $("${LIST_MODIFIED_PACKAGES}" --board=${FLAGS_board}) )
Gregory Meinke7851ece2018-05-09 13:34:06 -0600281 info "cros_workon modified packages '${MODIFIED_PACKAGES[*]}' detected"
Jason D. Clinton321e2f82017-08-09 16:21:23 -0600282 CROS_WORKON_PKGS+=( "${MODIFIED_PACKAGES[@]}" )
Mike Frysinger4114c792012-09-13 22:33:12 -0400283
David James4941c6b2014-02-03 16:24:59 -0800284 # TODO(anush): Make chrome a fake cros-workon package.
285 if [[ -n "${CHROME_ORIGIN}" ]]; then
286 CROS_WORKON_PKGS+=( chromeos-base/chromeos-chrome )
287 fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400288fi
289
Daniel Wangaf4d0012015-07-17 11:52:05 -0700290# cros_workon packages always have to be rebuilt.
Daniel Wang491f42a2015-08-20 12:29:59 -0700291FORCE_LOCAL_BUILD_PKGS+=( "${CROS_WORKON_PKGS[@]}" )
Daniel Wangaf4d0012015-07-17 11:52:05 -0700292
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600293if [[ -n "${FLAGS_board_root}" ]]; then
294 export ROOT="${FLAGS_board_root}"
295 export PORTAGE_CONFIGROOT="${ROOT}"
296 export SYSROOT="${ROOT}"
297 export PKGDIR="${ROOT}"/packages
298fi
299
300# Temporarily modify the emerge flags so we can calculate the revdeps
301# on the modified packages.
Gregory Meinke0766df42018-08-23 11:36:12 -0600302if [[ "${FLAGS_withrevdeps}" -eq "${FLAGS_TRUE}" ]]; then
Yves Arrouyec16e45e2018-08-31 08:37:15 -0700303 info "starting reverse dependency calculations ..."
Gregory Meinke0766df42018-08-23 11:36:12 -0600304 SIM_EMERGE_FLAGS=( "${EMERGE_FLAGS[@]}" --pretend --columns )
Gregory Meinkeee71dd12018-07-09 12:42:25 -0600305
Gregory Meinke0766df42018-08-23 11:36:12 -0600306 if [[ ${#PACKAGES[@]} -gt 0 ]]; then
307 SIM_EMERGE_FLAGS+=(
308 --reinstall-atoms="${PACKAGES[*]}"
309 --usepkg-exclude="${PACKAGES[*]}"
310 )
311 fi
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600312
Gregory Meinke0766df42018-08-23 11:36:12 -0600313 # Calculate only the ebuild changes from the emerge simulation ignoring
314 # the virtual packages and the forced rebuild of autotest-all package.
315 BASE_INSTALL_PKGS=( $( \
316 sudo -E "${EMERGE_CMD[@]}" "${SIM_EMERGE_FLAGS[@]}" "${PACKAGES[@]}" | \
317 sed -n -E '/^\[ebuild /{s:^[^]]+\] +::;s: .*::;p}' | \
318 grep -v -e '^virtual/' -e '^chromeos-base/autotest-all' | sort -u ) )
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600319
Gregory Meinke0766df42018-08-23 11:36:12 -0600320 MOD_PKGS=()
321 if [[ "${#BASE_INSTALL_PKGS[@]}" -gt 0 ]]; then
322 info "New packages being installed: ${BASE_INSTALL_PKGS[*]}."
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600323 # Convert specific versions into base package names
324 MOD_PKGS+=( $(\
Gregory Meinke0766df42018-08-23 11:36:12 -0600325 equery-${FLAGS_board} list -p -o --format='$category/$name' \
326 "${BASE_INSTALL_PKGS[@]}" | sort -u ) )
Mike Frysinger5a11e872018-09-05 16:29:02 -0400327 # Remove Chrome as rebuilding it is expensive and almost never makes sense.
328 # Ignore grep exit status in case chromeos-chrome is the only package.
Gregory Meinke0766df42018-08-23 11:36:12 -0600329 MOD_PKGS=( $(printf '%s\n' "${MOD_PKGS[@]}" | \
Mike Frysinger5a11e872018-09-05 16:29:02 -0400330 grep -v 'chromeos-base/chromeos-chrome' || :) )
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600331 fi
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600332
Gregory Meinke0766df42018-08-23 11:36:12 -0600333 FORCE_LOCAL_BUILD_PKGS+=( "${MOD_PKGS[@]}" )
334
335 if [[ "${#MOD_PKGS[@]}" -gt 0 ]]; then
336 info "calculating reverse dependencies on packages: ${MOD_PKGS[*]}"
337 REV_DEPS=( $(\
338 equery-${FLAGS_board} -q depends --indirect "${MOD_PKGS[@]}" |\
339 awk '{print $1}' | grep -v ^virtual/ | sort -u) )
340 if [[ "${#REV_DEPS[@]}" -gt 0 ]]; then
341 # Convert specific versions into base package names
342 RMOD_PKGS=( $(\
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600343 equery-${FLAGS_board} -q list -p -o --format='$category/$name' \
Gregory Meinke0766df42018-08-23 11:36:12 -0600344 "${REV_DEPS[@]}" | sort -u ) )
Mike Frysinger5a11e872018-09-05 16:29:02 -0400345 # Remove Chrome as rebuilding it is expensive and almost never makes
346 # sense. Ignore grep exit status in case chromeos-chrome is the only
347 # package.
Gregory Meinke0766df42018-08-23 11:36:12 -0600348 RMOD_PKGS=( $(printf '%s\n' "${RMOD_PKGS[@]}" | \
Mike Frysinger5a11e872018-09-05 16:29:02 -0400349 grep -v 'chromeos-base/chromeos-chrome' || :) )
Gregory Meinke0766df42018-08-23 11:36:12 -0600350 info "final reverse dependencies that will be rebuilt: ${RMOD_PKGS[*]}"
351 FORCE_LOCAL_BUILD_PKGS+=( "${RMOD_PKGS[@]}" )
352 fi
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600353 fi
Gregory Meinke0766df42018-08-23 11:36:12 -0600354fi # end FLAGS_withrevdeps
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600355
Daniel Wangaf4d0012015-07-17 11:52:05 -0700356if [[ ${#FORCE_LOCAL_BUILD_PKGS[@]} -gt 0 ]]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400357 EMERGE_FLAGS+=(
Daniel Wangaf4d0012015-07-17 11:52:05 -0700358 --reinstall-atoms="${FORCE_LOCAL_BUILD_PKGS[*]}"
359 --usepkg-exclude="${FORCE_LOCAL_BUILD_PKGS[*]}"
Mike Frysinger4114c792012-09-13 22:33:12 -0400360 )
David James710a7d12011-12-21 15:57:02 -0800361fi
Matt Tennant298f61a2012-06-25 21:54:33 -0700362
Mike Frysinger76452ba2012-09-13 22:45:34 -0400363info "Merging board packages now"
Matt Tennant298f61a2012-06-25 21:54:33 -0700364(
Hidehiko Abe7a41d342017-03-29 21:19:16 +0900365 # Support goma on bots. This has to run in subshell, otherwise EXIT trap
366 # handler is overwritten.
367 if [[ "${FLAGS_run_goma}" -eq "${FLAGS_TRUE}" ]]; then
368 info "Starting goma compiler_proxy."
369 goma_ctl="${GOMA_DIR:-${HOME}/goma}/goma_ctl.py"
Mike Frysingeraa84e432019-09-24 14:06:27 -0400370 # TODO(crbug.com/1007384): Stop forcing Python 2.
371 EPYTHON="python2" "${goma_ctl}" restart
372 trap "EPYTHON=python2 '${goma_ctl}' stop" EXIT
Hidehiko Abe7a41d342017-03-29 21:19:16 +0900373 fi
374
Chris McDonald3b359902019-08-12 13:02:12 -0600375 sudo -E "${EMERGE_CMD[@]}" "${EMERGE_FLAGS[@]}" "${PACKAGES[@]}"
Matt Tennant298f61a2012-06-25 21:54:33 -0700376)
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 -0700386command_completed
Brian Harringcb782242011-12-13 19:48:44 -0800387echo "Done"