blob: c529f4f03d67bb2a0bf427ef84ff49a414ae524b [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
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.
15find_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
29find_common_sh
30. "${SCRIPT_ROOT}/common.sh" || ! echo "Unable to load common.sh" || exit 1
31
32# Script must run inside the chroot
33restart_in_chroot_if_needed "$@"
34
35get_default_board
36
37# Flags
38DEFINE_string board "${DEFAULT_BOARD}" \
39 "The board to build packages for."
40# Deprecate chrome* options below once we have cbuild not passing these options
41DEFINE_boolean chromefromsource "${FLAGS_FALSE}" \
42 "Deprecated"
43DEFINE_string chromebuild "" \
44 "Deprecated"
45DEFINE_string chromebase "" \
46 "Deprecated"
47DEFINE_boolean usepkg "${FLAGS_TRUE}" \
48 "Use binary packages to bootstrap when possible."
49DEFINE_boolean withdev "${FLAGS_TRUE}" \
50 "Build useful developer friendly utilities."
51DEFINE_boolean withautotest "${FLAGS_TRUE}" \
52 "Build autotest client code."
53DEFINE_integer jobs -1 \
54 "How many packages to build in parallel at maximum."
55DEFINE_integer retries -1 \
56 "On build failure, the number of times to retry."
57DEFINE_boolean withtest "${FLAGS_TRUE}" \
58 "Build packages required for testing."
59DEFINE_boolean withfactory "${FLAGS_TRUE}" \
60 "Build factory installer."
61DEFINE_boolean fast "${DEFAULT_FAST}" \
62 "Call many emerges in parallel."
63DEFINE_boolean norebuild "${FLAGS_FALSE}" \
64 "Don't automatically rebuild dependencies."
65DEFINE_boolean showoutput "${FLAGS_FALSE}" \
66 "Show all output from parallel_emerge."
67DEFINE_boolean noworkon "${FLAGS_FALSE}" \
68 "Don't force-build workon packages."
69DEFINE_boolean withdebug "${FLAGS_TRUE}" \
70 "Build debug versions of Chromium-OS-specific packages."
71DEFINE_boolean oldchromebinary "${FLAGS_FALSE}" \
72 "Use the last prebuilt binary for Chrome produced by the buildbot."
73DEFINE_boolean skip_toolchain_update "${FLAGS_FALSE}" \
74 "Don't update toolchain automatically."
75
76
77# Parse command line
78FLAGS_HELP="usage: $0 [flags]"
79FLAGS "$@" || exit 1
80eval set -- "${FLAGS_ARGV}"
81check_flags_only_and_allow_null_arg "$@" && set --
82
83# Die on any errors.
84set -e
85
86# Right now build_packages has to be run from scripts/
87. ${SRC_ROOT}/third_party/chromiumos-overlay/chromeos/config/chromeos_version.sh
88
89if [[ -z "${FLAGS_board}" ]]; then
90 echo "Error: --board is required."
91 exit 1
92fi
93
94EMERGE_FLAGS="--backtrack=30"
95
96EMERGE_CMD="emerge"
97EMERGE_BOARD_CMD="emerge-${FLAGS_board}"
98if [[ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]]; then
99 EMERGE_CMD="${GCLIENT_ROOT}/chromite/bin/parallel_emerge"
100 EMERGE_BOARD_CMD="${EMERGE_CMD} --board=${FLAGS_board}"
101fi
102if [[ -n "${EXTRA_BOARD_FLAGS}" ]]; then
103 EMERGE_BOARD_CMD="${EMERGE_BOARD_CMD} ${EXTRA_BOARD_FLAGS}"
104fi
105
106if [[ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]]; then
107 # Use binary packages. Include all build-time dependencies,
108 # so as to avoid unnecessary differences between source
109 # and binary builds.
110 EMERGE_FLAGS="${EMERGE_FLAGS} --getbinpkg --usepkg --with-bdeps y"
111fi
112
113if [[ "${FLAGS_jobs}" -ne -1 ]]; then
114 EMERGE_JOBS="--jobs=${FLAGS_jobs}"
Brian Harringcb782242011-12-13 19:48:44 -0800115fi
116
117if [[ "${FLAGS_withdebug}" -eq "${FLAGS_FALSE}" ]]; then
118 export USE="${USE} -cros-debug"
119fi
120
121${EMERGE_CMD} --info
122
123# Before we can run any tools, we need to update chroot or setup_board.
124UPDATE_ARGS=""
125if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then
126 UPDATE_ARGS+=" --fast"
127else
128 UPDATE_ARGS+=" --nofast"
129fi
130if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then
131 UPDATE_ARGS+=" --usepkg"
132else
133 UPDATE_ARGS+=" --nousepkg"
134fi
135if [ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_TRUE}" ]; then
136 UPDATE_ARGS+=" --skip_toolchain_update"
137fi
138${SCRIPTS_DIR}/setup_board --quiet --board=${FLAGS_board} ${UPDATE_ARGS}
139
140if [ "${FLAGS_noworkon}" -eq "${FLAGS_FALSE}" ]; then
141 # Always build cros-workon packages
142 CROS_WORKON_PKGS=$(cros_workon --board="${FLAGS_board}" list)
143fi
144
145# TODO(anush): Make chrome a fake cros-workon package.
146if [[ -n "${CHROME_ORIGIN}" ]]; then
147 CROS_WORKON_PKGS="${CROS_WORKON_PKGS} chromeos-base/chromeos-chrome"
148fi
149
150PACKAGES="chromeos-base/chromeos"
151if [[ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]]; then
152 PACKAGES="${PACKAGES} chromeos-base/chromeos-dev"
153fi
154if [[ "${FLAGS_withfactory}" -eq "${FLAGS_TRUE}" ]]; then
155 PACKAGES="${PACKAGES} chromeos-base/chromeos-factoryinstall"
156 PACKAGES="${PACKAGES} chromeos-base/factorytest-init"
157 PACKAGES="${PACKAGES} chromeos-base/chromeos-hwid"
158fi
159if [[ "${FLAGS_withtest}" -eq "${FLAGS_TRUE}" ]]; then
160 PACKAGES="${PACKAGES} chromeos-base/chromeos-test"
161fi
162if [[ "${FLAGS_withautotest}" -eq "${FLAGS_TRUE}" ]]; then
163 PACKAGES="${PACKAGES} chromeos-base/autotest-all"
164fi
165
166# Verify that all packages can be emerged from scratch, without any
167# backtracking. Only print the output if this step fails.
168if ! OUTPUT=$(emerge-${FLAGS_board} -pe --backtrack=0 ${PACKAGES} 2>&1); then
169 printf "%s\n" "${OUTPUT}"
170 die "emerge detected broken ebuilds. See error message above."
171fi
172
David James710a7d12011-12-21 15:57:02 -0800173for pkg in ${CROS_WORKON_PKGS}; do
174 EMERGE_FLAGS+=" --reinstall-atoms=${pkg}"
175 EMERGE_FLAGS+=" --usepkg-exclude=${pkg}"
176done
177if [[ "${FLAGS_norebuild}" -eq "${FLAGS_FALSE}" ]]; then
178 EMERGE_FLAGS+=" --rebuild-if-unbuilt"
Brian Harringcb782242011-12-13 19:48:44 -0800179fi
David James710a7d12011-12-21 15:57:02 -0800180if [[ "${FLAGS_oldchromebinary}" -eq "${FLAGS_TRUE}" ]]; then
181 EMERGE_FLAGS+=" --useoldpkg-atoms=chromeos-chrome"
182 EMERGE_FLAGS+=" --useoldpkg-atoms=libcros"
183fi
184if [[ "${FLAGS_showoutput}" -eq "${FLAGS_TRUE}" && \
185 "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]]; then
186 # Only parallel_emerge supports --show-output.
187 EMERGE_FLAGS+=" --show-output"
188fi
189eretry sudo -E ${EMERGE_BOARD_CMD} -uDNv ${EMERGE_FLAGS} ${PACKAGES}
Brian Harringcb782242011-12-13 19:48:44 -0800190
191echo "Builds complete"
192print_time_elapsed
193echo "Done"