Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 1 | #!/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 James | 0b1baf6 | 2012-03-15 09:26:23 -0700 | [diff] [blame] | 7 | . "$(dirname "$0")/common.sh" || exit 1 |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 8 | |
| 9 | # Script must run inside the chroot |
| 10 | restart_in_chroot_if_needed "$@" |
| 11 | |
Zdenek Behan | 0578078 | 2012-05-18 03:07:28 +0200 | [diff] [blame] | 12 | assert_not_root_user |
| 13 | |
David James | 855afb7 | 2012-03-14 20:04:59 -0700 | [diff] [blame] | 14 | # Developer-visible flags. |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 15 | DEFINE_string board "${DEFAULT_BOARD}" \ |
| 16 | "The board to build packages for." |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 17 | DEFINE_boolean usepkg "${FLAGS_TRUE}" \ |
| 18 | "Use binary packages to bootstrap when possible." |
Thiago Goncales | 5ad4ca0 | 2013-07-12 10:55:11 -0700 | [diff] [blame] | 19 | DEFINE_boolean usepkgonly "${FLAGS_FALSE}" \ |
| 20 | "Only use binary packages to bootstrap; abort if any are missing." |
Mike Frysinger | f471142 | 2019-11-13 18:04:31 -0500 | [diff] [blame] | 21 | DEFINE_boolean workon "${FLAGS_TRUE}" \ |
| 22 | "Force-build workon packages." |
David James | 855afb7 | 2012-03-14 20:04:59 -0700 | [diff] [blame] | 23 | DEFINE_boolean showoutput "${FLAGS_FALSE}" \ |
| 24 | "Show all output from parallel_emerge." |
| 25 | DEFINE_boolean withautotest "${FLAGS_TRUE}" \ |
| 26 | "Build autotest client code." |
Bertrand SIMONNET | 2f6aaf2 | 2015-02-09 15:49:05 -0800 | [diff] [blame] | 27 | DEFINE_boolean withdebugsymbols "${FLAGS_FALSE}" \ |
Bertrand SIMONNET | c7a46e2 | 2014-12-11 15:58:11 -0800 | [diff] [blame] | 28 | "Install the debug symbols for all packages" |
Chris Ching | 4bc95a1 | 2016-11-22 13:44:13 -0700 | [diff] [blame] | 29 | DEFINE_string eventfile "${DEFAULT_EVENT_FILE}" \ |
| 30 | "Define the file that event logs will be written." |
Gregory Meinke | b0f0adc | 2018-04-17 12:02:28 -0600 | [diff] [blame] | 31 | DEFINE_boolean withrevdeps "${FLAGS_TRUE}" \ |
Gregory Meinke | 0766df4 | 2018-08-23 11:36:12 -0600 | [diff] [blame] | 32 | "Calculate reverse dependencies on changed ebuilds." |
Mike Frysinger | 38653b0 | 2019-10-04 13:56:29 -0400 | [diff] [blame] | 33 | DEFINE_boolean autosetgov "${FLAGS_FALSE}" \ |
| 34 | "Automatically set cpu governor to 'performance'." |
Chris McDonald | 5405a80 | 2019-11-12 13:58:38 -0700 | [diff] [blame] | 35 | DEFINE_boolean use_any_chrome "${FLAGS_TRUE}" \ |
| 36 | "Use any Chrome prebuilt available, even if the prebuilt doesn't match exactly." |
Alex Klein | f61b537 | 2020-04-16 17:02:33 -0600 | [diff] [blame] | 37 | DEFINE_boolean cleanbuild "${FLAGS_FALSE}" \ |
| 38 | "Perform a clean build; delete sysroot if it exists before building." |
Alex Klein | 80abe72 | 2020-04-29 11:13:43 -0600 | [diff] [blame] | 39 | DEFINE_boolean internal "${FLAGS_FALSE}" \ |
| 40 | "Build the internal version of chrome (set the chrome_internal USE flag)." |
Thiago Goncales | 5ad4ca0 | 2013-07-12 10:55:11 -0700 | [diff] [blame] | 41 | |
| 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)." |
| 49 | DEFINE_string board_root "" \ |
| 50 | "Emerge packages to board_root." |
David James | 855afb7 | 2012-03-14 20:04:59 -0700 | [diff] [blame] | 51 | |
Mike Frysinger | 76452ba | 2012-09-13 22:45:34 -0400 | [diff] [blame] | 52 | FLAGS_HELP="usage: $(basename $0) [flags] [packages] |
David James | 855afb7 | 2012-03-14 20:04:59 -0700 | [diff] [blame] | 53 | |
| 54 | build_packages updates the set of binary packages needed by Chrome OS. It will |
| 55 | cross compile all packages that have been updated into the given target's root |
| 56 | and build binary packages as a side-effect. The output packages will be picked |
| 57 | up by the build_image script to put together a bootable Chrome OS image. |
| 58 | |
Mike Frysinger | 76452ba | 2012-09-13 22:45:34 -0400 | [diff] [blame] | 59 | If [packages] are specified, only build those specific packages (and any |
| 60 | dependencies they might need). |
| 61 | |
David James | 855afb7 | 2012-03-14 20:04:59 -0700 | [diff] [blame] | 62 | For the fastest builds, use --nowithautotest --noworkon. |
| 63 | " |
David James | 855afb7 | 2012-03-14 20:04:59 -0700 | [diff] [blame] | 64 | |
| 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 Cui | eb4595f | 2012-12-17 14:28:42 -0800 | [diff] [blame] | 68 | DEFINE_string accept_licenses "" \ |
| 69 | "Licenses to append to the accept list." |
Allen Webb | 8bdcfd5 | 2021-04-23 16:54:28 -0500 | [diff] [blame] | 70 | DEFINE_boolean eclean "${FLAGS_TRUE}" \ |
| 71 | "Run eclean to delete old binpkgs." |
David James | 855afb7 | 2012-03-14 20:04:59 -0700 | [diff] [blame] | 72 | DEFINE_integer jobs -1 \ |
| 73 | "How many packages to build in parallel at maximum." |
| 74 | DEFINE_boolean norebuild "${FLAGS_FALSE}" \ |
| 75 | "Don't automatically rebuild dependencies." |
Mike Frysinger | 839e82a | 2012-03-01 14:22:10 -0500 | [diff] [blame] | 76 | DEFINE_boolean skip_chroot_upgrade "${FLAGS_FALSE}" \ |
| 77 | "Don't run the chroot upgrade automatically; use with care." |
Alex Klein | 1093ad4 | 2021-03-19 10:06:13 -0600 | [diff] [blame] | 78 | DEFINE_boolean skip_setup_board "${FLAGS_FALSE}" \ |
Michael Mortensen | a07f5a7 | 2021-04-09 11:55:59 -0600 | [diff] [blame] | 79 | "Don't run setup_board. Implies skip_chroot_upgrade and" \ |
| 80 | "skip_toolchain_update." |
David James | 855afb7 | 2012-03-14 20:04:59 -0700 | [diff] [blame] | 81 | DEFINE_boolean skip_toolchain_update "${FLAGS_FALSE}" \ |
| 82 | "Don't update toolchain automatically." |
| 83 | DEFINE_boolean withdev "${FLAGS_TRUE}" \ |
| 84 | "Build useful developer friendly utilities." |
| 85 | DEFINE_boolean withdebug "${FLAGS_TRUE}" \ |
| 86 | "Build debug versions of Chromium-OS-specific packages." |
| 87 | DEFINE_boolean withfactory "${FLAGS_TRUE}" \ |
| 88 | "Build factory installer." |
| 89 | DEFINE_boolean withtest "${FLAGS_TRUE}" \ |
| 90 | "Build packages required for testing." |
Alex Klein | 32d4d4c | 2021-03-08 16:16:02 -0700 | [diff] [blame] | 91 | DEFINE_boolean expandedbinhosts "${FLAGS_FALSE}" \ |
| 92 | "Allow expanded binhost inheritance." |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 93 | |
David James | 17c622a | 2012-03-07 09:34:08 -0800 | [diff] [blame] | 94 | # The --reuse_pkgs_from_local_boards flag tells Portage to share binary |
| 95 | # packages between boards that are built locally, so that the total time |
| 96 | # required to build several boards is reduced. This flag is only useful |
| 97 | # when you are not able to use remote binary packages, since remote binary |
| 98 | # packages are usually more up to date than anything you have locally. |
Hidehiko Abe | 7a41d34 | 2017-03-29 21:19:16 +0900 | [diff] [blame] | 99 | DEFINE_boolean reuse_pkgs_from_local_boards "${FLAGS_FALSE}" \ |
David James | 17c622a | 2012-03-07 09:34:08 -0800 | [diff] [blame] | 100 | "Bootstrap from local packages instead of remote packages." |
| 101 | |
Hidehiko Abe | 7a41d34 | 2017-03-29 21:19:16 +0900 | [diff] [blame] | 102 | # --run_goma option is designed to be used on bots. |
| 103 | # If you're trying to build pacakges with goma in your local dev env, this is |
| 104 | # *not* the option you're looking for. Please see comments below. |
| 105 | # This option; 1) starts goma, 2) builds packages (expecting that goma is |
| 106 | # used), then 3) stops goma explicitly. |
| 107 | # 3) is a request from the goma team, so that stats/logs can be taken. |
| 108 | # Note: GOMA_DIR and GOMA_SERVICE_ACCOUNT_JSON_FILE are expected to be passed |
| 109 | # via env var. |
| 110 | # |
| 111 | # In local dev env cases, compiler_proxy is expected to keep running. |
| 112 | # In such a case; |
| 113 | # $ python ${GOMA_DIR}/goma_ctl.py ensure_start |
| 114 | # $ ./build_packages (... and options without --run_goma ...) |
| 115 | # is an expected commandline sequence. If you set --run_goma flag while |
| 116 | # compiler_proxy is already running, the existing compiler_proxy will be |
| 117 | # stopped. |
| 118 | DEFINE_boolean run_goma "${FLAGS_FALSE}" \ |
| 119 | "If set to true, (re)starts goma, builds packages, and then stops goma." |
| 120 | |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 121 | # Parse command line |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 122 | FLAGS "$@" || exit 1 |
| 123 | eval set -- "${FLAGS_ARGV}" |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 124 | |
| 125 | # Die on any errors. |
Brian Harring | 7f175a5 | 2012-03-02 05:37:00 -0800 | [diff] [blame] | 126 | switch_to_strict_mode |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 127 | |
Alex Klein | dfa7bfa | 2020-04-20 12:55:22 -0600 | [diff] [blame] | 128 | # Chrome packages that need to be treated the same. These are the chrome and |
| 129 | # chrome follow-on packages that share the same version as chrome and are |
| 130 | # updated in lock step. |
| 131 | CHROME_PACKAGES=( |
| 132 | "chromeos-base/chromeos-chrome" |
| 133 | "chromeos-base/chrome-icu" |
| 134 | ) |
| 135 | |
Alex Klein | 80abe72 | 2020-04-29 11:13:43 -0600 | [diff] [blame] | 136 | if [[ "${FLAGS_internal}" -eq "${FLAGS_TRUE}" ]]; then |
| 137 | export USE="${USE} chrome_internal" |
| 138 | fi |
| 139 | |
Alex Klein | 12b9772 | 2019-12-09 14:25:33 -0700 | [diff] [blame] | 140 | # This is a temporary measure to help the goma team check the configs while |
| 141 | # they transition their backend service. |
| 142 | # TODO(crbug.com/1032290): Delete after the goma RBE transition is complete. |
| 143 | if [[ "${FLAGS_run_goma}" -eq "${FLAGS_TRUE}" ]]; then |
| 144 | info "Environment:" |
| 145 | env |
| 146 | info "End Environment." |
| 147 | fi |
| 148 | |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 149 | # Right now build_packages has to be run from scripts/ |
| 150 | . ${SRC_ROOT}/third_party/chromiumos-overlay/chromeos/config/chromeos_version.sh |
| 151 | |
Mike Frysinger | 38653b0 | 2019-10-04 13:56:29 -0400 | [diff] [blame] | 152 | # On some systems, powersave can take a long time to ramp up. Inform the user |
| 153 | # so they can get faster builds. https://crbug.com/1008932 |
| 154 | if grep -qs powersave \ |
| 155 | /sys/devices/system/cpu/cpufreq/policy*/scaling_governor; then |
| 156 | # Make sure we can actually support "performance". |
| 157 | if grep -qs performance \ |
| 158 | /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors; then |
| 159 | if [[ "${FLAGS_autosetgov}" -eq "${FLAGS_TRUE}" ]]; then |
| 160 | info "Temporarily setting cpu governor to 'performance'" |
| 161 | trap "sudo cpupower -c all frequency-set -g powersave >&/dev/null" EXIT |
| 162 | sudo cpupower -c all frequency-set -g performance >&/dev/null |
| 163 | else |
| 164 | warn "Current CPU governor set to 'powersave' which can slow down builds." |
| 165 | warn "Use --autosetgov to automatically (and temporarily) switch to" \ |
| 166 | "'performance'." |
| 167 | fi |
| 168 | fi |
| 169 | fi |
| 170 | |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 171 | if [[ -z "${FLAGS_board}" ]]; then |
| 172 | echo "Error: --board is required." |
| 173 | exit 1 |
| 174 | fi |
| 175 | |
Alex Klein | 1093ad4 | 2021-03-19 10:06:13 -0600 | [diff] [blame] | 176 | if [[ "${FLAGS_skip_setup_board}" -eq "${FLAGS_FALSE}" ]]; then |
| 177 | # Before we can run any tools, we need to update chroot or setup_board. |
| 178 | UPDATE_ARGS=() |
| 179 | if [[ -n ${FLAGS_accept_licenses} ]]; then |
| 180 | UPDATE_ARGS+=( --accept-licenses "${FLAGS_accept_licenses}" ) |
| 181 | fi |
| 182 | if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then |
| 183 | UPDATE_ARGS+=( --usepkg ) |
| 184 | else |
| 185 | UPDATE_ARGS+=( --nousepkg ) |
| 186 | fi |
| 187 | if [[ "${FLAGS_jobs}" -ne -1 ]]; then |
| 188 | UPDATE_ARGS+=( --jobs=${FLAGS_jobs} ) |
| 189 | fi |
| 190 | if [ "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ]; then |
| 191 | UPDATE_ARGS+=( --reuse-pkgs-from-local-boards ) |
| 192 | fi |
| 193 | if [ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_TRUE}" ]; then |
| 194 | UPDATE_ARGS+=( --skip-toolchain-update ) |
| 195 | fi |
| 196 | if [ "${FLAGS_skip_chroot_upgrade}" -eq "${FLAGS_TRUE}" ]; then |
| 197 | UPDATE_ARGS+=( --skip-chroot-upgrade ) |
| 198 | fi |
| 199 | if [[ -n ${FLAGS_board_root} ]]; then |
| 200 | UPDATE_ARGS+=( --board-root "${FLAGS_board_root}" ) |
| 201 | fi |
| 202 | if [ "${FLAGS_cleanbuild}" -eq "${FLAGS_TRUE}" ]; then |
| 203 | UPDATE_ARGS+=( --force ) |
| 204 | fi |
| 205 | if [[ "${FLAGS_expandedbinhosts}" -eq "${FLAGS_TRUE}" ]]; then |
| 206 | UPDATE_ARGS+=( --more-binhosts ) |
| 207 | else |
| 208 | UPDATE_ARGS+=( --fewer-binhosts ) |
| 209 | fi |
Mike Frysinger | 4114c79 | 2012-09-13 22:33:12 -0400 | [diff] [blame] | 210 | |
Alex Klein | 1093ad4 | 2021-03-19 10:06:13 -0600 | [diff] [blame] | 211 | setup_board --quiet --board=${FLAGS_board} "${UPDATE_ARGS[@]}" |
| 212 | fi |
Mike Frysinger | 4114c79 | 2012-09-13 22:33:12 -0400 | [diff] [blame] | 213 | |
Chris Masone | bbccc24 | 2014-02-08 16:23:53 -0800 | [diff] [blame] | 214 | sudo_clear_shadow_locks "/build/${FLAGS_board}" |
Ned Nguyen | 9af21f5 | 2019-04-05 11:30:52 -0600 | [diff] [blame] | 215 | PORTAGE_BINHOST=$(portageq-${FLAGS_board} envvar 'PORTAGE_BINHOST') |
| 216 | info "PORTAGE_BINHOST: ${PORTAGE_BINHOST}" |
| 217 | |
Chris Masone | bbccc24 | 2014-02-08 16:23:53 -0800 | [diff] [blame] | 218 | |
Mike Frysinger | 4114c79 | 2012-09-13 22:33:12 -0400 | [diff] [blame] | 219 | # Setup all the emerge command/flags. |
Mike Frysinger | 697ab96 | 2019-11-04 20:02:43 -0500 | [diff] [blame] | 220 | EMERGE_FLAGS=( -uDNv --backtrack=30 --newrepo ) |
Mike Frysinger | 4114c79 | 2012-09-13 22:33:12 -0400 | [diff] [blame] | 221 | |
Bertrand SIMONNET | 4dda4f5 | 2015-03-19 13:40:58 -0700 | [diff] [blame] | 222 | EMERGE_CMD=( |
| 223 | "${CHROMITE_BIN}/parallel_emerge" |
| 224 | --board=${FLAGS_board} |
| 225 | ) |
| 226 | |
Chris McDonald | 5405a80 | 2019-11-12 13:58:38 -0700 | [diff] [blame] | 227 | if [[ "${FLAGS_use_any_chrome}" -eq "${FLAGS_TRUE}" ]]; then |
Alex Klein | dfa7bfa | 2020-04-20 12:55:22 -0600 | [diff] [blame] | 228 | for pkg in "${CHROME_PACKAGES[@]}"; do |
| 229 | EMERGE_CMD+=( "--force-remote-binary=${pkg}" ) |
| 230 | done |
Chris McDonald | 5405a80 | 2019-11-12 13:58:38 -0700 | [diff] [blame] | 231 | fi |
| 232 | |
Mike Frysinger | 4114c79 | 2012-09-13 22:33:12 -0400 | [diff] [blame] | 233 | EMERGE_CMD+=( ${EXTRA_BOARD_FLAGS} ) |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 234 | |
David James | 17c622a | 2012-03-07 09:34:08 -0800 | [diff] [blame] | 235 | if [[ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" || |
Thiago Goncales | 5ad4ca0 | 2013-07-12 10:55:11 -0700 | [diff] [blame] | 236 | "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" || |
| 237 | "${FLAGS_usepkgonly}" -eq "${FLAGS_TRUE}" ]]; then |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 238 | # Use binary packages. Include all build-time dependencies, |
| 239 | # so as to avoid unnecessary differences between source |
| 240 | # and binary builds. |
Thiago Goncales | 5ad4ca0 | 2013-07-12 10:55:11 -0700 | [diff] [blame] | 241 | EMERGE_FLAGS+=( --getbinpkg --with-bdeps y ) |
| 242 | if [[ ${FLAGS_usepkgonly} -eq ${FLAGS_TRUE} ]]; then |
| 243 | EMERGE_FLAGS+=( --usepkgonly ) |
| 244 | else |
| 245 | EMERGE_FLAGS+=( --usepkg ) |
| 246 | fi |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 247 | fi |
| 248 | |
| 249 | if [[ "${FLAGS_jobs}" -ne -1 ]]; then |
Mike Frysinger | 4114c79 | 2012-09-13 22:33:12 -0400 | [diff] [blame] | 250 | EMERGE_FLAGS+=( --jobs=${FLAGS_jobs} ) |
| 251 | fi |
| 252 | |
| 253 | if [[ "${FLAGS_norebuild}" -eq "${FLAGS_FALSE}" ]]; then |
Chris McDonald | 00dcd72 | 2019-10-17 13:53:28 -0600 | [diff] [blame] | 254 | EMERGE_FLAGS+=( --rebuild-if-new-rev ) |
Mike Frysinger | 4114c79 | 2012-09-13 22:33:12 -0400 | [diff] [blame] | 255 | fi |
Bertrand SIMONNET | 4dda4f5 | 2015-03-19 13:40:58 -0700 | [diff] [blame] | 256 | if [[ "${FLAGS_showoutput}" -eq "${FLAGS_TRUE}" ]]; then |
Mike Frysinger | 4114c79 | 2012-09-13 22:33:12 -0400 | [diff] [blame] | 257 | EMERGE_FLAGS+=( --show-output ) |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 258 | fi |
| 259 | |
| 260 | if [[ "${FLAGS_withdebug}" -eq "${FLAGS_FALSE}" ]]; then |
| 261 | export USE="${USE} -cros-debug" |
| 262 | fi |
| 263 | |
Mike Frysinger | 4114c79 | 2012-09-13 22:33:12 -0400 | [diff] [blame] | 264 | # Figure out which packages we should be building. |
Mike Frysinger | 76452ba | 2012-09-13 22:45:34 -0400 | [diff] [blame] | 265 | PACKAGES=( "$@" ) |
Alex Klein | bdd2d76 | 2020-02-12 11:53:08 -0700 | [diff] [blame] | 266 | # Force rebuild chromeos-config because it is extremely cheap, and we do not |
| 267 | # want to reuse stale configs. |
| 268 | FORCE_LOCAL_BUILD_PKGS=( chromeos-base/chromeos-config ) |
Mike Frysinger | 76452ba | 2012-09-13 22:45:34 -0400 | [diff] [blame] | 269 | if [[ $# -eq 0 ]]; then |
Mike Frysinger | 2262195 | 2014-04-01 17:41:20 -0400 | [diff] [blame] | 270 | PACKAGES=( virtual/target-os ) |
Mike Frysinger | 76452ba | 2012-09-13 22:45:34 -0400 | [diff] [blame] | 271 | if [[ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]]; then |
Mike Frysinger | de39928 | 2014-04-15 18:26:04 -0400 | [diff] [blame] | 272 | PACKAGES+=( virtual/target-os-dev ) |
Mike Frysinger | 76452ba | 2012-09-13 22:45:34 -0400 | [diff] [blame] | 273 | fi |
| 274 | if [[ "${FLAGS_withfactory}" -eq "${FLAGS_TRUE}" ]]; then |
Hung-Te Lin | 9b43ced | 2016-01-14 20:29:47 +0800 | [diff] [blame] | 275 | PACKAGES+=( virtual/target-os-factory ) |
| 276 | PACKAGES+=( virtual/target-os-factory-shim ) |
Mike Frysinger | 76452ba | 2012-09-13 22:45:34 -0400 | [diff] [blame] | 277 | fi |
| 278 | if [[ "${FLAGS_withtest}" -eq "${FLAGS_TRUE}" ]]; then |
Mike Frysinger | 5266943 | 2014-05-05 14:34:09 -0400 | [diff] [blame] | 279 | PACKAGES+=( virtual/target-os-test ) |
Daniel Wang | af4d001 | 2015-07-17 11:52:05 -0700 | [diff] [blame] | 280 | # chromeos-ssh-testkeys may generate ssh keys if the right USE flag is set. |
| 281 | # We force rebuilding this package from source every time, so that |
| 282 | # consecutive builds don't share ssh keys. |
| 283 | FORCE_LOCAL_BUILD_PKGS+=( chromeos-base/chromeos-ssh-testkeys ) |
Mike Frysinger | 76452ba | 2012-09-13 22:45:34 -0400 | [diff] [blame] | 284 | fi |
| 285 | if [[ "${FLAGS_withautotest}" -eq "${FLAGS_TRUE}" ]]; then |
| 286 | PACKAGES+=( chromeos-base/autotest-all ) |
| 287 | fi |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 288 | fi |
| 289 | |
Chris McDonald | ac5d863 | 2019-10-23 15:55:45 -0600 | [diff] [blame] | 290 | info "Rebuilding Portage cache" |
| 291 | # Before running any emerge operations, regenerate the Portage dependency cache |
| 292 | # in parallel. |
Mike Frysinger | 5cf035f | 2021-01-26 00:57:46 -0500 | [diff] [blame] | 293 | info_run "${EMERGE_CMD[@]}" --regen --quiet |
Chris McDonald | ac5d863 | 2019-10-23 15:55:45 -0600 | [diff] [blame] | 294 | |
Allen Webb | 8bdcfd5 | 2021-04-23 16:54:28 -0500 | [diff] [blame] | 295 | # Clean out any stale binpkgs we've accumulated. This is done immediately after |
| 296 | # regenerating the cache in case ebuilds have been removed (e.g. from a revert). |
| 297 | if [[ "${FLAGS_eclean}" -eq "${FLAGS_TRUE}" ]]; then |
| 298 | info "Cleaning stale binpkgs" |
| 299 | info_run "eclean-${FLAGS_board}" packages |
| 300 | fi |
| 301 | |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 302 | # Verify that all packages can be emerged from scratch, without any |
| 303 | # backtracking. Only print the output if this step fails. |
Mike Frysinger | 76452ba | 2012-09-13 22:45:34 -0400 | [diff] [blame] | 304 | info "Checking package dependencies are correct: ${PACKAGES[*]}" |
David James | ab9ca21 | 2012-11-06 11:06:07 -0800 | [diff] [blame] | 305 | if ! OUTPUT=$(emerge-${FLAGS_board} -pe --backtrack=0 \ |
| 306 | "${PACKAGES[@]}" 2>&1); then |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 307 | printf "%s\n" "${OUTPUT}" |
Brian Harring | 7f175a5 | 2012-03-02 05:37:00 -0800 | [diff] [blame] | 308 | die_notrace "emerge detected broken ebuilds. See error message above." |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 309 | fi |
| 310 | |
Mike Frysinger | 4114c79 | 2012-09-13 22:33:12 -0400 | [diff] [blame] | 311 | # Build cros_workon packages when they are changed. |
| 312 | CROS_WORKON_PKGS=() |
Mike Frysinger | f471142 | 2019-11-13 18:04:31 -0500 | [diff] [blame] | 313 | if [ "${FLAGS_workon}" -eq "${FLAGS_TRUE}" ]; then |
Mike Frysinger | 4114c79 | 2012-09-13 22:33:12 -0400 | [diff] [blame] | 314 | LIST_MODIFIED_PACKAGES="${CHROMITE_BIN}/cros_list_modified_packages" |
Jason D. Clinton | 321e2f8 | 2017-08-09 16:21:23 -0600 | [diff] [blame] | 315 | MODIFIED_PACKAGES=( $("${LIST_MODIFIED_PACKAGES}" --board=${FLAGS_board}) ) |
Gregory Meinke | 7851ece | 2018-05-09 13:34:06 -0600 | [diff] [blame] | 316 | info "cros_workon modified packages '${MODIFIED_PACKAGES[*]}' detected" |
Jason D. Clinton | 321e2f8 | 2017-08-09 16:21:23 -0600 | [diff] [blame] | 317 | CROS_WORKON_PKGS+=( "${MODIFIED_PACKAGES[@]}" ) |
Mike Frysinger | 4114c79 | 2012-09-13 22:33:12 -0400 | [diff] [blame] | 318 | |
David James | 4941c6b | 2014-02-03 16:24:59 -0800 | [diff] [blame] | 319 | # TODO(anush): Make chrome a fake cros-workon package. |
| 320 | if [[ -n "${CHROME_ORIGIN}" ]]; then |
Alex Klein | dfa7bfa | 2020-04-20 12:55:22 -0600 | [diff] [blame] | 321 | CROS_WORKON_PKGS+=( "${CHROME_PACKAGES[@]}" ) |
David James | 4941c6b | 2014-02-03 16:24:59 -0800 | [diff] [blame] | 322 | fi |
Mike Frysinger | 4114c79 | 2012-09-13 22:33:12 -0400 | [diff] [blame] | 323 | fi |
| 324 | |
Daniel Wang | af4d001 | 2015-07-17 11:52:05 -0700 | [diff] [blame] | 325 | # cros_workon packages always have to be rebuilt. |
Daniel Wang | 491f42a | 2015-08-20 12:29:59 -0700 | [diff] [blame] | 326 | FORCE_LOCAL_BUILD_PKGS+=( "${CROS_WORKON_PKGS[@]}" ) |
Daniel Wang | af4d001 | 2015-07-17 11:52:05 -0700 | [diff] [blame] | 327 | |
Chris McDonald | 431cf23 | 2020-06-17 13:54:54 -0600 | [diff] [blame] | 328 | # Any package that directly depends on an active cros_workon package also needs |
| 329 | # to be rebuilt in order to be correctly built against the current set of |
| 330 | # changes a user may have made to the cros_workon package. |
| 331 | if [[ ${#CROS_WORKON_PKGS[@]} -gt 0 ]]; then |
| 332 | # Collect all installed packages that depend on active cros_workon packages. |
| 333 | WORKON_PKG_CONSUMERS=() |
| 334 | mapfile -t WORKON_PKG_CONSUMERS < <( \ |
Alex Klein | 685216d | 2020-10-02 12:54:29 -0600 | [diff] [blame] | 335 | equery-${FLAGS_board} -q depends "${CROS_WORKON_PKGS[@]}" | \ |
| 336 | sort -u | \ |
| 337 | grep -Ev "^\s*$" ) |
Chris McDonald | 431cf23 | 2020-06-17 13:54:54 -0600 | [diff] [blame] | 338 | |
| 339 | # Transform this list of packages with versions in to a list of just |
| 340 | # $CATEGORY/$NAME entries, since we don't want to pass packages with explicit |
| 341 | # version numbers as arguments to `emerge`. |
| 342 | if [[ ${#WORKON_PKG_CONSUMERS[@]} -gt 0 ]]; then |
| 343 | WORKON_REBUILD_PKGS=() |
| 344 | mapfile -t WORKON_REBUILD_PKGS < <( \ |
| 345 | equery-${FLAGS_board} list -p -o --format='$category/$name' \ |
| 346 | "${WORKON_PKG_CONSUMERS[@]}" | sort -u ) |
| 347 | |
| 348 | info "The following packages depend directly on an active" \ |
| 349 | "cros_workon package and will be rebuilt: ${WORKON_REBUILD_PKGS[*]}" |
| 350 | |
| 351 | FORCE_LOCAL_BUILD_PKGS+=( "${WORKON_REBUILD_PKGS[@]}" ) |
| 352 | fi |
| 353 | fi |
| 354 | |
Gregory Meinke | b0f0adc | 2018-04-17 12:02:28 -0600 | [diff] [blame] | 355 | if [[ -n "${FLAGS_board_root}" ]]; then |
| 356 | export ROOT="${FLAGS_board_root}" |
| 357 | export PORTAGE_CONFIGROOT="${ROOT}" |
| 358 | export SYSROOT="${ROOT}" |
| 359 | export PKGDIR="${ROOT}"/packages |
| 360 | fi |
| 361 | |
| 362 | # Temporarily modify the emerge flags so we can calculate the revdeps |
| 363 | # on the modified packages. |
Gregory Meinke | 0766df4 | 2018-08-23 11:36:12 -0600 | [diff] [blame] | 364 | if [[ "${FLAGS_withrevdeps}" -eq "${FLAGS_TRUE}" ]]; then |
Yves Arrouye | c16e45e | 2018-08-31 08:37:15 -0700 | [diff] [blame] | 365 | info "starting reverse dependency calculations ..." |
Gregory Meinke | 0766df4 | 2018-08-23 11:36:12 -0600 | [diff] [blame] | 366 | SIM_EMERGE_FLAGS=( "${EMERGE_FLAGS[@]}" --pretend --columns ) |
Gregory Meinke | ee71dd1 | 2018-07-09 12:42:25 -0600 | [diff] [blame] | 367 | |
Gregory Meinke | 0766df4 | 2018-08-23 11:36:12 -0600 | [diff] [blame] | 368 | if [[ ${#PACKAGES[@]} -gt 0 ]]; then |
| 369 | SIM_EMERGE_FLAGS+=( |
| 370 | --reinstall-atoms="${PACKAGES[*]}" |
| 371 | --usepkg-exclude="${PACKAGES[*]}" |
| 372 | ) |
| 373 | fi |
Gregory Meinke | b0f0adc | 2018-04-17 12:02:28 -0600 | [diff] [blame] | 374 | |
Chris McDonald | d346ead | 2020-06-16 14:57:53 -0600 | [diff] [blame] | 375 | # cros-workon packages are always going to be force reinstalled, so we add |
| 376 | # the forced reinstall behavior to the modified package calculation. This is |
| 377 | # necessary to include when a user has already installed a 9999 ebuild and is |
| 378 | # now reinstalling that package with additional local changes, because |
| 379 | # otherwise the modified package calculation would not see that a 'new' |
| 380 | # package is being installed. |
| 381 | if [[ ${#CROS_WORKON_PKGS[@]} -gt 0 ]]; then |
| 382 | SIM_EMERGE_FLAGS+=( |
| 383 | --reinstall-atoms="${CROS_WORKON_PKGS[*]}" |
| 384 | --usepkg-exclude="${CROS_WORKON_PKGS[*]}" |
| 385 | ) |
| 386 | fi |
| 387 | |
Gregory Meinke | 0766df4 | 2018-08-23 11:36:12 -0600 | [diff] [blame] | 388 | # Calculate only the ebuild changes from the emerge simulation ignoring |
| 389 | # the virtual packages and the forced rebuild of autotest-all package. |
Chris McDonald | 3eee070 | 2020-06-16 14:28:01 -0600 | [diff] [blame] | 390 | # The lines of the following block do the following operations: |
| 391 | # 1. Do a pretend `emerge` command to get a list of what would be built. |
| 392 | # 2. Filter to only packages that will be installed to the board sysroot. |
| 393 | # 3. Filter to only packages that would be built from source and rewrite the |
| 394 | # line from Portage's full output to only $CATEGORY/$PACKAGE |
Chris McDonald | d346ead | 2020-06-16 14:57:53 -0600 | [diff] [blame] | 395 | # 4. Filter the list of packages to a heuristic set of packages known to have |
| 396 | # incorrectly specified dependencies. |
Chris McDonald | 3eee070 | 2020-06-16 14:28:01 -0600 | [diff] [blame] | 397 | # 5. Sort the output and remove any duplicate entries. |
Gregory Meinke | 0766df4 | 2018-08-23 11:36:12 -0600 | [diff] [blame] | 398 | BASE_INSTALL_PKGS=( $( \ |
| 399 | sudo -E "${EMERGE_CMD[@]}" "${SIM_EMERGE_FLAGS[@]}" "${PACKAGES[@]}" | \ |
Chris McDonald | 3eee070 | 2020-06-16 14:28:01 -0600 | [diff] [blame] | 400 | grep -e 'to /build/' | \ |
Gregory Meinke | 0766df4 | 2018-08-23 11:36:12 -0600 | [diff] [blame] | 401 | sed -n -E '/^\[ebuild /{s:^[^]]+\] +::;s: .*::;p}' | \ |
Chris McDonald | d346ead | 2020-06-16 14:57:53 -0600 | [diff] [blame] | 402 | grep -E '/(chromeos-config.*|coreboot-private-files.*|tast-build-deps)$' | \ |
Chris McDonald | 3eee070 | 2020-06-16 14:28:01 -0600 | [diff] [blame] | 403 | sort -u ) ) |
Gregory Meinke | b0f0adc | 2018-04-17 12:02:28 -0600 | [diff] [blame] | 404 | |
Gregory Meinke | 0766df4 | 2018-08-23 11:36:12 -0600 | [diff] [blame] | 405 | MOD_PKGS=() |
| 406 | if [[ "${#BASE_INSTALL_PKGS[@]}" -gt 0 ]]; then |
Chris McDonald | d346ead | 2020-06-16 14:57:53 -0600 | [diff] [blame] | 407 | info "Forced rebuild packages detected: ${BASE_INSTALL_PKGS[*]}." |
Gregory Meinke | b0f0adc | 2018-04-17 12:02:28 -0600 | [diff] [blame] | 408 | # Convert specific versions into base package names |
| 409 | MOD_PKGS+=( $(\ |
Gregory Meinke | 0766df4 | 2018-08-23 11:36:12 -0600 | [diff] [blame] | 410 | equery-${FLAGS_board} list -p -o --format='$category/$name' \ |
| 411 | "${BASE_INSTALL_PKGS[@]}" | sort -u ) ) |
Mike Frysinger | 5a11e87 | 2018-09-05 16:29:02 -0400 | [diff] [blame] | 412 | # Remove Chrome as rebuilding it is expensive and almost never makes sense. |
| 413 | # Ignore grep exit status in case chromeos-chrome is the only package. |
Alex Klein | dfa7bfa | 2020-04-20 12:55:22 -0600 | [diff] [blame] | 414 | grep_cmd=( grep -v ) |
| 415 | for pkg in "${CHROME_PACKAGES[@]}"; do |
| 416 | grep_cmd+=( -e "${pkg}" ) |
| 417 | done |
| 418 | MOD_PKGS=( $(printf '%s\n' "${MOD_PKGS[@]}" | "${grep_cmd[@]}" || :) ) |
Gregory Meinke | b0f0adc | 2018-04-17 12:02:28 -0600 | [diff] [blame] | 419 | fi |
Gregory Meinke | b0f0adc | 2018-04-17 12:02:28 -0600 | [diff] [blame] | 420 | |
Gregory Meinke | 0766df4 | 2018-08-23 11:36:12 -0600 | [diff] [blame] | 421 | FORCE_LOCAL_BUILD_PKGS+=( "${MOD_PKGS[@]}" ) |
| 422 | |
| 423 | if [[ "${#MOD_PKGS[@]}" -gt 0 ]]; then |
| 424 | info "calculating reverse dependencies on packages: ${MOD_PKGS[*]}" |
| 425 | REV_DEPS=( $(\ |
| 426 | equery-${FLAGS_board} -q depends --indirect "${MOD_PKGS[@]}" |\ |
| 427 | awk '{print $1}' | grep -v ^virtual/ | sort -u) ) |
| 428 | if [[ "${#REV_DEPS[@]}" -gt 0 ]]; then |
| 429 | # Convert specific versions into base package names |
| 430 | RMOD_PKGS=( $(\ |
Gregory Meinke | b0f0adc | 2018-04-17 12:02:28 -0600 | [diff] [blame] | 431 | equery-${FLAGS_board} -q list -p -o --format='$category/$name' \ |
Gregory Meinke | 0766df4 | 2018-08-23 11:36:12 -0600 | [diff] [blame] | 432 | "${REV_DEPS[@]}" | sort -u ) ) |
Mike Frysinger | 5a11e87 | 2018-09-05 16:29:02 -0400 | [diff] [blame] | 433 | # Remove Chrome as rebuilding it is expensive and almost never makes |
| 434 | # sense. Ignore grep exit status in case chromeos-chrome is the only |
| 435 | # package. |
Alex Klein | dfa7bfa | 2020-04-20 12:55:22 -0600 | [diff] [blame] | 436 | grep_cmd=( grep -v ) |
| 437 | for pkg in "${CHROME_PACKAGES[@]}"; do |
| 438 | grep_cmd+=( -e "${pkg}" ) |
| 439 | done |
Chris McDonald | 27a67cc | 2020-05-06 16:47:44 -0600 | [diff] [blame] | 440 | RMOD_PKGS=( $(printf '%s\n' "${RMOD_PKGS[@]}" | "${grep_cmd[@]}" || :) ) |
Gregory Meinke | 0766df4 | 2018-08-23 11:36:12 -0600 | [diff] [blame] | 441 | info "final reverse dependencies that will be rebuilt: ${RMOD_PKGS[*]}" |
| 442 | FORCE_LOCAL_BUILD_PKGS+=( "${RMOD_PKGS[@]}" ) |
| 443 | fi |
Gregory Meinke | b0f0adc | 2018-04-17 12:02:28 -0600 | [diff] [blame] | 444 | fi |
Gregory Meinke | 0766df4 | 2018-08-23 11:36:12 -0600 | [diff] [blame] | 445 | fi # end FLAGS_withrevdeps |
Gregory Meinke | b0f0adc | 2018-04-17 12:02:28 -0600 | [diff] [blame] | 446 | |
Daniel Wang | af4d001 | 2015-07-17 11:52:05 -0700 | [diff] [blame] | 447 | if [[ ${#FORCE_LOCAL_BUILD_PKGS[@]} -gt 0 ]]; then |
Mike Frysinger | 4114c79 | 2012-09-13 22:33:12 -0400 | [diff] [blame] | 448 | EMERGE_FLAGS+=( |
Daniel Wang | af4d001 | 2015-07-17 11:52:05 -0700 | [diff] [blame] | 449 | --reinstall-atoms="${FORCE_LOCAL_BUILD_PKGS[*]}" |
| 450 | --usepkg-exclude="${FORCE_LOCAL_BUILD_PKGS[*]}" |
Mike Frysinger | 4114c79 | 2012-09-13 22:33:12 -0400 | [diff] [blame] | 451 | ) |
David James | 710a7d1 | 2011-12-21 15:57:02 -0800 | [diff] [blame] | 452 | fi |
Matt Tennant | 298f61a | 2012-06-25 21:54:33 -0700 | [diff] [blame] | 453 | |
Chris McDonald | 33cabb0 | 2019-12-13 14:17:08 -0700 | [diff] [blame] | 454 | # A list of critical system packages that should never be incidentally |
| 455 | # reinstalled as a side effect of build_packages. All packages in this list |
| 456 | # are special cased to prefer matching installed versions, overriding the |
| 457 | # typical logic of upgrading to the newest available version. |
| 458 | # |
| 459 | # This list can't include any package that gets installed to a board! |
| 460 | # Packages such as LLVM or binutils must not be in this list as the normal |
| 461 | # rebuild logic must still apply to them for board targets. |
| 462 | # |
| 463 | # TODO(crbug/1050752): Remove this list and the corresponding arguments |
| 464 | # to `emerge` below once we figure out how to exclude toolchain packages from |
| 465 | # being upgraded transitively via BDEPEND relations. |
| 466 | CRITICAL_SDK_PACKAGES=( |
Manoj Gupta | ed84755 | 2020-09-09 03:04:51 +0000 | [diff] [blame] | 467 | "dev-lang/rust" |
Luis Lozano | b4e2156 | 2021-01-29 02:20:03 +0000 | [diff] [blame] | 468 | "dev-lang/go" |
Chris McDonald | 33cabb0 | 2019-12-13 14:17:08 -0700 | [diff] [blame] | 469 | "sys-libs/glibc" |
| 470 | "sys-devel/gcc" |
| 471 | ) |
| 472 | |
Mike Frysinger | 76452ba | 2012-09-13 22:45:34 -0400 | [diff] [blame] | 473 | info "Merging board packages now" |
Matt Tennant | 298f61a | 2012-06-25 21:54:33 -0700 | [diff] [blame] | 474 | ( |
Hidehiko Abe | 7a41d34 | 2017-03-29 21:19:16 +0900 | [diff] [blame] | 475 | # Support goma on bots. This has to run in subshell, otherwise EXIT trap |
| 476 | # handler is overwritten. |
| 477 | if [[ "${FLAGS_run_goma}" -eq "${FLAGS_TRUE}" ]]; then |
| 478 | info "Starting goma compiler_proxy." |
| 479 | goma_ctl="${GOMA_DIR:-${HOME}/goma}/goma_ctl.py" |
Mike Frysinger | ea21dea | 2020-02-20 01:15:24 -0500 | [diff] [blame] | 480 | "${goma_ctl}" restart |
| 481 | trap "'${goma_ctl}' stop" EXIT |
Hidehiko Abe | 7a41d34 | 2017-03-29 21:19:16 +0900 | [diff] [blame] | 482 | fi |
| 483 | |
Mike Frysinger | 5cf035f | 2021-01-26 00:57:46 -0500 | [diff] [blame] | 484 | info_run sudo -E "${EMERGE_CMD[@]}" "${EMERGE_FLAGS[@]}" "${PACKAGES[@]}" \ |
Chris McDonald | 33cabb0 | 2019-12-13 14:17:08 -0700 | [diff] [blame] | 485 | --useoldpkg-atoms="${CRITICAL_SDK_PACKAGES[*]}" \ |
| 486 | --rebuild-exclude="${CRITICAL_SDK_PACKAGES[*]}" |
Matt Tennant | 298f61a | 2012-06-25 21:54:33 -0700 | [diff] [blame] | 487 | ) |
| 488 | |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 489 | echo "Builds complete" |
Bertrand SIMONNET | c7a46e2 | 2014-12-11 15:58:11 -0800 | [diff] [blame] | 490 | |
| 491 | if [[ ${FLAGS_withdebugsymbols} -eq ${FLAGS_TRUE} ]]; then |
| 492 | info "fetching the debug symbols" |
Mike Frysinger | 5cf035f | 2021-01-26 00:57:46 -0500 | [diff] [blame] | 493 | info_run sudo -E "${CHROMITE_BIN}/cros_install_debug_syms" \ |
Bertrand SIMONNET | c7a46e2 | 2014-12-11 15:58:11 -0800 | [diff] [blame] | 494 | "--board=${FLAGS_board}" "--all" |
| 495 | fi |
| 496 | |
Matt Tennant | 298f61a | 2012-06-25 21:54:33 -0700 | [diff] [blame] | 497 | command_completed |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 498 | echo "Done" |