blob: a8dd6ced6d1ebdc3d09090a1402723cdff9b52a6 [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
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
David James0b1baf62012-03-15 09:26:23 -070012. "$(dirname "$0")/common.sh" || exit 1
Brian Harringcb782242011-12-13 19:48:44 -080013
14# Script must run inside the chroot
15restart_in_chroot_if_needed "$@"
16
17get_default_board
18
19# Flags
20DEFINE_string board "${DEFAULT_BOARD}" \
21 "The board to build packages for."
22# Deprecate chrome* options below once we have cbuild not passing these options
23DEFINE_boolean chromefromsource "${FLAGS_FALSE}" \
24 "Deprecated"
25DEFINE_string chromebuild "" \
26 "Deprecated"
27DEFINE_string chromebase "" \
28 "Deprecated"
29DEFINE_boolean usepkg "${FLAGS_TRUE}" \
30 "Use binary packages to bootstrap when possible."
31DEFINE_boolean withdev "${FLAGS_TRUE}" \
32 "Build useful developer friendly utilities."
33DEFINE_boolean withautotest "${FLAGS_TRUE}" \
34 "Build autotest client code."
35DEFINE_integer jobs -1 \
36 "How many packages to build in parallel at maximum."
37DEFINE_integer retries -1 \
38 "On build failure, the number of times to retry."
39DEFINE_boolean withtest "${FLAGS_TRUE}" \
40 "Build packages required for testing."
41DEFINE_boolean withfactory "${FLAGS_TRUE}" \
42 "Build factory installer."
43DEFINE_boolean fast "${DEFAULT_FAST}" \
44 "Call many emerges in parallel."
45DEFINE_boolean norebuild "${FLAGS_FALSE}" \
46 "Don't automatically rebuild dependencies."
47DEFINE_boolean showoutput "${FLAGS_FALSE}" \
48 "Show all output from parallel_emerge."
49DEFINE_boolean noworkon "${FLAGS_FALSE}" \
50 "Don't force-build workon packages."
51DEFINE_boolean withdebug "${FLAGS_TRUE}" \
52 "Build debug versions of Chromium-OS-specific packages."
53DEFINE_boolean oldchromebinary "${FLAGS_FALSE}" \
54 "Use the last prebuilt binary for Chrome produced by the buildbot."
55DEFINE_boolean skip_toolchain_update "${FLAGS_FALSE}" \
56 "Don't update toolchain automatically."
Mike Frysinger839e82a2012-03-01 14:22:10 -050057DEFINE_boolean skip_chroot_upgrade "${FLAGS_FALSE}" \
58 "Don't run the chroot upgrade automatically; use with care."
Brian Harringcb782242011-12-13 19:48:44 -080059
David James17c622a2012-03-07 09:34:08 -080060# The --reuse_pkgs_from_local_boards flag tells Portage to share binary
61# packages between boards that are built locally, so that the total time
62# required to build several boards is reduced. This flag is only useful
63# when you are not able to use remote binary packages, since remote binary
64# packages are usually more up to date than anything you have locally.
65DEFINE_boolean reuse_pkgs_from_local_boards $FLAGS_FALSE \
66 "Bootstrap from local packages instead of remote packages."
67
Brian Harringcb782242011-12-13 19:48:44 -080068# Parse command line
69FLAGS_HELP="usage: $0 [flags]"
70FLAGS "$@" || exit 1
71eval set -- "${FLAGS_ARGV}"
72check_flags_only_and_allow_null_arg "$@" && set --
73
74# Die on any errors.
75set -e
76
77# Right now build_packages has to be run from scripts/
78. ${SRC_ROOT}/third_party/chromiumos-overlay/chromeos/config/chromeos_version.sh
79
80if [[ -z "${FLAGS_board}" ]]; then
81 echo "Error: --board is required."
82 exit 1
83fi
84
Mike Frysinger650bf872012-02-27 11:05:26 -050085EMERGE_FLAGS="--backtrack=30 --select"
Brian Harringcb782242011-12-13 19:48:44 -080086
87EMERGE_CMD="emerge"
88EMERGE_BOARD_CMD="emerge-${FLAGS_board}"
89if [[ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]]; then
90 EMERGE_CMD="${GCLIENT_ROOT}/chromite/bin/parallel_emerge"
91 EMERGE_BOARD_CMD="${EMERGE_CMD} --board=${FLAGS_board}"
92fi
93if [[ -n "${EXTRA_BOARD_FLAGS}" ]]; then
94 EMERGE_BOARD_CMD="${EMERGE_BOARD_CMD} ${EXTRA_BOARD_FLAGS}"
95fi
96
David James17c622a2012-03-07 09:34:08 -080097if [[ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ||
98 "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ]]; then
Brian Harringcb782242011-12-13 19:48:44 -080099 # Use binary packages. Include all build-time dependencies,
100 # so as to avoid unnecessary differences between source
101 # and binary builds.
102 EMERGE_FLAGS="${EMERGE_FLAGS} --getbinpkg --usepkg --with-bdeps y"
103fi
104
105if [[ "${FLAGS_jobs}" -ne -1 ]]; then
David James184e3902012-02-23 20:19:28 -0800106 EMERGE_FLAGS+=" --jobs=${FLAGS_jobs}"
Brian Harringcb782242011-12-13 19:48:44 -0800107fi
108
109if [[ "${FLAGS_withdebug}" -eq "${FLAGS_FALSE}" ]]; then
110 export USE="${USE} -cros-debug"
111fi
112
113${EMERGE_CMD} --info
114
115# Before we can run any tools, we need to update chroot or setup_board.
116UPDATE_ARGS=""
117if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then
118 UPDATE_ARGS+=" --fast"
119else
120 UPDATE_ARGS+=" --nofast"
121fi
122if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then
123 UPDATE_ARGS+=" --usepkg"
124else
125 UPDATE_ARGS+=" --nousepkg"
126fi
David James184e3902012-02-23 20:19:28 -0800127if [[ "${FLAGS_jobs}" -ne -1 ]]; then
128 UPDATE_ARGS+=" --jobs=${FLAGS_jobs}"
129fi
David James17c622a2012-03-07 09:34:08 -0800130if [ "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ]; then
131 UPDATE_ARGS+=" --reuse_pkgs_from_local_boards"
132fi
Brian Harringcb782242011-12-13 19:48:44 -0800133if [ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_TRUE}" ]; then
134 UPDATE_ARGS+=" --skip_toolchain_update"
135fi
Mike Frysinger839e82a2012-03-01 14:22:10 -0500136if [ "${FLAGS_skip_chroot_upgrade}" -eq "${FLAGS_TRUE}" ]; then
137 UPDATE_ARGS+=" --skip_chroot_upgrade"
138fi
139
Brian Harringcb782242011-12-13 19:48:44 -0800140${SCRIPTS_DIR}/setup_board --quiet --board=${FLAGS_board} ${UPDATE_ARGS}
141
142if [ "${FLAGS_noworkon}" -eq "${FLAGS_FALSE}" ]; then
143 # Always build cros-workon packages
144 CROS_WORKON_PKGS=$(cros_workon --board="${FLAGS_board}" list)
145fi
146
147# TODO(anush): Make chrome a fake cros-workon package.
148if [[ -n "${CHROME_ORIGIN}" ]]; then
149 CROS_WORKON_PKGS="${CROS_WORKON_PKGS} chromeos-base/chromeos-chrome"
150fi
151
152PACKAGES="chromeos-base/chromeos"
153if [[ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]]; then
154 PACKAGES="${PACKAGES} chromeos-base/chromeos-dev"
155fi
156if [[ "${FLAGS_withfactory}" -eq "${FLAGS_TRUE}" ]]; then
157 PACKAGES="${PACKAGES} chromeos-base/chromeos-factoryinstall"
158 PACKAGES="${PACKAGES} chromeos-base/factorytest-init"
159 PACKAGES="${PACKAGES} chromeos-base/chromeos-hwid"
160fi
161if [[ "${FLAGS_withtest}" -eq "${FLAGS_TRUE}" ]]; then
162 PACKAGES="${PACKAGES} chromeos-base/chromeos-test"
163fi
164if [[ "${FLAGS_withautotest}" -eq "${FLAGS_TRUE}" ]]; then
165 PACKAGES="${PACKAGES} chromeos-base/autotest-all"
166fi
167
168# Verify that all packages can be emerged from scratch, without any
169# backtracking. Only print the output if this step fails.
170if ! OUTPUT=$(emerge-${FLAGS_board} -pe --backtrack=0 ${PACKAGES} 2>&1); then
171 printf "%s\n" "${OUTPUT}"
172 die "emerge detected broken ebuilds. See error message above."
173fi
174
David James710a7d12011-12-21 15:57:02 -0800175for pkg in ${CROS_WORKON_PKGS}; do
176 EMERGE_FLAGS+=" --reinstall-atoms=${pkg}"
177 EMERGE_FLAGS+=" --usepkg-exclude=${pkg}"
178done
179if [[ "${FLAGS_norebuild}" -eq "${FLAGS_FALSE}" ]]; then
180 EMERGE_FLAGS+=" --rebuild-if-unbuilt"
Brian Harringcb782242011-12-13 19:48:44 -0800181fi
David James710a7d12011-12-21 15:57:02 -0800182if [[ "${FLAGS_oldchromebinary}" -eq "${FLAGS_TRUE}" ]]; then
183 EMERGE_FLAGS+=" --useoldpkg-atoms=chromeos-chrome"
184 EMERGE_FLAGS+=" --useoldpkg-atoms=libcros"
185fi
186if [[ "${FLAGS_showoutput}" -eq "${FLAGS_TRUE}" && \
187 "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]]; then
188 # Only parallel_emerge supports --show-output.
189 EMERGE_FLAGS+=" --show-output"
190fi
Mike Frysinger5011c7f2012-03-08 14:41:31 -0500191info "Merging board packages ${PACKAGES}"
David James710a7d12011-12-21 15:57:02 -0800192eretry sudo -E ${EMERGE_BOARD_CMD} -uDNv ${EMERGE_FLAGS} ${PACKAGES}
Brian Harringcb782242011-12-13 19:48:44 -0800193
194echo "Builds complete"
195print_time_elapsed
196echo "Done"