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 | |
| 7 | # Script to build the set of binary packages needed by Chrome OS. It will |
| 8 | # cross compile all of the packages into the given targets root and build |
| 9 | # binary packages as a side-effect. The output packages will be picked up |
| 10 | # by the build_image script to put together a bootable Chrome OS image. |
| 11 | |
| 12 | # Load common CrOS utilities. Inside the chroot this file is installed in |
| 13 | # /usr/lib/crosutils. Outside the chroot we find it relative to the script's |
| 14 | # location. |
| 15 | find_common_sh() { |
| 16 | local common_paths=(/usr/lib/crosutils $(dirname "$0")) |
| 17 | local path |
| 18 | |
| 19 | SCRIPT_ROOT= |
| 20 | for path in "${common_paths[@]}"; do |
| 21 | local common="${path}/common.sh" |
| 22 | if ([ -r "${common}" ] && . "${common}" && [ -d "${SCRIPTS_DIR}" ]); then |
| 23 | SCRIPT_ROOT=${path} |
| 24 | break |
| 25 | fi |
| 26 | done |
| 27 | } |
| 28 | |
| 29 | find_common_sh |
| 30 | . "${SCRIPT_ROOT}/common.sh" || ! echo "Unable to load common.sh" || exit 1 |
| 31 | |
| 32 | # Script must run inside the chroot |
| 33 | restart_in_chroot_if_needed "$@" |
| 34 | |
| 35 | get_default_board |
| 36 | |
| 37 | # Flags |
| 38 | DEFINE_string board "${DEFAULT_BOARD}" \ |
| 39 | "The board to build packages for." |
| 40 | # Deprecate chrome* options below once we have cbuild not passing these options |
| 41 | DEFINE_boolean chromefromsource "${FLAGS_FALSE}" \ |
| 42 | "Deprecated" |
| 43 | DEFINE_string chromebuild "" \ |
| 44 | "Deprecated" |
| 45 | DEFINE_string chromebase "" \ |
| 46 | "Deprecated" |
| 47 | DEFINE_boolean usepkg "${FLAGS_TRUE}" \ |
| 48 | "Use binary packages to bootstrap when possible." |
| 49 | DEFINE_boolean withdev "${FLAGS_TRUE}" \ |
| 50 | "Build useful developer friendly utilities." |
| 51 | DEFINE_boolean withautotest "${FLAGS_TRUE}" \ |
| 52 | "Build autotest client code." |
| 53 | DEFINE_integer jobs -1 \ |
| 54 | "How many packages to build in parallel at maximum." |
| 55 | DEFINE_integer retries -1 \ |
| 56 | "On build failure, the number of times to retry." |
| 57 | DEFINE_boolean withtest "${FLAGS_TRUE}" \ |
| 58 | "Build packages required for testing." |
| 59 | DEFINE_boolean withfactory "${FLAGS_TRUE}" \ |
| 60 | "Build factory installer." |
| 61 | DEFINE_boolean fast "${DEFAULT_FAST}" \ |
| 62 | "Call many emerges in parallel." |
| 63 | DEFINE_boolean norebuild "${FLAGS_FALSE}" \ |
| 64 | "Don't automatically rebuild dependencies." |
| 65 | DEFINE_boolean showoutput "${FLAGS_FALSE}" \ |
| 66 | "Show all output from parallel_emerge." |
| 67 | DEFINE_boolean noworkon "${FLAGS_FALSE}" \ |
| 68 | "Don't force-build workon packages." |
| 69 | DEFINE_boolean withdebug "${FLAGS_TRUE}" \ |
| 70 | "Build debug versions of Chromium-OS-specific packages." |
| 71 | DEFINE_boolean oldchromebinary "${FLAGS_FALSE}" \ |
| 72 | "Use the last prebuilt binary for Chrome produced by the buildbot." |
| 73 | DEFINE_boolean skip_toolchain_update "${FLAGS_FALSE}" \ |
| 74 | "Don't update toolchain automatically." |
| 75 | |
David James | 17c622a | 2012-03-07 09:34:08 -0800 | [diff] [blame^] | 76 | # The --reuse_pkgs_from_local_boards flag tells Portage to share binary |
| 77 | # packages between boards that are built locally, so that the total time |
| 78 | # required to build several boards is reduced. This flag is only useful |
| 79 | # when you are not able to use remote binary packages, since remote binary |
| 80 | # packages are usually more up to date than anything you have locally. |
| 81 | DEFINE_boolean reuse_pkgs_from_local_boards $FLAGS_FALSE \ |
| 82 | "Bootstrap from local packages instead of remote packages." |
| 83 | |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 84 | |
| 85 | # Parse command line |
| 86 | FLAGS_HELP="usage: $0 [flags]" |
| 87 | FLAGS "$@" || exit 1 |
| 88 | eval set -- "${FLAGS_ARGV}" |
| 89 | check_flags_only_and_allow_null_arg "$@" && set -- |
| 90 | |
| 91 | # Die on any errors. |
| 92 | set -e |
| 93 | |
| 94 | # Right now build_packages has to be run from scripts/ |
| 95 | . ${SRC_ROOT}/third_party/chromiumos-overlay/chromeos/config/chromeos_version.sh |
| 96 | |
| 97 | if [[ -z "${FLAGS_board}" ]]; then |
| 98 | echo "Error: --board is required." |
| 99 | exit 1 |
| 100 | fi |
| 101 | |
Mike Frysinger | 650bf87 | 2012-02-27 11:05:26 -0500 | [diff] [blame] | 102 | EMERGE_FLAGS="--backtrack=30 --select" |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 103 | |
| 104 | EMERGE_CMD="emerge" |
| 105 | EMERGE_BOARD_CMD="emerge-${FLAGS_board}" |
| 106 | if [[ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]]; then |
| 107 | EMERGE_CMD="${GCLIENT_ROOT}/chromite/bin/parallel_emerge" |
| 108 | EMERGE_BOARD_CMD="${EMERGE_CMD} --board=${FLAGS_board}" |
| 109 | fi |
| 110 | if [[ -n "${EXTRA_BOARD_FLAGS}" ]]; then |
| 111 | EMERGE_BOARD_CMD="${EMERGE_BOARD_CMD} ${EXTRA_BOARD_FLAGS}" |
| 112 | fi |
| 113 | |
David James | 17c622a | 2012-03-07 09:34:08 -0800 | [diff] [blame^] | 114 | if [[ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" || |
| 115 | "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ]]; then |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 116 | # Use binary packages. Include all build-time dependencies, |
| 117 | # so as to avoid unnecessary differences between source |
| 118 | # and binary builds. |
| 119 | EMERGE_FLAGS="${EMERGE_FLAGS} --getbinpkg --usepkg --with-bdeps y" |
| 120 | fi |
| 121 | |
| 122 | if [[ "${FLAGS_jobs}" -ne -1 ]]; then |
David James | 184e390 | 2012-02-23 20:19:28 -0800 | [diff] [blame] | 123 | EMERGE_FLAGS+=" --jobs=${FLAGS_jobs}" |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 124 | fi |
| 125 | |
| 126 | if [[ "${FLAGS_withdebug}" -eq "${FLAGS_FALSE}" ]]; then |
| 127 | export USE="${USE} -cros-debug" |
| 128 | fi |
| 129 | |
| 130 | ${EMERGE_CMD} --info |
| 131 | |
| 132 | # Before we can run any tools, we need to update chroot or setup_board. |
| 133 | UPDATE_ARGS="" |
| 134 | if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then |
| 135 | UPDATE_ARGS+=" --fast" |
| 136 | else |
| 137 | UPDATE_ARGS+=" --nofast" |
| 138 | fi |
| 139 | if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then |
| 140 | UPDATE_ARGS+=" --usepkg" |
| 141 | else |
| 142 | UPDATE_ARGS+=" --nousepkg" |
| 143 | fi |
David James | 184e390 | 2012-02-23 20:19:28 -0800 | [diff] [blame] | 144 | if [[ "${FLAGS_jobs}" -ne -1 ]]; then |
| 145 | UPDATE_ARGS+=" --jobs=${FLAGS_jobs}" |
| 146 | fi |
David James | 17c622a | 2012-03-07 09:34:08 -0800 | [diff] [blame^] | 147 | if [ "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ]; then |
| 148 | UPDATE_ARGS+=" --reuse_pkgs_from_local_boards" |
| 149 | fi |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 150 | if [ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_TRUE}" ]; then |
| 151 | UPDATE_ARGS+=" --skip_toolchain_update" |
| 152 | fi |
| 153 | ${SCRIPTS_DIR}/setup_board --quiet --board=${FLAGS_board} ${UPDATE_ARGS} |
| 154 | |
| 155 | if [ "${FLAGS_noworkon}" -eq "${FLAGS_FALSE}" ]; then |
| 156 | # Always build cros-workon packages |
| 157 | CROS_WORKON_PKGS=$(cros_workon --board="${FLAGS_board}" list) |
| 158 | fi |
| 159 | |
| 160 | # TODO(anush): Make chrome a fake cros-workon package. |
| 161 | if [[ -n "${CHROME_ORIGIN}" ]]; then |
| 162 | CROS_WORKON_PKGS="${CROS_WORKON_PKGS} chromeos-base/chromeos-chrome" |
| 163 | fi |
| 164 | |
| 165 | PACKAGES="chromeos-base/chromeos" |
| 166 | if [[ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]]; then |
| 167 | PACKAGES="${PACKAGES} chromeos-base/chromeos-dev" |
| 168 | fi |
| 169 | if [[ "${FLAGS_withfactory}" -eq "${FLAGS_TRUE}" ]]; then |
| 170 | PACKAGES="${PACKAGES} chromeos-base/chromeos-factoryinstall" |
| 171 | PACKAGES="${PACKAGES} chromeos-base/factorytest-init" |
| 172 | PACKAGES="${PACKAGES} chromeos-base/chromeos-hwid" |
| 173 | fi |
| 174 | if [[ "${FLAGS_withtest}" -eq "${FLAGS_TRUE}" ]]; then |
| 175 | PACKAGES="${PACKAGES} chromeos-base/chromeos-test" |
| 176 | fi |
| 177 | if [[ "${FLAGS_withautotest}" -eq "${FLAGS_TRUE}" ]]; then |
| 178 | PACKAGES="${PACKAGES} chromeos-base/autotest-all" |
| 179 | fi |
| 180 | |
| 181 | # Verify that all packages can be emerged from scratch, without any |
| 182 | # backtracking. Only print the output if this step fails. |
| 183 | if ! OUTPUT=$(emerge-${FLAGS_board} -pe --backtrack=0 ${PACKAGES} 2>&1); then |
| 184 | printf "%s\n" "${OUTPUT}" |
| 185 | die "emerge detected broken ebuilds. See error message above." |
| 186 | fi |
| 187 | |
David James | 710a7d1 | 2011-12-21 15:57:02 -0800 | [diff] [blame] | 188 | for pkg in ${CROS_WORKON_PKGS}; do |
| 189 | EMERGE_FLAGS+=" --reinstall-atoms=${pkg}" |
| 190 | EMERGE_FLAGS+=" --usepkg-exclude=${pkg}" |
| 191 | done |
| 192 | if [[ "${FLAGS_norebuild}" -eq "${FLAGS_FALSE}" ]]; then |
| 193 | EMERGE_FLAGS+=" --rebuild-if-unbuilt" |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 194 | fi |
David James | 710a7d1 | 2011-12-21 15:57:02 -0800 | [diff] [blame] | 195 | if [[ "${FLAGS_oldchromebinary}" -eq "${FLAGS_TRUE}" ]]; then |
| 196 | EMERGE_FLAGS+=" --useoldpkg-atoms=chromeos-chrome" |
| 197 | EMERGE_FLAGS+=" --useoldpkg-atoms=libcros" |
| 198 | fi |
| 199 | if [[ "${FLAGS_showoutput}" -eq "${FLAGS_TRUE}" && \ |
| 200 | "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]]; then |
| 201 | # Only parallel_emerge supports --show-output. |
| 202 | EMERGE_FLAGS+=" --show-output" |
| 203 | fi |
| 204 | eretry sudo -E ${EMERGE_BOARD_CMD} -uDNv ${EMERGE_FLAGS} ${PACKAGES} |
Brian Harring | cb78224 | 2011-12-13 19:48:44 -0800 | [diff] [blame] | 205 | |
| 206 | echo "Builds complete" |
| 207 | print_time_elapsed |
| 208 | echo "Done" |