blob: beee9318c83a30b68fe10d6712e2219cb922732b [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."
Alex Kleinf61b5372020-04-16 17:02:33 -060037DEFINE_boolean cleanbuild "${FLAGS_FALSE}" \
38 "Perform a clean build; delete sysroot if it exists before building."
Alex Klein80abe722020-04-29 11:13:43 -060039DEFINE_boolean internal "${FLAGS_FALSE}" \
40 "Build the internal version of chrome (set the chrome_internal USE flag)."
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"
David James855afb72012-03-14 20:04:59 -070064
65# The following options are advanced options, only available to those willing
66# to read the source code. They are not shown in help output, since they are
67# not needed for the typical developer workflow.
Ryan Cuieb4595f2012-12-17 14:28:42 -080068DEFINE_string accept_licenses "" \
69 "Licenses to append to the accept list."
David James855afb72012-03-14 20:04:59 -070070DEFINE_integer jobs -1 \
71 "How many packages to build in parallel at maximum."
72DEFINE_boolean norebuild "${FLAGS_FALSE}" \
73 "Don't automatically rebuild dependencies."
Mike Frysinger839e82a2012-03-01 14:22:10 -050074DEFINE_boolean skip_chroot_upgrade "${FLAGS_FALSE}" \
75 "Don't run the chroot upgrade automatically; use with care."
Alex Klein1093ad42021-03-19 10:06:13 -060076DEFINE_boolean skip_setup_board "${FLAGS_FALSE}" \
Michael Mortensena07f5a72021-04-09 11:55:59 -060077 "Don't run setup_board. Implies skip_chroot_upgrade and" \
78 "skip_toolchain_update."
David James855afb72012-03-14 20:04:59 -070079DEFINE_boolean skip_toolchain_update "${FLAGS_FALSE}" \
80 "Don't update toolchain automatically."
81DEFINE_boolean withdev "${FLAGS_TRUE}" \
82 "Build useful developer friendly utilities."
83DEFINE_boolean withdebug "${FLAGS_TRUE}" \
84 "Build debug versions of Chromium-OS-specific packages."
85DEFINE_boolean withfactory "${FLAGS_TRUE}" \
86 "Build factory installer."
87DEFINE_boolean withtest "${FLAGS_TRUE}" \
88 "Build packages required for testing."
Alex Klein32d4d4c2021-03-08 16:16:02 -070089DEFINE_boolean expandedbinhosts "${FLAGS_FALSE}" \
90 "Allow expanded binhost inheritance."
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
Alex Kleindfa7bfa2020-04-20 12:55:22 -0600126# Chrome packages that need to be treated the same. These are the chrome and
127# chrome follow-on packages that share the same version as chrome and are
128# updated in lock step.
129CHROME_PACKAGES=(
130 "chromeos-base/chromeos-chrome"
131 "chromeos-base/chrome-icu"
132)
133
Alex Klein80abe722020-04-29 11:13:43 -0600134if [[ "${FLAGS_internal}" -eq "${FLAGS_TRUE}" ]]; then
135 export USE="${USE} chrome_internal"
136fi
137
Alex Klein12b97722019-12-09 14:25:33 -0700138# This is a temporary measure to help the goma team check the configs while
139# they transition their backend service.
140# TODO(crbug.com/1032290): Delete after the goma RBE transition is complete.
141if [[ "${FLAGS_run_goma}" -eq "${FLAGS_TRUE}" ]]; then
142 info "Environment:"
143 env
144 info "End Environment."
145fi
146
Brian Harringcb782242011-12-13 19:48:44 -0800147# Right now build_packages has to be run from scripts/
148. ${SRC_ROOT}/third_party/chromiumos-overlay/chromeos/config/chromeos_version.sh
149
Mike Frysinger38653b02019-10-04 13:56:29 -0400150# On some systems, powersave can take a long time to ramp up. Inform the user
151# so they can get faster builds. https://crbug.com/1008932
152if grep -qs powersave \
153 /sys/devices/system/cpu/cpufreq/policy*/scaling_governor; then
154 # Make sure we can actually support "performance".
155 if grep -qs performance \
156 /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors; then
157 if [[ "${FLAGS_autosetgov}" -eq "${FLAGS_TRUE}" ]]; then
158 info "Temporarily setting cpu governor to 'performance'"
159 trap "sudo cpupower -c all frequency-set -g powersave >&/dev/null" EXIT
160 sudo cpupower -c all frequency-set -g performance >&/dev/null
161 else
162 warn "Current CPU governor set to 'powersave' which can slow down builds."
163 warn "Use --autosetgov to automatically (and temporarily) switch to" \
164 "'performance'."
165 fi
166 fi
167fi
168
Brian Harringcb782242011-12-13 19:48:44 -0800169if [[ -z "${FLAGS_board}" ]]; then
170 echo "Error: --board is required."
171 exit 1
172fi
173
Alex Klein1093ad42021-03-19 10:06:13 -0600174if [[ "${FLAGS_skip_setup_board}" -eq "${FLAGS_FALSE}" ]]; then
175 # Before we can run any tools, we need to update chroot or setup_board.
176 UPDATE_ARGS=()
177 if [[ -n ${FLAGS_accept_licenses} ]]; then
178 UPDATE_ARGS+=( --accept-licenses "${FLAGS_accept_licenses}" )
179 fi
180 if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then
181 UPDATE_ARGS+=( --usepkg )
182 else
183 UPDATE_ARGS+=( --nousepkg )
184 fi
185 if [[ "${FLAGS_jobs}" -ne -1 ]]; then
186 UPDATE_ARGS+=( --jobs=${FLAGS_jobs} )
187 fi
188 if [ "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ]; then
189 UPDATE_ARGS+=( --reuse-pkgs-from-local-boards )
190 fi
191 if [ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_TRUE}" ]; then
192 UPDATE_ARGS+=( --skip-toolchain-update )
193 fi
194 if [ "${FLAGS_skip_chroot_upgrade}" -eq "${FLAGS_TRUE}" ]; then
195 UPDATE_ARGS+=( --skip-chroot-upgrade )
196 fi
197 if [[ -n ${FLAGS_board_root} ]]; then
198 UPDATE_ARGS+=( --board-root "${FLAGS_board_root}" )
199 fi
200 if [ "${FLAGS_cleanbuild}" -eq "${FLAGS_TRUE}" ]; then
201 UPDATE_ARGS+=( --force )
202 fi
203 if [[ "${FLAGS_expandedbinhosts}" -eq "${FLAGS_TRUE}" ]]; then
204 UPDATE_ARGS+=( --more-binhosts )
205 else
206 UPDATE_ARGS+=( --fewer-binhosts )
207 fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400208
Alex Klein1093ad42021-03-19 10:06:13 -0600209 setup_board --quiet --board=${FLAGS_board} "${UPDATE_ARGS[@]}"
210fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400211
Chris Masonebbccc242014-02-08 16:23:53 -0800212sudo_clear_shadow_locks "/build/${FLAGS_board}"
Ned Nguyen9af21f52019-04-05 11:30:52 -0600213PORTAGE_BINHOST=$(portageq-${FLAGS_board} envvar 'PORTAGE_BINHOST')
214info "PORTAGE_BINHOST: ${PORTAGE_BINHOST}"
215
Chris Masonebbccc242014-02-08 16:23:53 -0800216
Mike Frysinger4114c792012-09-13 22:33:12 -0400217# Setup all the emerge command/flags.
Mike Frysinger697ab962019-11-04 20:02:43 -0500218EMERGE_FLAGS=( -uDNv --backtrack=30 --newrepo )
Mike Frysinger4114c792012-09-13 22:33:12 -0400219
Bertrand SIMONNET4dda4f52015-03-19 13:40:58 -0700220EMERGE_CMD=(
221 "${CHROMITE_BIN}/parallel_emerge"
222 --board=${FLAGS_board}
223)
224
Chris McDonald5405a802019-11-12 13:58:38 -0700225if [[ "${FLAGS_use_any_chrome}" -eq "${FLAGS_TRUE}" ]]; then
Alex Kleindfa7bfa2020-04-20 12:55:22 -0600226 for pkg in "${CHROME_PACKAGES[@]}"; do
227 EMERGE_CMD+=( "--force-remote-binary=${pkg}" )
228 done
Chris McDonald5405a802019-11-12 13:58:38 -0700229fi
230
Mike Frysinger4114c792012-09-13 22:33:12 -0400231EMERGE_CMD+=( ${EXTRA_BOARD_FLAGS} )
Brian Harringcb782242011-12-13 19:48:44 -0800232
David James17c622a2012-03-07 09:34:08 -0800233if [[ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ||
Thiago Goncales5ad4ca02013-07-12 10:55:11 -0700234 "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ||
235 "${FLAGS_usepkgonly}" -eq "${FLAGS_TRUE}" ]]; then
Brian Harringcb782242011-12-13 19:48:44 -0800236 # Use binary packages. Include all build-time dependencies,
237 # so as to avoid unnecessary differences between source
238 # and binary builds.
Thiago Goncales5ad4ca02013-07-12 10:55:11 -0700239 EMERGE_FLAGS+=( --getbinpkg --with-bdeps y )
240 if [[ ${FLAGS_usepkgonly} -eq ${FLAGS_TRUE} ]]; then
241 EMERGE_FLAGS+=( --usepkgonly )
242 else
243 EMERGE_FLAGS+=( --usepkg )
244 fi
Brian Harringcb782242011-12-13 19:48:44 -0800245fi
246
247if [[ "${FLAGS_jobs}" -ne -1 ]]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400248 EMERGE_FLAGS+=( --jobs=${FLAGS_jobs} )
249fi
250
251if [[ "${FLAGS_norebuild}" -eq "${FLAGS_FALSE}" ]]; then
Chris McDonald00dcd722019-10-17 13:53:28 -0600252 EMERGE_FLAGS+=( --rebuild-if-new-rev )
Mike Frysinger4114c792012-09-13 22:33:12 -0400253fi
Bertrand SIMONNET4dda4f52015-03-19 13:40:58 -0700254if [[ "${FLAGS_showoutput}" -eq "${FLAGS_TRUE}" ]]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400255 EMERGE_FLAGS+=( --show-output )
Brian Harringcb782242011-12-13 19:48:44 -0800256fi
257
258if [[ "${FLAGS_withdebug}" -eq "${FLAGS_FALSE}" ]]; then
259 export USE="${USE} -cros-debug"
260fi
261
Mike Frysinger4114c792012-09-13 22:33:12 -0400262# Figure out which packages we should be building.
Mike Frysinger76452ba2012-09-13 22:45:34 -0400263PACKAGES=( "$@" )
Alex Kleinbdd2d762020-02-12 11:53:08 -0700264# Force rebuild chromeos-config because it is extremely cheap, and we do not
265# want to reuse stale configs.
266FORCE_LOCAL_BUILD_PKGS=( chromeos-base/chromeos-config )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400267if [[ $# -eq 0 ]]; then
Mike Frysinger22621952014-04-01 17:41:20 -0400268 PACKAGES=( virtual/target-os )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400269 if [[ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]]; then
Mike Frysingerde399282014-04-15 18:26:04 -0400270 PACKAGES+=( virtual/target-os-dev )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400271 fi
272 if [[ "${FLAGS_withfactory}" -eq "${FLAGS_TRUE}" ]]; then
Hung-Te Lin9b43ced2016-01-14 20:29:47 +0800273 PACKAGES+=( virtual/target-os-factory )
274 PACKAGES+=( virtual/target-os-factory-shim )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400275 fi
276 if [[ "${FLAGS_withtest}" -eq "${FLAGS_TRUE}" ]]; then
Mike Frysinger52669432014-05-05 14:34:09 -0400277 PACKAGES+=( virtual/target-os-test )
Daniel Wangaf4d0012015-07-17 11:52:05 -0700278 # chromeos-ssh-testkeys may generate ssh keys if the right USE flag is set.
279 # We force rebuilding this package from source every time, so that
280 # consecutive builds don't share ssh keys.
281 FORCE_LOCAL_BUILD_PKGS+=( chromeos-base/chromeos-ssh-testkeys )
Mike Frysinger76452ba2012-09-13 22:45:34 -0400282 fi
283 if [[ "${FLAGS_withautotest}" -eq "${FLAGS_TRUE}" ]]; then
284 PACKAGES+=( chromeos-base/autotest-all )
285 fi
Brian Harringcb782242011-12-13 19:48:44 -0800286fi
287
Chris McDonaldac5d8632019-10-23 15:55:45 -0600288info "Rebuilding Portage cache"
289# Before running any emerge operations, regenerate the Portage dependency cache
290# in parallel.
Mike Frysinger5cf035f2021-01-26 00:57:46 -0500291info_run "${EMERGE_CMD[@]}" --regen --quiet
Chris McDonaldac5d8632019-10-23 15:55:45 -0600292
Brian Harringcb782242011-12-13 19:48:44 -0800293# Verify that all packages can be emerged from scratch, without any
294# backtracking. Only print the output if this step fails.
Mike Frysinger76452ba2012-09-13 22:45:34 -0400295info "Checking package dependencies are correct: ${PACKAGES[*]}"
David Jamesab9ca212012-11-06 11:06:07 -0800296if ! OUTPUT=$(emerge-${FLAGS_board} -pe --backtrack=0 \
297 "${PACKAGES[@]}" 2>&1); then
Brian Harringcb782242011-12-13 19:48:44 -0800298 printf "%s\n" "${OUTPUT}"
Brian Harring7f175a52012-03-02 05:37:00 -0800299 die_notrace "emerge detected broken ebuilds. See error message above."
Brian Harringcb782242011-12-13 19:48:44 -0800300fi
301
Mike Frysinger4114c792012-09-13 22:33:12 -0400302# Build cros_workon packages when they are changed.
303CROS_WORKON_PKGS=()
Mike Frysingerf4711422019-11-13 18:04:31 -0500304if [ "${FLAGS_workon}" -eq "${FLAGS_TRUE}" ]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400305 LIST_MODIFIED_PACKAGES="${CHROMITE_BIN}/cros_list_modified_packages"
Jason D. Clinton321e2f82017-08-09 16:21:23 -0600306 MODIFIED_PACKAGES=( $("${LIST_MODIFIED_PACKAGES}" --board=${FLAGS_board}) )
Gregory Meinke7851ece2018-05-09 13:34:06 -0600307 info "cros_workon modified packages '${MODIFIED_PACKAGES[*]}' detected"
Jason D. Clinton321e2f82017-08-09 16:21:23 -0600308 CROS_WORKON_PKGS+=( "${MODIFIED_PACKAGES[@]}" )
Mike Frysinger4114c792012-09-13 22:33:12 -0400309
David James4941c6b2014-02-03 16:24:59 -0800310 # TODO(anush): Make chrome a fake cros-workon package.
311 if [[ -n "${CHROME_ORIGIN}" ]]; then
Alex Kleindfa7bfa2020-04-20 12:55:22 -0600312 CROS_WORKON_PKGS+=( "${CHROME_PACKAGES[@]}" )
David James4941c6b2014-02-03 16:24:59 -0800313 fi
Mike Frysinger4114c792012-09-13 22:33:12 -0400314fi
315
Daniel Wangaf4d0012015-07-17 11:52:05 -0700316# cros_workon packages always have to be rebuilt.
Daniel Wang491f42a2015-08-20 12:29:59 -0700317FORCE_LOCAL_BUILD_PKGS+=( "${CROS_WORKON_PKGS[@]}" )
Daniel Wangaf4d0012015-07-17 11:52:05 -0700318
Chris McDonald431cf232020-06-17 13:54:54 -0600319# Any package that directly depends on an active cros_workon package also needs
320# to be rebuilt in order to be correctly built against the current set of
321# changes a user may have made to the cros_workon package.
322if [[ ${#CROS_WORKON_PKGS[@]} -gt 0 ]]; then
323 # Collect all installed packages that depend on active cros_workon packages.
324 WORKON_PKG_CONSUMERS=()
325 mapfile -t WORKON_PKG_CONSUMERS < <( \
Alex Klein685216d2020-10-02 12:54:29 -0600326 equery-${FLAGS_board} -q depends "${CROS_WORKON_PKGS[@]}" | \
327 sort -u | \
328 grep -Ev "^\s*$" )
Chris McDonald431cf232020-06-17 13:54:54 -0600329
330 # Transform this list of packages with versions in to a list of just
331 # $CATEGORY/$NAME entries, since we don't want to pass packages with explicit
332 # version numbers as arguments to `emerge`.
333 if [[ ${#WORKON_PKG_CONSUMERS[@]} -gt 0 ]]; then
334 WORKON_REBUILD_PKGS=()
335 mapfile -t WORKON_REBUILD_PKGS < <( \
336 equery-${FLAGS_board} list -p -o --format='$category/$name' \
337 "${WORKON_PKG_CONSUMERS[@]}" | sort -u )
338
339 info "The following packages depend directly on an active" \
340 "cros_workon package and will be rebuilt: ${WORKON_REBUILD_PKGS[*]}"
341
342 FORCE_LOCAL_BUILD_PKGS+=( "${WORKON_REBUILD_PKGS[@]}" )
343 fi
344fi
345
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600346if [[ -n "${FLAGS_board_root}" ]]; then
347 export ROOT="${FLAGS_board_root}"
348 export PORTAGE_CONFIGROOT="${ROOT}"
349 export SYSROOT="${ROOT}"
350 export PKGDIR="${ROOT}"/packages
351fi
352
353# Temporarily modify the emerge flags so we can calculate the revdeps
354# on the modified packages.
Gregory Meinke0766df42018-08-23 11:36:12 -0600355if [[ "${FLAGS_withrevdeps}" -eq "${FLAGS_TRUE}" ]]; then
Yves Arrouyec16e45e2018-08-31 08:37:15 -0700356 info "starting reverse dependency calculations ..."
Gregory Meinke0766df42018-08-23 11:36:12 -0600357 SIM_EMERGE_FLAGS=( "${EMERGE_FLAGS[@]}" --pretend --columns )
Gregory Meinkeee71dd12018-07-09 12:42:25 -0600358
Gregory Meinke0766df42018-08-23 11:36:12 -0600359 if [[ ${#PACKAGES[@]} -gt 0 ]]; then
360 SIM_EMERGE_FLAGS+=(
361 --reinstall-atoms="${PACKAGES[*]}"
362 --usepkg-exclude="${PACKAGES[*]}"
363 )
364 fi
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600365
Chris McDonaldd346ead2020-06-16 14:57:53 -0600366 # cros-workon packages are always going to be force reinstalled, so we add
367 # the forced reinstall behavior to the modified package calculation. This is
368 # necessary to include when a user has already installed a 9999 ebuild and is
369 # now reinstalling that package with additional local changes, because
370 # otherwise the modified package calculation would not see that a 'new'
371 # package is being installed.
372 if [[ ${#CROS_WORKON_PKGS[@]} -gt 0 ]]; then
373 SIM_EMERGE_FLAGS+=(
374 --reinstall-atoms="${CROS_WORKON_PKGS[*]}"
375 --usepkg-exclude="${CROS_WORKON_PKGS[*]}"
376 )
377 fi
378
Gregory Meinke0766df42018-08-23 11:36:12 -0600379 # Calculate only the ebuild changes from the emerge simulation ignoring
380 # the virtual packages and the forced rebuild of autotest-all package.
Chris McDonald3eee0702020-06-16 14:28:01 -0600381 # The lines of the following block do the following operations:
382 # 1. Do a pretend `emerge` command to get a list of what would be built.
383 # 2. Filter to only packages that will be installed to the board sysroot.
384 # 3. Filter to only packages that would be built from source and rewrite the
385 # line from Portage's full output to only $CATEGORY/$PACKAGE
Chris McDonaldd346ead2020-06-16 14:57:53 -0600386 # 4. Filter the list of packages to a heuristic set of packages known to have
387 # incorrectly specified dependencies.
Chris McDonald3eee0702020-06-16 14:28:01 -0600388 # 5. Sort the output and remove any duplicate entries.
Gregory Meinke0766df42018-08-23 11:36:12 -0600389 BASE_INSTALL_PKGS=( $( \
390 sudo -E "${EMERGE_CMD[@]}" "${SIM_EMERGE_FLAGS[@]}" "${PACKAGES[@]}" | \
Chris McDonald3eee0702020-06-16 14:28:01 -0600391 grep -e 'to /build/' | \
Gregory Meinke0766df42018-08-23 11:36:12 -0600392 sed -n -E '/^\[ebuild /{s:^[^]]+\] +::;s: .*::;p}' | \
Chris McDonaldd346ead2020-06-16 14:57:53 -0600393 grep -E '/(chromeos-config.*|coreboot-private-files.*|tast-build-deps)$' | \
Chris McDonald3eee0702020-06-16 14:28:01 -0600394 sort -u ) )
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600395
Gregory Meinke0766df42018-08-23 11:36:12 -0600396 MOD_PKGS=()
397 if [[ "${#BASE_INSTALL_PKGS[@]}" -gt 0 ]]; then
Chris McDonaldd346ead2020-06-16 14:57:53 -0600398 info "Forced rebuild packages detected: ${BASE_INSTALL_PKGS[*]}."
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600399 # Convert specific versions into base package names
400 MOD_PKGS+=( $(\
Gregory Meinke0766df42018-08-23 11:36:12 -0600401 equery-${FLAGS_board} list -p -o --format='$category/$name' \
402 "${BASE_INSTALL_PKGS[@]}" | sort -u ) )
Mike Frysinger5a11e872018-09-05 16:29:02 -0400403 # Remove Chrome as rebuilding it is expensive and almost never makes sense.
404 # Ignore grep exit status in case chromeos-chrome is the only package.
Alex Kleindfa7bfa2020-04-20 12:55:22 -0600405 grep_cmd=( grep -v )
406 for pkg in "${CHROME_PACKAGES[@]}"; do
407 grep_cmd+=( -e "${pkg}" )
408 done
409 MOD_PKGS=( $(printf '%s\n' "${MOD_PKGS[@]}" | "${grep_cmd[@]}" || :) )
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600410 fi
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600411
Gregory Meinke0766df42018-08-23 11:36:12 -0600412 FORCE_LOCAL_BUILD_PKGS+=( "${MOD_PKGS[@]}" )
413
414 if [[ "${#MOD_PKGS[@]}" -gt 0 ]]; then
415 info "calculating reverse dependencies on packages: ${MOD_PKGS[*]}"
416 REV_DEPS=( $(\
417 equery-${FLAGS_board} -q depends --indirect "${MOD_PKGS[@]}" |\
418 awk '{print $1}' | grep -v ^virtual/ | sort -u) )
419 if [[ "${#REV_DEPS[@]}" -gt 0 ]]; then
420 # Convert specific versions into base package names
421 RMOD_PKGS=( $(\
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600422 equery-${FLAGS_board} -q list -p -o --format='$category/$name' \
Gregory Meinke0766df42018-08-23 11:36:12 -0600423 "${REV_DEPS[@]}" | sort -u ) )
Mike Frysinger5a11e872018-09-05 16:29:02 -0400424 # Remove Chrome as rebuilding it is expensive and almost never makes
425 # sense. Ignore grep exit status in case chromeos-chrome is the only
426 # package.
Alex Kleindfa7bfa2020-04-20 12:55:22 -0600427 grep_cmd=( grep -v )
428 for pkg in "${CHROME_PACKAGES[@]}"; do
429 grep_cmd+=( -e "${pkg}" )
430 done
Chris McDonald27a67cc2020-05-06 16:47:44 -0600431 RMOD_PKGS=( $(printf '%s\n' "${RMOD_PKGS[@]}" | "${grep_cmd[@]}" || :) )
Gregory Meinke0766df42018-08-23 11:36:12 -0600432 info "final reverse dependencies that will be rebuilt: ${RMOD_PKGS[*]}"
433 FORCE_LOCAL_BUILD_PKGS+=( "${RMOD_PKGS[@]}" )
434 fi
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600435 fi
Gregory Meinke0766df42018-08-23 11:36:12 -0600436fi # end FLAGS_withrevdeps
Gregory Meinkeb0f0adc2018-04-17 12:02:28 -0600437
Daniel Wangaf4d0012015-07-17 11:52:05 -0700438if [[ ${#FORCE_LOCAL_BUILD_PKGS[@]} -gt 0 ]]; then
Mike Frysinger4114c792012-09-13 22:33:12 -0400439 EMERGE_FLAGS+=(
Daniel Wangaf4d0012015-07-17 11:52:05 -0700440 --reinstall-atoms="${FORCE_LOCAL_BUILD_PKGS[*]}"
441 --usepkg-exclude="${FORCE_LOCAL_BUILD_PKGS[*]}"
Mike Frysinger4114c792012-09-13 22:33:12 -0400442 )
David James710a7d12011-12-21 15:57:02 -0800443fi
Matt Tennant298f61a2012-06-25 21:54:33 -0700444
Chris McDonald33cabb02019-12-13 14:17:08 -0700445# A list of critical system packages that should never be incidentally
446# reinstalled as a side effect of build_packages. All packages in this list
447# are special cased to prefer matching installed versions, overriding the
448# typical logic of upgrading to the newest available version.
449#
450# This list can't include any package that gets installed to a board!
451# Packages such as LLVM or binutils must not be in this list as the normal
452# rebuild logic must still apply to them for board targets.
453#
454# TODO(crbug/1050752): Remove this list and the corresponding arguments
455# to `emerge` below once we figure out how to exclude toolchain packages from
456# being upgraded transitively via BDEPEND relations.
457CRITICAL_SDK_PACKAGES=(
Manoj Guptaed847552020-09-09 03:04:51 +0000458 "dev-lang/rust"
Luis Lozanob4e21562021-01-29 02:20:03 +0000459 "dev-lang/go"
Chris McDonald33cabb02019-12-13 14:17:08 -0700460 "sys-libs/glibc"
461 "sys-devel/gcc"
462)
463
Mike Frysinger76452ba2012-09-13 22:45:34 -0400464info "Merging board packages now"
Matt Tennant298f61a2012-06-25 21:54:33 -0700465(
Hidehiko Abe7a41d342017-03-29 21:19:16 +0900466 # Support goma on bots. This has to run in subshell, otherwise EXIT trap
467 # handler is overwritten.
468 if [[ "${FLAGS_run_goma}" -eq "${FLAGS_TRUE}" ]]; then
469 info "Starting goma compiler_proxy."
470 goma_ctl="${GOMA_DIR:-${HOME}/goma}/goma_ctl.py"
Mike Frysingerea21dea2020-02-20 01:15:24 -0500471 "${goma_ctl}" restart
472 trap "'${goma_ctl}' stop" EXIT
Hidehiko Abe7a41d342017-03-29 21:19:16 +0900473 fi
474
Mike Frysinger5cf035f2021-01-26 00:57:46 -0500475 info_run sudo -E "${EMERGE_CMD[@]}" "${EMERGE_FLAGS[@]}" "${PACKAGES[@]}" \
Chris McDonald33cabb02019-12-13 14:17:08 -0700476 --useoldpkg-atoms="${CRITICAL_SDK_PACKAGES[*]}" \
477 --rebuild-exclude="${CRITICAL_SDK_PACKAGES[*]}"
Matt Tennant298f61a2012-06-25 21:54:33 -0700478)
479
Brian Harringcb782242011-12-13 19:48:44 -0800480echo "Builds complete"
Bertrand SIMONNETc7a46e22014-12-11 15:58:11 -0800481
482if [[ ${FLAGS_withdebugsymbols} -eq ${FLAGS_TRUE} ]]; then
483 info "fetching the debug symbols"
Mike Frysinger5cf035f2021-01-26 00:57:46 -0500484 info_run sudo -E "${CHROMITE_BIN}/cros_install_debug_syms" \
Bertrand SIMONNETc7a46e22014-12-11 15:58:11 -0800485 "--board=${FLAGS_board}" "--all"
486fi
487
Matt Tennant298f61a2012-06-25 21:54:33 -0700488command_completed
Brian Harringcb782242011-12-13 19:48:44 -0800489echo "Done"