common.sh: output a backtrace and debug information on failure.

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>
This commit is contained in:
Brian Harring 2012-03-02 05:37:00 -08:00 committed by Gerrit
parent 82975f96c5
commit 7f175a59e1
40 changed files with 250 additions and 99 deletions

View File

@ -34,7 +34,7 @@ function main() {
# Parse command line
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
set -e
switch_to_strict_mode
if [[ -z "${FLAGS_from}" ]]; then
echo "Please specify --from directory"

View File

@ -42,7 +42,7 @@ eval set -- "$FLAGS_ARGV"
# Check on the board that they are trying to set up.
if [ -z "$FLAGS_board" ] ; then
die "Error: --board required."
die_notrace "Error: --board required."
fi
BUCKET="chromeos-image-archive"

View File

@ -31,7 +31,7 @@ find_common_sh
FLAGS "$@" || exit 1
set -e
switch_to_strict_mode
# TMP necessary for remote_access_init.
TMP=$(mktemp -d /tmp/cros_check_chrome_version.XXXX)

View File

@ -36,7 +36,7 @@ assert_inside_chroot
die "Unable to load /usr/lib/installer/chromeos-common.sh"
. "${SCRIPTS_DIR}/build_library/build_image_util.sh" || die "No build_image_util"
set -e
switch_to_strict_mode
if [ $# -lt 2 ]; then
echo "Usage: ${0} /PATH/TO/IMAGE IMAGE.BIN [shflags overrides]"
@ -143,8 +143,8 @@ FLAGS "${@}" || exit 1
[ -z "${FLAGS_verity_salt}" ] && FLAGS_verity_salt=$(make_salt)
# Only now can we die on error. shflags functions leak non-zero error codes,
# so will die prematurely if 'set -e' is specified before now.
set -e -u
# so will die prematurely if 'switch_to_strict_mode' is specified before now.
switch_to_strict_mode -u
# $1 - Directory where developer rootfs is mounted.
# $2 - Directory where developer stateful_partition is mounted.

View File

@ -68,7 +68,7 @@ if [ -z "${FLAGS_board}" ]; then
exit 1
fi
set -e
switch_to_strict_mode
trap cleanup EXIT
eval set -- "${FLAGS_ARGV}"

View File

@ -57,7 +57,7 @@ FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Abort on error
set -e
switch_to_strict_mode
if [ -z $FLAGS_from ] || [ ! -f $FLAGS_from ] ; then
echo "Error: invalid flag --from"

View File

@ -50,7 +50,7 @@ failure() {
}
# Abort on error
set -e
switch_to_strict_mode
trap "failure" EXIT
@ -68,18 +68,19 @@ fi
VBOOT_DIR="${SRC_ROOT}/platform/vboot_reference"
if [ ! -d "${VBOOT_DIR}" ]; then
die "VBOOT DIR NOT FOUND at \'${VBOOT_DIR}\' .."
die_notrace "VBOOT DIR NOT FOUND at \'${VBOOT_DIR}\' .."
fi
TMP_IMAGE=$(mktemp)
VBOOT_KEYS="${VBOOT_DIR}/tests/devkeys"
if [ ! -d "${VBOOT_KEYS}" ]; then
die "VBOOT KEYS NOT FOUND at \'${VBOOT_KEYS}\' .."
die_notrace "VBOOT KEYS NOT FOUND at \'${VBOOT_KEYS}\' .."
fi
VBOOT_SIGN="${VBOOT_DIR}/scripts/image_signing/sign_official_build.sh"
if [ ! -x "${VBOOT_SIGN}" ]; then
die "VBOOT TOOL sign_official_build.sh NOT FOUND at \'${VBOOT_SIGN}\' .."
die_notrace \
"VBOOT TOOL sign_official_build.sh NOT FOUND at \'${VBOOT_SIGN}\' .."
fi
cp "${FLAGS_from}" "${TMP_IMAGE}"

View File

@ -28,4 +28,5 @@ find_common_sh
. "${SCRIPT_ROOT}/common.sh" || (echo "Unable to load common.sh" && exit 1)
# --- END COMMON.SH BOILERPLATE ---
die "error: Please run cros_workon_make from chroot:/usr/bin/cros_workon_make"
die_notrace \
"error: Please run cros_workon_make from chroot:/usr/bin/cros_workon_make"

View File

@ -87,8 +87,8 @@ 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 'set -e' is specified before now.
set -e
# so will die prematurely if 'switch_to_strict_mode' is specified before now.
switch_to_strict_mode
# Determine build version.
OVERLAY_CHROMEOS_DIR="${SRC_ROOT}/third_party/chromiumos-overlay/chromeos"
@ -161,7 +161,7 @@ fi
if [ $((FLAGS_rootfs_size + FLAGS_rootfs_hash_pad)) -gt \
${FLAGS_rootfs_partition_size} ] ; then
die "rootfs ($((FLAGS_rootfs_size + FLAGS_rootfs_hash_pad)) MiB) is" \
die_notrace "rootfs ($((FLAGS_rootfs_size + FLAGS_rootfs_hash_pad)) MiB) is" \
"bigger than partition (${FLAGS_rootfs_partition_size} MiB)."
fi
@ -204,7 +204,8 @@ if [[ -e "${BUILD_DIR}" ]]; then
else
error "Directory ${BUILD_DIR} already exists."
error "Use --build_attempt option to specify an unused attempt."
die "Or use --replace if you want to overwrite this directory."
error "Or use --replace if you want to overwrite this directory."
die "Unwilling to overwrite ${BUILD_DIR}."
fi
fi

View File

@ -58,7 +58,7 @@ FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Die on error
set -e
switch_to_strict_mode
verity_args=
# Even with a rootfs_image, root= is not changed unless specified.

View File

@ -73,7 +73,8 @@ create_base_image() {
ROOT_LOOP_DEV=$(sudo losetup --show -f "${ROOT_FS_IMG}")
if [ -z "${ROOT_LOOP_DEV}" ] ; then
die "No free loop device. Free up a loop device or reboot. exiting. "
die_notrace \
"No free loop device. Free up a loop device or reboot. exiting. "
fi
# Specify a block size and block count to avoid using the hash pad.
@ -105,7 +106,8 @@ create_base_image() {
DISK_LABEL="C-STATE"
STATEFUL_LOOP_DEV=$(sudo losetup --show -f "${STATEFUL_FS_IMG}")
if [ -z "${STATEFUL_LOOP_DEV}" ] ; then
die "No free loop device. Free up a loop device or reboot. exiting. "
die_notrace \
"No free loop device. Free up a loop device or reboot. exiting. "
fi
sudo mkfs.ext4 "${STATEFUL_LOOP_DEV}"
sudo tune2fs -L "${DISK_LABEL}" -U "${UUID}" -c 0 -i 0 "${STATEFUL_LOOP_DEV}"
@ -138,7 +140,8 @@ create_base_image() {
LIBC_PATH="${PKGDIR}/cross-${CHOST}/${LIBC_TAR}"
if ! [[ -e ${LIBC_PATH} ]]; then
die "${LIBC_PATH} does not exist. Try running ./setup_board" \
die_notrace \
"${LIBC_PATH} does not exist. Try running ./setup_board" \
"--board=${BOARD} to update the version of libc installed on that board."
fi

View File

@ -65,14 +65,15 @@ parse_build_image_args() {
get_images_to_build ${FLAGS_ARGV}
if should_build_image ${CHROMEOS_TEST_IMAGE_NAME}; then
if should_build_image "${CHROMEOS_FACTORY_TEST_IMAGE_NAME}"; then
die "Cannot build both the test and factory_test images."
die_notrace "Cannot build both the test and factory_test images."
fi
fi
if should_build_image ${CHROMEOS_BASE_IMAGE_NAME} \
${CHROMEOS_DEVELOPER_IMAGE_NAME} ${CHROMEOS_TEST_IMAGE_NAME} \
${CHROMEOS_FACTORY_TEST_IMAGE_NAME} &&
should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then
die "Can't build ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME} with any other" \
die_notrace \
"Can't build ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME} with any other" \
"image."
fi
if should_build_image ${CHROMEOS_FACTORY_INSTALL_SHIM_NAME}; then

View File

@ -33,7 +33,7 @@ DEFINE_integer verity_max_ios 1024 \
# Parse flags
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
set -e
switch_to_strict_mode
# Only let dm-verity block if rootfs verification is configured.
dev_wait=0

View File

@ -19,14 +19,14 @@ FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Die on any errors
set -e
switch_to_strict_mode
# Check all parts of a pipe
set -o pipefail
ROOT="$FLAGS_root"
if [[ ! -d "$ROOT" ]]; then
die "Root FS does not exist ($ROOT)"
die_notrace "Root FS does not exist ($ROOT)"
fi
BINARIES="$ROOT/usr/bin/Xorg

View File

@ -70,7 +70,7 @@ eval set -- "${FLAGS_ARGV}"
check_flags_only_and_allow_null_arg "$@" && set --
# Die on any errors.
set -e
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
@ -167,7 +167,7 @@ fi
# 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 "emerge detected broken ebuilds. See error message above."
die_notrace "emerge detected broken ebuilds. See error message above."
fi
for pkg in ${CROS_WORKON_PKGS}; do

119
common.sh
View File

@ -7,8 +7,6 @@
# All scripts should die on error unless commands are specifically excepted
# by prefixing with '!' or surrounded by 'set +e' / 'set -e'.
# TODO: Re-enable this once shflags is less prone to dying.
#set -e
# The number of jobs to pass to tools that can run in parallel (such as make
# and dpkg-buildpackage
@ -52,21 +50,115 @@ if tput colors >/dev/null 2>&1; then
V_VIDOFF="$(tput sgr0)"
fi
# Stubs for sh compatibility.
function _dump_trace() { :; }
function _escaped_echo() {
printf '%b\n' "$*"
}
# Bash awareness, including stacktraces if possible.
if [ -n "${BASH_VERSION-}" ]; then
function _escaped_echo() {
echo -e "$@"
}
# Turn on bash debug support if available.
if shopt -s extdebug 2> /dev/null; then
# Pull the path relative to this lib; SCRIPT_ROOT should always be set,
# but has never been formally required.
if [ -n "${SOURCE_ROOT-}" ]; then
. "${SOURCE_ROOT}"/common_bash_backtraces.sh
else
x=$(readlink -f "${BASH_SOURCE[0]}")
. "${x%/*}"/common_bash_backtraces.sh
unset x
fi
fi
fi
# Declare these asap so that code below can safely assume they exist.
function _message {
local prefix="${1}"
shift
if [ $# -eq 0 ]; then
_escaped_echo >&2 "${prefix}${CROS_LOG_PREFIX:-""}:${V_VIDOFF}"
return
fi
(
# Handle newlines in the message, prefixing each chunk correctly.
# Do this in a subshell to avoid having to track IFS/set -f state.
IFS="
"
set +f
set -- $*
IFS=' '
if [ $# -eq 0 ]; then
# Empty line was requested.
set -- ''
fi
for line in "$@"; do
_escaped_echo >&2 "${prefix}${CROS_LOG_PREFIX:-}: ${line}${V_VIDOFF}"
done
)
}
function info {
echo -e >&2 "${V_BOLD_GREEN}INFO ${CROS_LOG_PREFIX:-""}: $@${V_VIDOFF}"
_message "${V_BOLD_GREEN}INFO " "$*"
}
function warn {
echo -e >&2 "${V_BOLD_YELLOW}WARNING ${CROS_LOG_PREFIX:-""}: $@${V_VIDOFF}"
_message "${V_BOLD_YELLOW}WARNING " "$*"
}
function error {
echo -e >&2 "${V_BOLD_RED}ERROR ${CROS_LOG_PREFIX:-""}: $@${V_VIDOFF}"
_message "${V_BOLD_RED}ERROR " "$*"
}
# For all die functions, they must explicitly force set +eu;
# no reason to have them cause their own crash if we're inthe middle
# of reporting an error condition then exiting.
function die_err_trap {
local command="$1" result="$2"
set +e +u
# Per the message, bash misreports 127 as 1 during err trap sometimes.
# Note this fact to ensure users don't place too much faith in the
# exit code in that case.
set -- "Command '${command}' exited with nonzero code: ${result}"
if [ -n "${BASH_VERSION-}" ]; then
if [ "$result" = 1 ] && [ -z "$(type -t $command)" ]; then
set -- "$@" \
'(Note bash sometimes misreports "command not found" as exit code 1 '\
'instead of 127)'
fi
fi
_dump_trace
error
error "Command failed:"
DIE_PREFIX=' '
die_notrace "$@"
}
# Exit this script due to a failure, outputting a backtrace in the process.
function die {
error "$@"
set +e +u
_dump_trace
error
error "Error was:"
DIE_PREFIX=' '
die_notrace "$@"
}
# Exit this script w/out a backtrace.
function die_notrace {
set +e +u
if [ $# -eq 0 ]; then
set -- '(no error message given)'
fi
for line in "$@"; do
error "${DIE_PREFIX}$line"
done
exit 1
}
@ -137,7 +229,7 @@ CHROMEOS_DEV_SETTINGS="${CHROMEOS_DEV_SETTINGS:-$SCRIPTS_DIR/.chromeos_dev}"
if [ -f "$CHROMEOS_DEV_SETTINGS" ]; then
# Turn on exit-on-error during custom settings processing
SAVE_OPTS=$(set +o)
set -e
switch_to_strict_mode
# Read settings
. "$CHROMEOS_DEV_SETTINGS"
@ -863,3 +955,16 @@ function show_help_if_requested() {
fi
done
}
function switch_to_strict_mode() {
# Set up strict execution mode; note that the trap
# must follow switch_to_strict_mode, else it will have no effect.
set -e
trap 'die_err_trap "${BASH_COMMAND:-command unknown}" "$?"' ERR
if [ $# -ne 0 ]; then
set "$@"
fi
}
# TODO: Re-enable this once shflags is set -e safe.
#switch_to_strict_mode

35
common_bash_backtraces.sh Normal file
View File

@ -0,0 +1,35 @@
# Copyright (c) 2012 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.
# Code used for bash stack dumps included by common.sh when we're in
# bash mode.
# Output a backtrace all the way back to the raw invocation, suppressing
# only the _dump_trace frame itself.
function _dump_trace {
local j n p func src line args
p=${#BASH_ARGV[@]}
for (( n = ${#FUNCNAME[@]}; n > 1; n-- )); do
func=${FUNCNAME[${n} - 1]}
src=${BASH_SOURCE[${n}]##*/}
line=${BASH_LINENO[${n} - 1]}
args=
if [[ -z ${BASH_ARGC[${n} -1]} ]]; then
args='(args unknown, no debug available)'
else
for (( j = 0 ; j < ${BASH_ARGC[${n} -1]} ; ++j )); do
args="${args:+${args} }'${BASH_ARGV[$(( p - j - 1 ))]}'"
done
! (( p -= ${BASH_ARGC[${n} - 1]} ))
fi
if [[ $n == ${#FUNCNAME[@]} ]]; then
error "script called: ${0##/*} ${args}"
error "Backtrace: (most recent call is last)"
else
error "$(printf ' file %s, line %s, called: %s %s' \
"${src}" "${line}" "${func}" "${args}")"
fi
done
}

View File

@ -159,9 +159,9 @@ function main() {
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
set -e
switch_to_strict_mode
[ -n "$FLAGS_board" ] || die "--board is required."
[ -n "$FLAGS_board" ] || die_notrace "--board is required."
SYSROOT="/build/${FLAGS_board}"

View File

@ -16,16 +16,16 @@ function usage() {
if [ -z "$1" ] ; then
usage
die "The URL or path to symbols tarball (debug.tgz) is required"
die_notrace "The URL or path to symbols tarball (debug.tgz) is required"
fi
if [ -z "$2" ] ; then
usage
die "The URL to BVT test results is required"
die_notrace "The URL to BVT test results is required"
fi
# Die on any errors.
set -e
switch_to_strict_mode
BREAKPAD_DIR="debug/breakpad"
STACKS_GENERATED=""

View File

@ -133,7 +133,7 @@ function main() {
fi
else
[ -n "${FLAGS_ARGV}" ] || usage
[ -n "${FLAGS_board}" ] || die "--board is required."
[ -n "${FLAGS_board}" ] || die_notrace "--board is required."
fi
local modules_file="${TMP}/modules"

View File

@ -20,7 +20,7 @@ eval set -- "${FLAGS_ARGV}"
# Check on the board that they are trying to set up.
if [ -z "$FLAGS_board" ] ; then
die "Error: --board required."
die_notrace "Error: --board required."
fi
IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}"
@ -28,13 +28,14 @@ IMAGES_DIR="${DEFAULT_BUILD_ROOT}/images/${FLAGS_board}"
# If there are no images, error out since presumably the
# caller isn't doing this for fun.
if [[ ! -d ${IMAGES_DIR} ]] ; then
die "${IMAGES_DIR} does not exist; have you run ./build_image?"
die_notrace \
"${IMAGES_DIR} does not exist; have you run ./build_image?"
fi
# Use latest link if it exists, otherwise most recently changed dir
if [ -L ${IMAGES_DIR}/latest ] ; then
if ! dst=$(readlink "${IMAGES_DIR}"/latest) ; then
die "Could not read ${IMAGES_DIR}/latest; have you run ./build_image?"
die_notrace "Could not read ${IMAGES_DIR}/latest; have you run ./build_image?"
fi
DEFAULT_FROM="${IMAGES_DIR}/${dst}"
else

View File

@ -23,11 +23,11 @@ DEFINE_string board "$DEFAULT_BOARD" \
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
[[ -z "${FLAGS_board}" ]] && die "A board must be specified."
[[ -z "${FLAGS_board}" ]] && die_notrace "A board must be specified."
if [[ -z "${FLAGS_ARGV}" ]]; then
warn "Please specify package."
die "Usage: ./get_package_list.sh chromeos-base/chromeos > package.list"
warn "Usage: ./get_package_list.sh chromeos-base/chromeos > package.list"
die_notrace "Please specify a package."
fi
emerge-$FLAGS_board --emptytree --usepkgonly -p -v --columns \

View File

@ -59,7 +59,7 @@ FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
if [ $# -gt 0 ]; then
die "Arguments aren't currently supported in image_to_usb."
die_notrace "Arguments aren't currently supported in image_to_usb."
fi
# Generates a descriptive string of a removable device. Includes the
@ -92,7 +92,7 @@ function are_you_sure() {
# Prohibit mutually exclusive factory/install flags.
if [ ${FLAGS_factory} -eq ${FLAGS_TRUE} -a \
${FLAGS_factory_install} -eq ${FLAGS_TRUE} ] ; then
die "Factory test image is incompatible with factory install shim"
die_notrace "Factory test image is incompatible with factory install shim"
fi
# Allow --from /foo/file.bin
@ -117,7 +117,7 @@ fi
# Die on any errors.
set -e
switch_to_strict_mode
# No board, no default and no image set then we can't find the image
if [ -z ${FLAGS_from} ] && [ -z ${FLAGS_board} ] ; then
@ -137,7 +137,7 @@ if [ -z "${FLAGS_from}" ]; then
fi
if [ ! -d "${FLAGS_from}" ] ; then
die "Cannot find image directory ${FLAGS_from}"
die_notrace "Cannot find image directory ${FLAGS_from}"
fi
# No target provided, attempt autodetection.
@ -192,7 +192,7 @@ if [ "${FLAGS_to}" == "/dev/sdX" ]; then
FLAGS_to="${disk_string%%:*}"
elif [ -n "${FLAGS_to_product}" ]; then
die "Cannot specify both --to and --to_product"
die_notrace "Cannot specify both --to and --to_product"
fi
# Guess ARCH if it's unset
@ -217,7 +217,7 @@ if [ -b "${FLAGS_to}" ]; then
disk_string=$(get_disk_string ${FLAGS_to})
elif [ ${FLAGS_force_non_usb} -ne ${FLAGS_TRUE} ]; then
# Safeguard against writing to a real non-USB disk or non-SD disk
die "${FLAGS_to} does not appear to be a USB/MMC disk," \
die_notrace "${FLAGS_to} does not appear to be a USB/MMC disk," \
"use --force_non_usb to override"
fi
fi
@ -295,7 +295,7 @@ fi
# Make sure that the selected image exists.
if [ ! -f "${SRC_IMAGE}" ]; then
die "Image not found: ${SRC_IMAGE}"
die_notrace "Image not found: ${SRC_IMAGE}"
fi
# Let's do it.

View File

@ -67,10 +67,10 @@ FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Die on any errors.
set -e
switch_to_strict_mode
if [ -z "${FLAGS_board}" ] ; then
die "--board is required."
die_notrace "--board is required."
fi
if [ "${FLAGS_full}" -eq "${FLAGS_TRUE}" ] && \
@ -213,7 +213,7 @@ elif [ "${FLAGS_format}" = "vmware" ]; then
qemu-img convert -f raw "${TEMP_IMG}" \
-O vmdk "${FLAGS_to}/${FLAGS_vmdk}"
else
die "Invalid format: ${FLAGS_format}"
die_notrace "Invalid format: ${FLAGS_format}"
fi
rm -rf "${TEMP_DIR}" "${TEMP_IMG}"

View File

@ -28,7 +28,7 @@ DEFINE_string image "" "Path to the image to use"
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
set -e
switch_to_strict_mode
# build_packages artifact output.
SYSROOT="${GCLIENT_ROOT}/chroot/build/${FLAGS_board}"
# build_image artifact output.

View File

@ -51,8 +51,8 @@ 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 'set -e' is specified before now.
set -e
# so will die prematurely if 'switch_to_strict_mode' is specified before now.
switch_to_strict_mode
if [ $FLAGS_verbose -eq $FLAGS_TRUE ]; then
# Make debugging with -v easy.
@ -79,7 +79,7 @@ get_install_vblock() {
sudo umount "$stateful_mnt"
rmdir "$stateful_mnt"
set -e
switch_to_strict_mode
echo "$out"
}
@ -245,7 +245,7 @@ install_recovery_kernel() {
sudo cp "$vmlinuz" "$esp_mnt/syslinux/vmlinuz.A" || failed=1
sudo umount "$esp_mnt"
rmdir "$esp_mnt"
set -e
switch_to_strict_mode
fi
if [ $failed -eq 1 ]; then
@ -325,7 +325,7 @@ maybe_resize_stateful() {
sudo mkdir "$new_stateful_mnt/var"
sudo umount "$new_stateful_mnt"
rmdir "$new_stateful_mnt"
set -e
switch_to_strict_mode
# Create a recovery image of the right size
# TODO(wad) Make the developer script case create a custom GPT with
@ -358,7 +358,7 @@ FLAGS_image=$(readlink -f "$FLAGS_image")
# Abort early if we can't find the image.
if [ ! -f "$FLAGS_image" ]; then
die "Image not found: $FLAGS_image"
die_notrace "Image not found: $FLAGS_image"
fi
IMAGE_DIR="$(dirname "$FLAGS_image")"
@ -380,12 +380,12 @@ SCRIPTS_DIR=${SCRIPT_ROOT}
if [ $FLAGS_kernel_image_only -eq $FLAGS_TRUE -a \
-n "$FLAGS_kernel_image" ]; then
die "Cannot use --kernel_image_only with --kernel_image"
die_notrace "Cannot use --kernel_image_only with --kernel_image"
fi
if [ $FLAGS_modify_in_place -eq $FLAGS_TRUE ]; then
if [ $FLAGS_minimize_image -eq $FLAGS_TRUE ]; then
die "Cannot use --modify_in_place and --minimize_image together."
die_notrace "Cannot use --modify_in_place and --minimize_image together."
fi
RECOVERY_IMAGE="${FLAGS_image}"
fi

View File

@ -42,8 +42,8 @@ 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 'set -e' is specified before now.
set -e
# so will die prematurely if 'switch_to_strict_mode' is specified before now.
switch_to_strict_mode
. "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1
. "${BUILD_LIBRARY_DIR}/mount_gpt_util.sh" || exit 1

View File

@ -42,7 +42,8 @@ cleanup() {
}
if [ ! -d "$VBOOT_DIR" ]; then
die "The required path: $VBOOT_DIR does not exist. This directory needs"\
die_notrace \
"The required path: $VBOOT_DIR does not exist. This directory needs"\
"to be sync'd into your chroot.\n $ cros_workon start vboot_reference"
fi

View File

@ -47,19 +47,19 @@ VBOOT_DIR="${CHROOT_TRUNK_DIR}/src/platform/vboot_reference/scripts/"\
"image_signing"
if [ ! -d $PYAUTO_DEP ]; then
die "The required path: $PYAUTO_DEP does not exist. Did you mean to pass \
--build_root and the path to the autotest bundle?"
die_notrace "The required path: $PYAUTO_DEP does not exist. Did you mean \
to pass --build_root and the path to the autotest bundle?"
fi
if [ ! -d $CHROME_DEP ]; then
die "The required path: $CHROME_DEP does not exist. Did you mean to pass \
--build_root and the path to the autotest bundle?"
die_notrace "The required path: $CHROME_DEP does not exist. Did you mean \
to pass --build_root and the path to the autotest bundle?"
fi
if [ ! -d $VBOOT_DIR ]; then
die "The required path: $VBOOT_DIR does not exist. This directory needs to \
be sync'd into your chroot.\n $ cros_workon start vboot_reference --board \
${FLAGS_board}"
die_notrace "The required path: $VBOOT_DIR does not exist. This directory \
needs to be sync'd into your chroot.\n $ cros_workon start vboot_reference \
--board ${FLAGS_board}"
fi
if [ ! -d "${FLAGS_build_root}/client/cros" ]; then

View File

@ -49,7 +49,7 @@ FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Die on error
set -e
switch_to_strict_mode
# Find the last image built on the board.
if [ ${FLAGS_most_recent} -eq ${FLAGS_TRUE} ] ; then
@ -60,7 +60,7 @@ fi
# If --from is a block device, --image can't also be specified.
if [ -b "${FLAGS_from}" ]; then
if [ "${FLAGS_image}" != "chromiumos_image.bin" ]; then
die "-i ${FLAGS_image} can't be used with block device ${FLAGS_from}"
die_notrace "-i ${FLAGS_image} can't be used with block device ${FLAGS_from}"
fi
fi
@ -68,7 +68,7 @@ fi
if [ -f "${FLAGS_from}" ]; then
# If --from is specified as a file, --image cannot be also specified.
if [ "${FLAGS_image}" != "chromiumos_image.bin" ]; then
die "-i ${FLAGS_image} can't be used with --from file ${FLAGS_from}"
die_notrace "-i ${FLAGS_image} can't be used with --from file ${FLAGS_from}"
fi
pathname=$(dirname "${FLAGS_from}")
filename=$(basename "${FLAGS_from}")
@ -95,7 +95,7 @@ function unmount_image() {
fi
sudo umount "${FLAGS_stateful_mountpt}"
sudo umount "${FLAGS_rootfs_mountpt}"
set -e
switch_to_strict_mode
}
function get_usb_partitions() {

View File

@ -75,9 +75,9 @@ fi
FLAGS_distfiles="${FLAGS_trunk}/distfiles"
# Only now can we die on error. shflags functions leak non-zero error codes,
# so will die prematurely if 'set -e' is specified before now.
# so will die prematurely if 'switch_to_strict_mode' is specified before now.
# TODO: replace shflags with something less error-prone, or contribute a fix.
set -e
switch_to_strict_mode
INNER_CHROME_ROOT=$FLAGS_chrome_root_mount # inside chroot
CHROME_ROOT_CONFIG="/var/cache/chrome_root" # inside chroot

View File

@ -54,9 +54,9 @@ assert_not_root_user
umask 022
# Only now can we die on error. shflags functions leak non-zero error codes,
# so will die prematurely if 'set -e' is specified before now.
# so will die prematurely if 'switch_to_strict_mode' is specified before now.
# TODO: replace shflags with something less error-prone, or contribute a fix.
set -e
switch_to_strict_mode
. "${SCRIPT_ROOT}"/sdk_lib/make_conf_util.sh

View File

@ -11,7 +11,7 @@
. "/usr/lib/crosutils/common.sh" || exit 1
# Die on any errors.
set -e
switch_to_strict_mode
SHARED_USER_PASSWD_FILE="/etc/shared_user_passwd.txt"

View File

@ -471,8 +471,8 @@ 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 'set -e' is specified before now.
set -e
# so will die prematurely if 'switch_to_strict_mode' is specified before now.
switch_to_strict_mode
if [ -z "$FLAGS_board" ] ; then
error "--board required."
@ -516,7 +516,7 @@ ARCH=$(get_board_arch "${BOARD}") || exit 1
case "$BOARD" in
*-host)
if [[ $FLAGS_usepkg -eq $FLAGS_TRUE ]]; then
die "host boards only support --nousepkg"
die_notrace "host boards only support --nousepkg"
fi
HOST_BOARD=true
;;

View File

@ -23,7 +23,7 @@ function main() {
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
set -e
switch_to_strict_mode
trap cleanup EXIT

View File

@ -51,7 +51,7 @@ DEFINE_string usb_disk /dev/sdb3 \
# Parse flags
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
set -e
switch_to_strict_mode
part_index_to_uuid() {
local image="$1"

View File

@ -35,8 +35,8 @@ 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 'set -e' is specified before now.
set -e
# 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

View File

@ -24,8 +24,8 @@ 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 'set -e' is specified before now.
set -e
# so will die prematurely if 'switch_to_strict_mode' is specified before now.
switch_to_strict_mode
function cleanup {
cleanup_remote_access

View File

@ -185,7 +185,9 @@ function main() {
MAX_TOTAL_ERRORS_FOR_RETRY=${TEST_MAX_TOTAL_ERRORS_FOR_RETRY}
fi
[ -n "$FLAGS_board" ] || die "--board is required."
switch_to_strict_mode
[ -n "$FLAGS_board" ] || die_notrace "--board is required."
SYSROOT="/build/${FLAGS_board}"

View File

@ -30,7 +30,7 @@ FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
if [ -z $FLAGS_image ] ; then
die "Use --image to specify a device or an image file."
die_notrace "Use --image to specify a device or an image file."
fi
# Turn path into an absolute path.
@ -38,10 +38,10 @@ FLAGS_image=$(eval readlink -f ${FLAGS_image})
# Abort early if we can't find the image
if [ ! -b ${FLAGS_image} ] && [ ! -f $FLAGS_image ] ; then
die "No image found at $FLAGS_image"
die_notrace "No image found at $FLAGS_image"
fi
set -e
switch_to_strict_mode
function get_partitions() {
if [ -b ${FLAGS_image} ] ; then
@ -99,7 +99,7 @@ cleanup
if [ "${expected_hash}" != "${generated_hash}" ]; then
warn "expected hash = ${expected_hash}"
warn "actual hash = ${generated_hash}"
die "Root filesystem has been modified unexpectedly!"
die_notrace "Root filesystem has been modified unexpectedly!"
else
info "Root filesystem checksum match!"
fi