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>
108 lines
3.6 KiB
Bash
Executable File
108 lines
3.6 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.
|
|
|
|
# Script to modify a keyfob-based chromeos system image for testability.
|
|
#
|
|
# N.B. This script duplicates function provided by
|
|
# "build_image --test"; that command option is the preferred
|
|
# command line interface for creating a test image. Please don't
|
|
# add features (options, command line syntax, whatever) to this
|
|
# script, unless it's necessary to maintain compatibility with
|
|
# "build_image".
|
|
#
|
|
# TODO(vlaviano): delete this script.
|
|
|
|
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
|
|
. "${SCRIPT_ROOT}/build_library/build_common.sh" || exit 1
|
|
|
|
|
|
DEFINE_string board "$DEFAULT_BOARD" "Board for which the image was built" b
|
|
DEFINE_boolean factory $FLAGS_FALSE \
|
|
"Modify the image for manufacturing testing" f
|
|
DEFINE_string image "" "Location of the rootfs raw image file" i
|
|
DEFINE_integer jobs -1 \
|
|
"How many packages to build in parallel at maximum." j
|
|
DEFINE_boolean yes $FLAGS_FALSE "Answer yes to all prompts" y
|
|
DEFINE_boolean fast $DEFAULT_FAST "Call many emerges in parallel"
|
|
DEFINE_boolean inplace $FLAGS_TRUE \
|
|
"Modify/overwrite the image $CHROMEOS_IMAGE_NAME in place. \
|
|
Otherwise the image will be copied to $CHROMEOS_TEST_IMAGE_NAME \
|
|
(or $CHROMEOS_FACTORY_TEST_IMAGE_NAME for --factory) if needed, and \
|
|
modified there"
|
|
DEFINE_boolean force_copy $FLAGS_FALSE \
|
|
"Always rebuild test image if --noinplace"
|
|
DEFINE_boolean standard_backdoor ${FLAGS_TRUE} \
|
|
"Install standard backdoor credentials for testing"
|
|
|
|
# Parse command line
|
|
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
|
|
|
|
. "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1
|
|
. "${BUILD_LIBRARY_DIR}/mount_gpt_util.sh" || exit 1
|
|
. "${BUILD_LIBRARY_DIR}/test_image_util.sh" || exit 1
|
|
|
|
|
|
# No image was provided. Use the standard latest image
|
|
if [ -z "$FLAGS_image" ]; then
|
|
IMAGES_DIR="$($SCRIPT_ROOT/get_latest_image.sh --board=$BOARD)"
|
|
FLAGS_image="$IMAGES_DIR/$CHROMEOS_IMAGE_NAME"
|
|
fi
|
|
|
|
# Turn path into an absolute path.
|
|
FLAGS_image=$(eval readlink -f "$FLAGS_image")
|
|
|
|
# Setting for build scripts.
|
|
BUILD_DIR="$(dirname "$FLAGS_image")"
|
|
|
|
ROOT_FS_DIR="${BUILD_DIR}/rootfs"
|
|
STATEFUL_FS_DIR="${BUILD_DIR}/stateful_partition"
|
|
|
|
# Copy the image to a test location if required
|
|
if [ $FLAGS_inplace -eq $FLAGS_FALSE ]; then
|
|
if [ $FLAGS_factory -eq $FLAGS_TRUE ]; then
|
|
TEST_PATHNAME="$BUILD_DIR/$CHROMEOS_FACTORY_TEST_IMAGE_NAME"
|
|
else
|
|
TEST_PATHNAME="$BUILD_DIR/$CHROMEOS_TEST_IMAGE_NAME"
|
|
fi
|
|
if [ ! -f "$TEST_PATHNAME" -o $FLAGS_force_copy -eq $FLAGS_TRUE ]; then
|
|
copy_image $(basename "$FLAGS_image") $(basename "$TEST_PATHNAME")
|
|
FLAGS_image="$TEST_PATHNAME"
|
|
else
|
|
echo "Using cached $(basename "${TEST_PATHNAME}")"
|
|
exit
|
|
fi
|
|
|
|
# No need to confirm now, since we are not overwriting the main image
|
|
FLAGS_yes=$FLAGS_TRUE
|
|
fi
|
|
|
|
# Abort early if we can't find the image
|
|
if [ ! -f "$FLAGS_image" ]; then
|
|
echo "No image found at $FLAGS_image"
|
|
exit 1
|
|
fi
|
|
|
|
# Make sure this is really what the user wants, before nuking the device
|
|
if [ $FLAGS_yes -ne $FLAGS_TRUE ]; then
|
|
read -p "Modifying image $FLAGS_image for test; are you sure (y/N)? " SURE
|
|
SURE="${SURE:0:1}" # Get just the first character
|
|
if [ "$SURE" != "y" ]; then
|
|
echo "Ok, better safe than sorry."
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "Modifying image $FLAGS_image for test..."
|
|
fi
|
|
|
|
mod_image_for_test $(basename "$FLAGS_image")
|
|
|
|
print_time_elapsed
|