flatcar-scripts/upload_symbols
Ken Mixter f5adf798f0 crosutils: Detect sym_upload errors by its stdout instead of return value
Change-Id: If649d355f3d9cb2650613e4eb6d34813216c0b61

BUG=7516
TEST=Change hardcoded URL to illegal URL and verify symbol sends fail

Review URL: http://codereview.chromium.org/3635001
2010-10-07 17:54:04 -07:00

142 lines
4.4 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.
# Script to upload all debug symbols required for crash reporting
# purposes. This script need only be used to upload release builds
# symbols or to debug crashes on non-release builds (in which case try
# to only upload the symbols for those executables involved).
#
# NOTE: This script must be run from the chromeos build chroot environment.
#
# Load common constants. This should be the first executable line.
# The path to common.sh should be relative to your script's location.
. "$(dirname "$0")/common.sh"
# Script must be run inside the chroot
restart_in_chroot_if_needed $*
get_default_board
# Flags
DEFINE_string board "$DEFAULT_BOARD" "The board to build packages for."
DEFINE_string breakpad_root "" "Root directory for breakpad symbols."
DEFINE_boolean official_build ${FLAGS_FALSE} "Point to official symbol server."
DEFINE_boolean regenerate ${FLAGS_FALSE} "Regenerate all symbols."
DEFINE_boolean verbose ${FLAGS_FALSE} "Be verbose."
DEFINE_boolean yes ${FLAGS_FALSE} "Answer yes to all prompts."
SYM_UPLOAD="sym_upload"
ANY_ERRORS=0
OUT_DIR=$(mktemp -d "/tmp/err.XXXX")
function cleanup() {
rm -rf "${OUT_DIR}"
}
function really_upload() {
if [ ${FLAGS_yes} -eq ${FLAGS_TRUE} ]; then
return 0
fi
echo "Uploading symbols for an entire Chromium OS build is really only "
echo "necessary for release builds and in a few cases for developers "
echo "to debug problems. It will take considerable time to run. For "
echo "developer debugging purposes, consider instead passing specific files "
echo "to upload."
read -p "Are you sure you want to upload all build symbols (y/N)? " SURE
SURE="${SURE:0:1}" # Get just the first character
if [ "${SURE}" != "y" ]; then
echo "Ok, better safe than sorry."
return 1
fi
return 0
}
# Upload the given symbol file to given URL.
function upload_file() {
local upload_file="$1"
local upload_url="$2"
if [ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]; then
info "Uploading ${upload_file}"
fi
"${SYM_UPLOAD}" "${upload_file}" "${upload_url}" > "${OUT_DIR}/stdout" \
2> "${OUT_DIR}/stderr"
if ! grep -q "Successfully sent the symbol file." "${OUT_DIR}/stdout"; then
error "Unable to upload symbols in ${upload_file}:"
cat "${OUT_DIR}/stderr"
ANY_ERRORS=1
return 1
fi
if [ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]; then
size=$(wc -c "${upload_file}" | cut -d' ' -f1)
info "Successfully uploaded ${size}B."
fi
return 0
}
function main() {
trap cleanup EXIT
# Parse command line
FLAGS_HELP="usage: $0 [flags] [<files...>]"
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
set -e
[ -n "$FLAGS_board" ] || die "--board is required."
SYSROOT="/build/${FLAGS_board}"
local upload_url=""
if [ $FLAGS_official_build -eq $FLAGS_TRUE ]; then
upload_url="http://clients2.google.com/cr/symbol"
else
upload_url="http://clients2.google.com/cr/staging_symbol"
warn "This is an unofficial build, uploading to staging server."
fi
info "Uploading symbols to ${upload_url} from ${SYSROOT}."
DEFAULT_BREAKPAD_ROOT="${SYSROOT}/usr/lib/debug/breakpad"
if [ -z "${FLAGS_breakpad_root}" ]; then
FLAGS_breakpad_root="${DEFAULT_BREAKPAD_ROOT}"
else
if [ ${FLAGS_regenerate} -eq ${FLAGS_TRUE} ]; then
warn "Assuming --noregenerate when --breakpad_root is specified"
FLAGS_regenerate=${FLAGS_FALSE}
fi
fi
if [ -z "${FLAGS_ARGV}" ]; then
if [ ${FLAGS_regenerate} -eq ${FLAGS_TRUE} ]; then
really_upload || exit 1
info "Clearing ${DEFAULT_BREAKPAD_ROOT}"
sudo rm -rf "${DEFAULT_BREAKPAD_ROOT}"
info "Generating all breakpad symbol files."
local verbosity=""
local generate_script="$(dirname $0)/cros_generate_breakpad_symbols"
[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ] && verbosity="--verbose"
if ! "${generate_script}" --board=${FLAGS_board} ${verbosity}; then
error "Some errors while generating symbols; uploading anyway"
ANY_ERRORS=1
fi
fi
info "Uploading all breakpad symbol files."
for sym_file in $(find "${FLAGS_breakpad_root}" -name \*.sym); do
! upload_file "${sym_file}" "${upload_url}"
done
else
error "Unexpected args ${FLAGS_ARGV}"
fi
[ ${ANY_ERRORS} -ne 0 ] && die "Encountered problems"
return 0
}
main "$@"