mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-27 00:21:44 +02:00
Currently, if set -e spots a nonzero exit we basically have no real debug information- it just stops immediately without stating where or why. This forces our scripts to be stupidly verbose so we can track roughly where they were, thus when they fail we can use that information to localize the rough exit point. Instead we should be traping that set -e induced exit and outputing necessary debug information to run it down. This includes outputing the relevant stack trace, or at least what we can get of it. The 'die' function is now enhanced to automatically dump the trace that lead to it. For most consumers this is desired- however for commandline parsing induced dies ("--board is missing" for example), the trace is noise. For those cases, a 'die_notrace' function was added that retains the original non-backtrace behaviour. Example output via instrumenting cros_generate_breakpad_symbols w/ the failing command '/bin/false' (nonzero exit code). Before: ./cros_generate_breakpad_symbols monkeys --board=x86-alex <no output at all, just exit code 1> With this CL: ./cros_generate_breakpad_symbols monkeys --board=x86-alex ERROR : script called: ./cros_generate_breakpad_symbols 'monkeys' '--board=x86-alex' ERROR : Backtrace: (most recent call is last) ERROR : file cros_generate_breakpad_symbols, line 207, called: main 'monkeys' '--board=x86-alex' ERROR : file cros_generate_breakpad_symbols, line 163, called: die_err_trap '/bin/false' '1' ERROR : ERROR : Command failed: ERROR : Command '/bin/false' exited with nonzero code: 1 BUG=chromium-os:30598 TEST=inject a failing command into a script, verify the output. TEST=inject a 'command not found', verify the output TEST=cbuildbot x86-generic-full --remote TEST=cbuildbot arm-tegra2-full --remote TEST=cbuildbot chromiumos-sdk --remote Change-Id: I517ffde4d1bb7e2310a74f5a6455b53ba2dea86c Reviewed-on: https://gerrit.chromium.org/gerrit/17225 Reviewed-by: Brian Harring <ferringb@chromium.org> Tested-by: Brian Harring <ferringb@chromium.org> Commit-Ready: Brian Harring <ferringb@chromium.org>
191 lines
6.5 KiB
Bash
Executable File
191 lines
6.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
. "$(dirname "$0")/common.sh" || exit 1
|
|
|
|
# Script must run inside the chroot
|
|
restart_in_chroot_if_needed "$@"
|
|
|
|
get_default_board
|
|
|
|
# Developer-visible flags.
|
|
DEFINE_string board "${DEFAULT_BOARD}" \
|
|
"The board to build packages for."
|
|
DEFINE_boolean usepkg "${FLAGS_TRUE}" \
|
|
"Use binary packages to bootstrap when possible."
|
|
DEFINE_boolean noworkon "${FLAGS_FALSE}" \
|
|
"Don't force-build workon packages."
|
|
DEFINE_boolean showoutput "${FLAGS_FALSE}" \
|
|
"Show all output from parallel_emerge."
|
|
DEFINE_boolean withautotest "${FLAGS_TRUE}" \
|
|
"Build autotest client code."
|
|
|
|
FLAGS_HELP="usage: $(basename $0) [flags]
|
|
|
|
build_packages updates the set of binary packages needed by Chrome OS. It will
|
|
cross compile all packages that have been updated into the given target's root
|
|
and build binary packages as a side-effect. The output packages will be picked
|
|
up by the build_image script to put together a bootable Chrome OS image.
|
|
|
|
For the fastest builds, use --nowithautotest --noworkon.
|
|
"
|
|
show_help_if_requested "$@"
|
|
|
|
# The following options are advanced options, only available to those willing
|
|
# to read the source code. They are not shown in help output, since they are
|
|
# not needed for the typical developer workflow.
|
|
DEFINE_boolean fast "${DEFAULT_FAST}" \
|
|
"Call many emerges in parallel."
|
|
DEFINE_integer jobs -1 \
|
|
"How many packages to build in parallel at maximum."
|
|
DEFINE_boolean norebuild "${FLAGS_FALSE}" \
|
|
"Don't automatically rebuild dependencies."
|
|
DEFINE_boolean skip_chroot_upgrade "${FLAGS_FALSE}" \
|
|
"Don't run the chroot upgrade automatically; use with care."
|
|
DEFINE_boolean skip_toolchain_update "${FLAGS_FALSE}" \
|
|
"Don't update toolchain automatically."
|
|
DEFINE_boolean withdev "${FLAGS_TRUE}" \
|
|
"Build useful developer friendly utilities."
|
|
DEFINE_boolean withdebug "${FLAGS_TRUE}" \
|
|
"Build debug versions of Chromium-OS-specific packages."
|
|
DEFINE_boolean withfactory "${FLAGS_TRUE}" \
|
|
"Build factory installer."
|
|
DEFINE_boolean withtest "${FLAGS_TRUE}" \
|
|
"Build packages required for testing."
|
|
|
|
# The --reuse_pkgs_from_local_boards flag tells Portage to share binary
|
|
# packages between boards that are built locally, so that the total time
|
|
# required to build several boards is reduced. This flag is only useful
|
|
# when you are not able to use remote binary packages, since remote binary
|
|
# packages are usually more up to date than anything you have locally.
|
|
DEFINE_boolean reuse_pkgs_from_local_boards $FLAGS_FALSE \
|
|
"Bootstrap from local packages instead of remote packages."
|
|
|
|
# Parse command line
|
|
FLAGS "$@" || exit 1
|
|
eval set -- "${FLAGS_ARGV}"
|
|
check_flags_only_and_allow_null_arg "$@" && set --
|
|
|
|
# Die on any errors.
|
|
switch_to_strict_mode
|
|
|
|
# Right now build_packages has to be run from scripts/
|
|
. ${SRC_ROOT}/third_party/chromiumos-overlay/chromeos/config/chromeos_version.sh
|
|
|
|
if [[ -z "${FLAGS_board}" ]]; then
|
|
echo "Error: --board is required."
|
|
exit 1
|
|
fi
|
|
|
|
EMERGE_FLAGS="--backtrack=30 --select"
|
|
|
|
EMERGE_CMD="emerge"
|
|
EMERGE_BOARD_CMD="emerge-${FLAGS_board}"
|
|
if [[ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]]; then
|
|
EMERGE_CMD="${GCLIENT_ROOT}/chromite/bin/parallel_emerge"
|
|
EMERGE_BOARD_CMD="${EMERGE_CMD} --board=${FLAGS_board}"
|
|
fi
|
|
if [[ -n "${EXTRA_BOARD_FLAGS}" ]]; then
|
|
EMERGE_BOARD_CMD="${EMERGE_BOARD_CMD} ${EXTRA_BOARD_FLAGS}"
|
|
fi
|
|
|
|
if [[ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ||
|
|
"${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ]]; then
|
|
# Use binary packages. Include all build-time dependencies,
|
|
# so as to avoid unnecessary differences between source
|
|
# and binary builds.
|
|
EMERGE_FLAGS="${EMERGE_FLAGS} --getbinpkg --usepkg --with-bdeps y"
|
|
fi
|
|
|
|
if [[ "${FLAGS_jobs}" -ne -1 ]]; then
|
|
EMERGE_FLAGS+=" --jobs=${FLAGS_jobs}"
|
|
fi
|
|
|
|
if [[ "${FLAGS_withdebug}" -eq "${FLAGS_FALSE}" ]]; then
|
|
export USE="${USE} -cros-debug"
|
|
fi
|
|
|
|
${EMERGE_CMD} --info
|
|
|
|
# Before we can run any tools, we need to update chroot or setup_board.
|
|
UPDATE_ARGS=""
|
|
if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then
|
|
UPDATE_ARGS+=" --fast"
|
|
else
|
|
UPDATE_ARGS+=" --nofast"
|
|
fi
|
|
if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then
|
|
UPDATE_ARGS+=" --usepkg"
|
|
else
|
|
UPDATE_ARGS+=" --nousepkg"
|
|
fi
|
|
if [[ "${FLAGS_jobs}" -ne -1 ]]; then
|
|
UPDATE_ARGS+=" --jobs=${FLAGS_jobs}"
|
|
fi
|
|
if [ "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ]; then
|
|
UPDATE_ARGS+=" --reuse_pkgs_from_local_boards"
|
|
fi
|
|
if [ "${FLAGS_skip_toolchain_update}" -eq "${FLAGS_TRUE}" ]; then
|
|
UPDATE_ARGS+=" --skip_toolchain_update"
|
|
fi
|
|
if [ "${FLAGS_skip_chroot_upgrade}" -eq "${FLAGS_TRUE}" ]; then
|
|
UPDATE_ARGS+=" --skip_chroot_upgrade"
|
|
fi
|
|
|
|
${SCRIPTS_DIR}/setup_board --quiet --board=${FLAGS_board} ${UPDATE_ARGS}
|
|
|
|
if [ "${FLAGS_noworkon}" -eq "${FLAGS_FALSE}" ]; then
|
|
# Always build cros-workon packages
|
|
CROS_WORKON_PKGS=$(cros_workon --board="${FLAGS_board}" list)
|
|
fi
|
|
|
|
# TODO(anush): Make chrome a fake cros-workon package.
|
|
if [[ -n "${CHROME_ORIGIN}" ]]; then
|
|
CROS_WORKON_PKGS="${CROS_WORKON_PKGS} chromeos-base/chromeos-chrome"
|
|
fi
|
|
|
|
PACKAGES="chromeos-base/chromeos"
|
|
if [[ "${FLAGS_withdev}" -eq "${FLAGS_TRUE}" ]]; then
|
|
PACKAGES="${PACKAGES} chromeos-base/chromeos-dev"
|
|
fi
|
|
if [[ "${FLAGS_withfactory}" -eq "${FLAGS_TRUE}" ]]; then
|
|
PACKAGES="${PACKAGES} chromeos-base/chromeos-factoryinstall"
|
|
PACKAGES="${PACKAGES} chromeos-base/factorytest-init"
|
|
PACKAGES="${PACKAGES} chromeos-base/chromeos-hwid"
|
|
fi
|
|
if [[ "${FLAGS_withtest}" -eq "${FLAGS_TRUE}" ]]; then
|
|
PACKAGES="${PACKAGES} chromeos-base/chromeos-test"
|
|
fi
|
|
if [[ "${FLAGS_withautotest}" -eq "${FLAGS_TRUE}" ]]; then
|
|
PACKAGES="${PACKAGES} chromeos-base/autotest-all"
|
|
fi
|
|
|
|
# Verify that all packages can be emerged from scratch, without any
|
|
# backtracking. Only print the output if this step fails.
|
|
if ! OUTPUT=$(emerge-${FLAGS_board} -pe --backtrack=0 ${PACKAGES} 2>&1); then
|
|
printf "%s\n" "${OUTPUT}"
|
|
die_notrace "emerge detected broken ebuilds. See error message above."
|
|
fi
|
|
|
|
for pkg in ${CROS_WORKON_PKGS}; do
|
|
EMERGE_FLAGS+=" --reinstall-atoms=${pkg}"
|
|
EMERGE_FLAGS+=" --usepkg-exclude=${pkg}"
|
|
done
|
|
if [[ "${FLAGS_norebuild}" -eq "${FLAGS_FALSE}" ]]; then
|
|
EMERGE_FLAGS+=" --rebuild-if-unbuilt"
|
|
fi
|
|
if [[ "${FLAGS_showoutput}" -eq "${FLAGS_TRUE}" && \
|
|
"${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]]; then
|
|
# Only parallel_emerge supports --show-output.
|
|
EMERGE_FLAGS+=" --show-output"
|
|
fi
|
|
info "Merging board packages ${PACKAGES}"
|
|
sudo -E ${EMERGE_BOARD_CMD} -uDNv ${EMERGE_FLAGS} ${PACKAGES}
|
|
|
|
echo "Builds complete"
|
|
print_time_elapsed
|
|
echo "Done"
|