blob: 11aad0fa631c8a4ef38cba6a7bb9983ef9f14ec3 [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_string eventfile "${DEFAULT_EVENT_FILE}" \
30 "Define the file that event logs will be written."
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -060031DEFINE_boolean withrevdeps "${FLAGS_TRUE}" \
Gregory Meinke0766df42018-08-23 11:36:12 -060032 "Calculate reverse dependencies on changed ebuilds."
Mike Frysinger38653b02019-10-04 13:56:29 -040033DEFINE_boolean autosetgov "${FLAGS_FALSE}" \
34 "Automatically set cpu governor to 'performance'."
Chris McDonald5405a802019-11-12 13:58:38 -070035DEFINE_boolean use_any_chrome "${FLAGS_TRUE}" \
36 "Use any Chrome prebuilt available, even if the prebuilt doesn't match exactly."
Thiago Goncales5ad4ca02013-07-12 10:55:11 -070037
38# The --board_root flag specifies the environment variables ROOT and PKGDIR.
39# This allows fetching and emerging of all packages to specified board_root.
40# Note that --board_root will setup the board normally in /build/$BOARD, if it's
41# not setup yet. It also expects the toolchain to already be installed in the
42# board_root. --usepkgonly and --norebuild are required, because building is not
43# supported when board_root is set.
44# enforce this)."
45DEFINE_string board_root "" \
46 "Emerge packages to board_root."
David James855afb72012-03-14 20:04:59 -070047
Mike Frysinger76452ba2012-09-13 22:45:34 -040048FLAGS_HELP="usage: $(basename $0) [flags] [packages]
David James855afb72012-03-14 20:04:59 -070049
50build_packages updates the set of binary packages needed by Chrome OS. It will
51cross compile all packages that have been updated into the given target's root
52and build binary packages as a side-effect. The output packages will be picked
53up by the build_image script to put together a bootable Chrome OS image.
54
Mike Frysinger76452ba2012-09-13 22:45:34 -040055If [packages] are specified, only build those specific packages (and any
56dependencies they might need).
57
David James855afb72012-03-14 20:04:59 -070058For the fastest builds, use --nowithautotest --noworkon.
59"
David James855afb72012-03-14 20:04:59 -070060
61# The following options are advanced options, only available to those willing
62# to read the source code. They are not shown in help output, since they are
63# not needed for the typical developer workflow.
Ryan Cuieb4595f2012-12-17 14:28:42 -080064DEFINE_string accept_licenses "" \
65 "Licenses to append to the accept list."
David James855afb72012-03-14 20:04:59 -070066DEFINE_integer jobs -1 \
67 "How many packages to build in parallel at maximum."
68DEFINE_boolean norebuild "${FLAGS_FALSE}" \
69 "Don't automatically rebuild dependencies."
Mike Frysinger839e82a2012-03-01 14:22:10 -050070DEFINE_boolean skip_chroot_upgrade "${FLAGS_FALSE}" \
71 "Don't run the chroot upgrade automatically; use with care."
David James855afb72012-03-14 20:04:59 -070072DEFINE_boolean skip_toolchain_update "${FLAGS_FALSE}" \
73 "Don't update toolchain automatically."
74DEFINE_boolean withdev "${FLAGS_TRUE}" \
75 "Build useful developer friendly utilities."
76DEFINE_boolean withdebug "${FLAGS_TRUE}" \
77 "Build debug versions of Chromium-OS-specific packages."
78DEFINE_boolean withfactory "${FLAGS_TRUE}" \
79 "Build factory installer."
80DEFINE_boolean withtest "${FLAGS_TRUE}" \
81 "Build packages required for testing."
Brian Harringcb782242011-12-13 19:48:44 -080082
David James17c622a2012-03-07 09:34:08 -080083# The --reuse_pkgs_from_local_boards flag tells Portage to share binary
84# packages between boards that are built locally, so that the total time
85# required to build several boards is reduced. This flag is only useful
86# when you are not able to use remote binary packages, since remote binary
87# packages are usually more up to date than anything you have locally.
Hidehiko Abe7a41d342017-03-29 21:19:16 +090088DEFINE_boolean reuse_pkgs_from_local_boards "${FLAGS_FALSE}" \
David James17c622a2012-03-07 09:34:08 -080089 "Bootstrap from local packages instead of remote packages."
90
Hidehiko Abe7a41d342017-03-29 21:19:16 +090091# --run_goma option is designed to be used on bots.
92# If you're trying to build pacakges with goma in your local dev env, this is
93# *not* the option you're looking for. Please see comments below.
94# This option; 1) starts goma, 2) builds packages (expecting that goma is
95# used), then 3) stops goma explicitly.
96# 3) is a request from the goma team, so that stats/logs can be taken.
97# Note: GOMA_DIR and GOMA_SERVICE_ACCOUNT_JSON_FILE are expected to be passed
98# via env var.
99#
100# In local dev env cases, compiler_proxy is expected to keep running.
101# In such a case;
102# $ python ${GOMA_DIR}/goma_ctl.py ensure_start
103# $ ./build_packages (... and options without --run_goma ...)
104# is an expected commandline sequence. If you set --run_goma flag while
105# compiler_proxy is already running, the existing compiler_proxy will be
106# stopped.
107DEFINE_boolean run_goma "${FLAGS_FALSE}" \
108 "If set to true, (re)starts goma, builds packages, and then stops goma."
109
Brian Harringcb782242011-12-13 19:48:44 -0800110# Parse command line
Brian Harringcb782242011-12-13 19:48:44 -0800111FLAGS "$@" || exit 1
112eval set -- "${FLAGS_ARGV}"
Brian Harringcb782242011-12-13 19:48:44 -0800113
114# Die on any errors.
Brian Harring7f175a52012-03-02 05:37:00 -0800115switch_to_strict_mode
Brian Harringcb782242011-12-13 19:48:44 -0800116
Alex Klein12b97722019-12-09 14:25:33 -0700117# This is a temporary measure to help the goma team check the configs while
118# they transition their backend service.
119# TODO(crbug.com/1032290): Delete after the goma RBE transition is complete.
120if [[ "${FLAGS_run_goma}" -eq "${FLAGS_TRUE}" ]]; then
121 info "Environment:"
122 env
123 info "End Environment."
124fi
125
Brian Harringcb782242011-12-13 19:48:44 -0800126# Right now build_packages has to be run from scripts/
127. ${SRC_ROOT}/third_party/chromiumos-overlay/chromeos/config/chromeos_version.sh
128
Mike Frysinger38653b02019-10-04 13:56:29 -0400129# On some systems, powersave can take a long time to ramp up. Inform the user
130# so they can get faster builds. https://crbug.com/1008932
131if grep -qs powersave \
132 /sys/devices/system/cpu/cpufreq/policy*/scaling_governor; then
133 # Make sure we can actually support "performance".
134 if grep -qs performance \
135 /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors; then
136 if [[ "${FLAGS_autosetgov}" -eq "${FLAGS_TRUE}" ]]; then
137 info "Temporarily setting cpu governor to 'performance'"
138 trap "sudo cpupower -c all frequency-set -g powersave >&/dev/null" EXIT
139 sudo cpupower -c all frequency-set -g performance >&/dev/null
140 else
141 warn "Current CPU governor set to 'powersave' which can slow down builds."
142 warn "Use --autosetgov to automatically (and temporarily) switch to" \
143 "'performance'."
144 fi
145 fi
146fi
147
Brian Harringcb782242011-12-13 19:48:44 -0800148if [[ -z "${FLAGS_board}" ]]; then
149 echo "Error: --board is required."
150 exit 1
151fi
152
Mike Frysinger4114c792012-09-13 22:33:12 -0400153# Before we can run any tools, we need to update chroot or setup_board.
154UPDATE_ARGS=()
Ryan Cuieb4595f2012-12-17 14:28:42 -0800155if [[ -n ${FLAGS_accept_licenses} ]]; then
Alex Kleind65766f2019-01-11 14:57:34 -0700156 UPDATE_ARGS+=( --accept-licenses "${FLAGS_accept_licenses}" )
Ryan Cuieb4595f2012-12-17 14:28:42 -0800157fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400158if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then
159 UPDATE_ARGS+=( --usepkg )
160else
161 UPDATE_ARGS+=( --nousepkg )
162fi
163if [[ "${FLAGS_jobs}" -ne -1 ]]; then
164 UPDATE_ARGS+=( --jobs=${FLAGS_jobs} )
165fi
166if [ "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ]; then
Alex Kleind65766f2019-01-11 14:57:34 -0700167 UPDATE_ARGS+=( --reuse-pkgs-from-local-boards )
Mike Frysinger4114c792012-09-13 22:33:12 -0400168fi
169if [ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_TRUE}" ]; then
Alex Kleind65766f2019-01-11 14:57:34 -0700170 UPDATE_ARGS+=( --skip-toolchain-update )
Mike Frysinger4114c792012-09-13 22:33:12 -0400171fi
172if [ "${FLAGS_skip_chroot_upgrade}" -eq "${FLAGS_TRUE}" ]; then
Alex Kleind65766f2019-01-11 14:57:34 -0700173 UPDATE_ARGS+=( --skip-chroot-upgrade )
Mike Frysinger4114c792012-09-13 22:33:12 -0400174fi
Bertrand SIMONNET10ede912014-10-09 16:21:13 -0700175if [[ -n ${FLAGS_board_root} ]]; then
Alex Kleind65766f2019-01-11 14:57:34 -0700176 UPDATE_ARGS+=( --board-root "${FLAGS_board_root}" )
Bertrand SIMONNET10ede912014-10-09 16:21:13 -0700177fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400178
Alex Kleind65766f2019-01-11 14:57:34 -0700179setup_board --quiet --board=${FLAGS_board} "${UPDATE_ARGS[@]}"
Mike Frysinger4114c792012-09-13 22:33:12 -0400180
Chris Masonebbccc242014-02-08 16:23:53 -0800181sudo_clear_shadow_locks "/build/${FLAGS_board}"
Ned Nguyen9af21f52019-04-05 11:30:52 -0600182PORTAGE_BINHOST=$(portageq-${FLAGS_board} envvar 'PORTAGE_BINHOST')
183info "PORTAGE_BINHOST: ${PORTAGE_BINHOST}"
184
Chris Masonebbccc242014-02-08 16:23:53 -0800185
Mike Frysinger4114c792012-09-13 22:33:12 -0400186# Setup all the emerge command/flags.
Mike Frysinger697ab962019-11-04 20:02:43 -0500187EMERGE_FLAGS=( -uDNv --backtrack=30 --newrepo )
Mike Frysinger4114c792012-09-13 22:33:12 -0400188
Bertrand SIMONNET4dda4f52015-03-19 13:40:58 -0700189EMERGE_CMD=(
190 "${CHROMITE_BIN}/parallel_emerge"
191 --board=${FLAGS_board}
192)
193
Chris McDonald5405a802019-11-12 13:58:38 -0700194if [[ "${FLAGS_use_any_chrome}" -eq "${FLAGS_TRUE}" ]]; then
Alex Kleinac67cdf2020-04-16 12:58:34 -0600195 EMERGE_CMD+=(
196 "--force-remote-binary=chromeos-base/chromeos-chrome"
197 "--force-remote-binary=chromeos-base/chrome-icu"
198 )
Chris McDonald5405a802019-11-12 13:58:38 -0700199fi
200
Mike Frysinger4114c792012-09-13 22:33:12 -0400201EMERGE_CMD+=( ${EXTRA_BOARD_FLAGS} )
Brian Harringcb782242011-12-13 19:48:44 -0800202
David James17c622a2012-03-07 09:34:08 -0800203if [[ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ||
Thiago Goncales5ad4ca02013-07-12 10:55:11 -0700204 "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ||
205 "${FLAGS_usepkgonly}" -eq "${FLAGS_TRUE}" ]]; then
Brian Harringcb782242011-12-13 19:48:44 -0800206 # Use binary packages. Include all build-time dependencies,
207 # so as to avoid unnecessary differences between source
208 # and binary builds.
Thiago Goncales5ad4ca02013-07-12 10:55:11 -0700209 EMERGE_FLAGS+=( --getbinpkg --with-bdeps y )
210 if [[ ${FLAGS_usepkgonly} -eq ${FLAGS_TRUE} ]]; then
211 EMERGE_FLAGS+=( --usepkgonly )
212 else
213 EMERGE_FLAGS+=( --usepkg )
214 fi
Brian Harringcb782242011-12-13 19:48:44 -0800215fi
216
217if [[ "${FLAGS_jobs}" -ne -1 ]]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400218 EMERGE_FLAGS+=( --jobs=${FLAGS_jobs} )
219fi
220
221if [[ "${FLAGS_norebuild}" -eq "${FLAGS_FALSE}" ]]; then
Chris McDonald00dcd722019-10-17 13:53:28 -0600222 EMERGE_FLAGS+=( --rebuild-if-new-rev )
Mike Frysinger4114c792012-09-13 22:33:12 -0400223fi
Bertrand SIMONNET4dda4f52015-03-19 13:40:58 -0700224if [[ "${FLAGS_showoutput}" -eq "${FLAGS_TRUE}" ]]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400225 EMERGE_FLAGS+=( --show-output )
Brian Harringcb782242011-12-13 19:48:44 -0800226fi
227
228if [[ "${FLAGS_withdebug}" -eq "${FLAGS_FALSE}" ]]; then
229 export USE="${USE} -cros-debug"
230fi
231
Mike Frysinger4114c792012-09-13 22:33:12 -0400232# Figure out which packages we should be building.
Mike Frysinger76452ba2012-09-13 22:45:34 -0400233PACKAGES=( "$@" )
Alex Kleinbdd2d762020-02-12 11:53:08 -0700234# Force rebuild chromeos-config because it is extremely cheap, and we do not
235# want to reuse stale configs.
236FORCE_LOCAL_BUILD_PKGS=( chromeos-base/chromeos-config )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400237if [[ $# -eq 0 ]]; then
Mike Frysinger22621952014-04-01 17:41:20 -0400238 PACKAGES=( virtual/target-os )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400239 if [[ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]]; then
Mike Frysingerde399282014-04-15 18:26:04 -0400240 PACKAGES+=( virtual/target-os-dev )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400241 fi
242 if [[ "${FLAGS_withfactory}" -eq "${FLAGS_TRUE}" ]]; then
Hung-Te Lin9b43ced2016-01-14 20:29:47 +0800243 PACKAGES+=( virtual/target-os-factory )
244 PACKAGES+=( virtual/target-os-factory-shim )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400245 fi
246 if [[ "${FLAGS_withtest}" -eq "${FLAGS_TRUE}" ]]; then
Mike Frysinger52669432014-05-05 14:34:09 -0400247 PACKAGES+=( virtual/target-os-test )
Daniel Wangaf4d0012015-07-17 11:52:05 -0700248 # chromeos-ssh-testkeys may generate ssh keys if the right USE flag is set.
249 # We force rebuilding this package from source every time, so that
250 # consecutive builds don't share ssh keys.
251 FORCE_LOCAL_BUILD_PKGS+=( chromeos-base/chromeos-ssh-testkeys )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400252 fi
253 if [[ "${FLAGS_withautotest}" -eq "${FLAGS_TRUE}" ]]; then
254 PACKAGES+=( chromeos-base/autotest-all )
255 fi
Brian Harringcb782242011-12-13 19:48:44 -0800256fi
257
Chris McDonaldac5d8632019-10-23 15:55:45 -0600258info "Rebuilding Portage cache"
259# Before running any emerge operations, regenerate the Portage dependency cache
260# in parallel.
Mike Frysinger61157612019-08-17 13:29:28 -0400261"${EMERGE_CMD[@]}" --regen --quiet
Chris McDonaldac5d8632019-10-23 15:55:45 -0600262
Brian Harringcb782242011-12-13 19:48:44 -0800263# Verify that all packages can be emerged from scratch, without any
264# backtracking. Only print the output if this step fails.
Mike Frysinger76452ba2012-09-13 22:45:34 -0400265info "Checking package dependencies are correct: ${PACKAGES[*]}"
David Jamesab9ca212012-11-06 11:06:07 -0800266if ! OUTPUT=$(emerge-${FLAGS_board} -pe --backtrack=0 \
267 "${PACKAGES[@]}" 2>&1); then
Brian Harringcb782242011-12-13 19:48:44 -0800268 printf "%s\n" "${OUTPUT}"
Brian Harring7f175a52012-03-02 05:37:00 -0800269 die_notrace "emerge detected broken ebuilds. See error message above."
Brian Harringcb782242011-12-13 19:48:44 -0800270fi
271
Mike Frysinger4114c792012-09-13 22:33:12 -0400272# Build cros_workon packages when they are changed.
273CROS_WORKON_PKGS=()
Mike Frysingerf4711422019-11-13 18:04:31 -0500274if [ "${FLAGS_workon}" -eq "${FLAGS_TRUE}" ]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400275 LIST_MODIFIED_PACKAGES="${CHROMITE_BIN}/cros_list_modified_packages"
Jason D. Clinton321e2f82017-08-09 16:21:23 -0600276 MODIFIED_PACKAGES=( $("${LIST_MODIFIED_PACKAGES}" --board=${FLAGS_board}) )
Gregory Meinke7851ece2018-05-09 13:34:06 -0600277 info "cros_workon modified packages '${MODIFIED_PACKAGES[*]}' detected"
Jason D. Clinton321e2f82017-08-09 16:21:23 -0600278 CROS_WORKON_PKGS+=( "${MODIFIED_PACKAGES[@]}" )
Mike Frysinger4114c792012-09-13 22:33:12 -0400279
David James4941c6b2014-02-03 16:24:59 -0800280 # TODO(anush): Make chrome a fake cros-workon package.
281 if [[ -n "${CHROME_ORIGIN}" ]]; then
Alex Kleinac67cdf2020-04-16 12:58:34 -0600282 CROS_WORKON_PKGS+=( chromeos-base/chromeos-chrome chromeos-base/chrome-icu )
David James4941c6b2014-02-03 16:24:59 -0800283 fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400284fi
285
Daniel Wangaf4d0012015-07-17 11:52:05 -0700286# cros_workon packages always have to be rebuilt.
Daniel Wang491f42a2015-08-20 12:29:59 -0700287FORCE_LOCAL_BUILD_PKGS+=( "${CROS_WORKON_PKGS[@]}" )
Daniel Wangaf4d0012015-07-17 11:52:05 -0700288
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600289if [[ -n "${FLAGS_board_root}" ]]; then
290 export ROOT="${FLAGS_board_root}"
291 export PORTAGE_CONFIGROOT="${ROOT}"
292 export SYSROOT="${ROOT}"
293 export PKGDIR="${ROOT}"/packages
294fi
295
296# Temporarily modify the emerge flags so we can calculate the revdeps
297# on the modified packages.
Gregory Meinke0766df42018-08-23 11:36:12 -0600298if [[ "${FLAGS_withrevdeps}" -eq "${FLAGS_TRUE}" ]]; then
Yves Arrouyec16e45e2018-08-31 08:37:15 -0700299 info "starting reverse dependency calculations ..."
Gregory Meinke0766df42018-08-23 11:36:12 -0600300 SIM_EMERGE_FLAGS=( "${EMERGE_FLAGS[@]}" --pretend --columns )
Gregory Meinkeee71dd12018-07-09 12:42:25 -0600301
Gregory Meinke0766df42018-08-23 11:36:12 -0600302 if [[ ${#PACKAGES[@]} -gt 0 ]]; then
303 SIM_EMERGE_FLAGS+=(
304 --reinstall-atoms="${PACKAGES[*]}"
305 --usepkg-exclude="${PACKAGES[*]}"
306 )
307 fi
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600308
Gregory Meinke0766df42018-08-23 11:36:12 -0600309 # Calculate only the ebuild changes from the emerge simulation ignoring
310 # the virtual packages and the forced rebuild of autotest-all package.
311 BASE_INSTALL_PKGS=( $( \
312 sudo -E "${EMERGE_CMD[@]}" "${SIM_EMERGE_FLAGS[@]}" "${PACKAGES[@]}" | \
313 sed -n -E '/^\[ebuild /{s:^[^]]+\] +::;s: .*::;p}' | \
314 grep -v -e '^virtual/' -e '^chromeos-base/autotest-all' | sort -u ) )
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600315
Gregory Meinke0766df42018-08-23 11:36:12 -0600316 MOD_PKGS=()
317 if [[ "${#BASE_INSTALL_PKGS[@]}" -gt 0 ]]; then
318 info "New packages being installed: ${BASE_INSTALL_PKGS[*]}."
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600319 # Convert specific versions into base package names
320 MOD_PKGS+=( $(\
Gregory Meinke0766df42018-08-23 11:36:12 -0600321 equery-${FLAGS_board} list -p -o --format='$category/$name' \
322 "${BASE_INSTALL_PKGS[@]}" | sort -u ) )
Mike Frysinger5a11e872018-09-05 16:29:02 -0400323 # Remove Chrome as rebuilding it is expensive and almost never makes sense.
324 # Ignore grep exit status in case chromeos-chrome is the only package.
Gregory Meinke0766df42018-08-23 11:36:12 -0600325 MOD_PKGS=( $(printf '%s\n' "${MOD_PKGS[@]}" | \
Alex Kleinac67cdf2020-04-16 12:58:34 -0600326 grep -v \
327 -e 'chromeos-base/chrome-icu' \
328 -e 'chromeos-base/chromeos-chrome' || :) )
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600329 fi
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600330
Gregory Meinke0766df42018-08-23 11:36:12 -0600331 FORCE_LOCAL_BUILD_PKGS+=( "${MOD_PKGS[@]}" )
332
333 if [[ "${#MOD_PKGS[@]}" -gt 0 ]]; then
334 info "calculating reverse dependencies on packages: ${MOD_PKGS[*]}"
335 REV_DEPS=( $(\
336 equery-${FLAGS_board} -q depends --indirect "${MOD_PKGS[@]}" |\
337 awk '{print $1}' | grep -v ^virtual/ | sort -u) )
338 if [[ "${#REV_DEPS[@]}" -gt 0 ]]; then
339 # Convert specific versions into base package names
340 RMOD_PKGS=( $(\
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600341 equery-${FLAGS_board} -q list -p -o --format='$category/$name' \
Gregory Meinke0766df42018-08-23 11:36:12 -0600342 "${REV_DEPS[@]}" | sort -u ) )
Mike Frysinger5a11e872018-09-05 16:29:02 -0400343 # Remove Chrome as rebuilding it is expensive and almost never makes
344 # sense. Ignore grep exit status in case chromeos-chrome is the only
345 # package.
Gregory Meinke0766df42018-08-23 11:36:12 -0600346 RMOD_PKGS=( $(printf '%s\n' "${RMOD_PKGS[@]}" | \
Alex Kleinac67cdf2020-04-16 12:58:34 -0600347 grep -v \
348 -e 'chromeos-base/chrome-icu' \
349 -e '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
Chris McDonald33cabb02019-12-13 14:17:08 -0700363# A list of critical system packages that should never be incidentally
364# reinstalled as a side effect of build_packages. All packages in this list
365# are special cased to prefer matching installed versions, overriding the
366# typical logic of upgrading to the newest available version.
367#
368# This list can't include any package that gets installed to a board!
369# Packages such as LLVM or binutils must not be in this list as the normal
370# rebuild logic must still apply to them for board targets.
371#
372# TODO(crbug/1050752): Remove this list and the corresponding arguments
373# to `emerge` below once we figure out how to exclude toolchain packages from
374# being upgraded transitively via BDEPEND relations.
375CRITICAL_SDK_PACKAGES=(
376 "sys-libs/glibc"
377 "sys-devel/gcc"
378)
379
Mike Frysinger76452ba2012-09-13 22:45:34 -0400380info "Merging board packages now"
Matt Tennant298f61a2012-06-25 21:54:33 -0700381(
Hidehiko Abe7a41d342017-03-29 21:19:16 +0900382 # Support goma on bots. This has to run in subshell, otherwise EXIT trap
383 # handler is overwritten.
384 if [[ "${FLAGS_run_goma}" -eq "${FLAGS_TRUE}" ]]; then
385 info "Starting goma compiler_proxy."
386 goma_ctl="${GOMA_DIR:-${HOME}/goma}/goma_ctl.py"
Mike Frysingerea21dea2020-02-20 01:15:24 -0500387 "${goma_ctl}" restart
388 trap "'${goma_ctl}' stop" EXIT
Hidehiko Abe7a41d342017-03-29 21:19:16 +0900389 fi
390
Chris McDonald33cabb02019-12-13 14:17:08 -0700391 sudo -E "${EMERGE_CMD[@]}" "${EMERGE_FLAGS[@]}" "${PACKAGES[@]}" \
392 --useoldpkg-atoms="${CRITICAL_SDK_PACKAGES[*]}" \
393 --rebuild-exclude="${CRITICAL_SDK_PACKAGES[*]}"
Matt Tennant298f61a2012-06-25 21:54:33 -0700394)
395
Brian Harringcb782242011-12-13 19:48:44 -0800396echo "Builds complete"
Bertrand SIMONNETc7a46e22014-12-11 15:58:11 -0800397
398if [[ ${FLAGS_withdebugsymbols} -eq ${FLAGS_TRUE} ]]; then
399 info "fetching the debug symbols"
Mike Frysinger66accd22017-09-13 03:50:30 -0400400 sudo -E "${CHROMITE_BIN}/cros_install_debug_syms" \
Bertrand SIMONNETc7a46e22014-12-11 15:58:11 -0800401 "--board=${FLAGS_board}" "--all"
402fi
403
Matt Tennant298f61a2012-06-25 21:54:33 -0700404command_completed
Brian Harringcb782242011-12-13 19:48:44 -0800405echo "Done"