mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-12 15:36:58 +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>
113 lines
4.1 KiB
Bash
Executable File
113 lines
4.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Copyright (c) 2010 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
|
|
assert_inside_chroot "$@"
|
|
|
|
# Do not run as root
|
|
assert_not_root_user
|
|
|
|
# Developer-visible flags.
|
|
DEFINE_boolean usepkg $FLAGS_TRUE \
|
|
"Use binary packages to bootstrap."
|
|
|
|
FLAGS_HELP="usage: $(basename $0) [flags]
|
|
Performs an update of the chroot. This script is called as part of
|
|
build_packages, so there is typically no need to call this script directly.
|
|
"
|
|
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."
|
|
|
|
# Parse command line flags
|
|
FLAGS "$@" || exit 1
|
|
eval set -- "${FLAGS_ARGV}"
|
|
|
|
# Only now can we die on error. shflags functions leak non-zero error codes,
|
|
# so will die prematurely if 'switch_to_strict_mode' is specified before now.
|
|
switch_to_strict_mode
|
|
|
|
. ${SCRIPTS_DIR}/sdk_lib/make_conf_util.sh
|
|
|
|
# Run version hooks as pre-update
|
|
${SCRIPTS_DIR}/run_chroot_version_hooks
|
|
|
|
# Create /etc/make.conf.host_setup. The file content is regenerated
|
|
# from scratch every update. There are various reasons to do this:
|
|
# + It's cheap, so this is an easy way to guarantee correct content
|
|
# after an upgrade.
|
|
# + Inside make_chroot.sh, we use a temporary version of the file
|
|
# which must be updated before the script completes; that final
|
|
# update happens here.
|
|
# + If the repositories change to add or remove the private
|
|
# overlay, the file may need to be regenerated.
|
|
create_host_setup
|
|
|
|
info "Updating chroot"
|
|
|
|
EMERGE_FLAGS="-uNv --with-bdeps=y --select"
|
|
if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then
|
|
EMERGE_FLAGS="${EMERGE_FLAGS} --getbinpkg"
|
|
|
|
# Only update toolchain when binpkgs are available. Toolchain rollout
|
|
# process only takes place when the chromiumos sdk builder finishes
|
|
# a successful build.
|
|
EMERGE_FLAGS+=" --useoldpkg-atoms=sys-devel/binutils"
|
|
EMERGE_FLAGS+=" --useoldpkg-atoms=sys-devel/gcc"
|
|
EMERGE_FLAGS+=" --useoldpkg-atoms=sys-libs/glibc"
|
|
fi
|
|
|
|
if [[ "${FLAGS_jobs}" -ne -1 ]]; then
|
|
EMERGE_FLAGS+=" --jobs=${FLAGS_jobs}"
|
|
fi
|
|
|
|
# Perform an update of hard-host-depends and world in the chroot.
|
|
EMERGE_CMD="emerge"
|
|
if [ "${FLAGS_fast}" -eq "${FLAGS_TRUE}" ]; then
|
|
EMERGE_CMD="${GCLIENT_ROOT}/chromite/bin/parallel_emerge"
|
|
fi
|
|
|
|
# In first pass, update portage and toolchains. Lagged updates of both
|
|
# can cause serious issues later.
|
|
export CHOST="$(portageq envvar CHOST)"
|
|
LATEST=$(gcc-config -l | awk -v chost="${CHOST}" '$2 ~ chost { print $2 }' | \
|
|
sort -V | tail -n 1)
|
|
CURRENT="$(gcc-config -c)" || true # This fails if current profile is invalid.
|
|
sudo -E ${EMERGE_CMD} ${EMERGE_FLAGS} \
|
|
sys-devel/gcc sys-devel/binutils sys-libs/glibc sys-apps/portage
|
|
# If the latest toolchain wasn't already selected before we updated, do nothing,
|
|
# otherwise autoselect the latest. Also fix if the current profile is invalid.
|
|
if [ "${LATEST}" != "${CURRENT}" ] || ! gcc-config -c &> /dev/null; then
|
|
LATEST=$(gcc-config -l | awk -v chost="${CHOST}" '$2 ~ chost { print $2 }' | \
|
|
sort -V | tail -n 1 )
|
|
sudo -E gcc-config "${LATEST}"
|
|
fi
|
|
|
|
# Second pass, update everything else.
|
|
EMERGE_FLAGS+=" --deep"
|
|
sudo -E ${EMERGE_CMD} ${EMERGE_FLAGS} \
|
|
chromeos-base/hard-host-depends world
|
|
|
|
# Automatically discard all CONFIG_PROTECT'ed files. Those that are
|
|
# protected should not be overwritten until the variable is changed.
|
|
# Autodiscard is option "-9" followed by the "YES" confirmation.
|
|
printf '%s\nYES\n' -9 | sudo etc-update
|
|
|
|
# If the user still has old perl modules installed, update them.
|
|
PERL_VERSIONS=$(find /usr/lib*/perl5/vendor_perl/ -maxdepth 1 -mindepth 1 \
|
|
-type d -printf '%P\n' | sort -u | wc -w)
|
|
if [ "$PERL_VERSIONS" -gt 1 ] ; then
|
|
sudo perl-cleaner --all -- --quiet
|
|
fi
|