blob: 08189296e2b7aa932f4c06879d5212200fe84211 [file] [log] [blame]
#!/bin/bash
# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#### CATEGORY=Run, inspect and debug
### generate a report of error conditions
## usage: fx triage [--config <config-file>]
## [--bugreport <path-to-bugreport>]
## Processes "fx bugreport" output looking for problems specified in a config
## file. If no bugreport output is specified (no '--inspect') it runs a new
## "fx bugreport" and uses its "inspect.json" file.
##
## --config <config-file-or-dir> Path to config file or dir
## --bugreport <dir> Directory to get an inspect.json file from
## --tag <tag> Adds an action tag to include
## --exclude-tag <tag> Adds an action tag to exclude
## --test (deprecated) Run self-tests (only)
##
## 0 or more --config paths may be given. Path is relative to CWD, or absolute.
## If path is a directory, path/*.triage will be loaded.
## If 0 paths are given, config defaults to
## /src/diagnostics/config/triage/*.triage.
##
## 0 or more --tag values may be given. If tags are provided, only actions with
## matching tags will be included.
##
## 0 or more --exclude-tag values may be given. If exclude tags are provided,
## actions with matching tags will be excluded. This value is ignored if
## any --tag values are included.
##
## If no --tag values or --exclude-tag values are included then all of the
## actions will be included.
##
## 0 or more --bugreport paths may be given. Path is relative to CWD, or
## absolute. Each path is a directory containing an unpacked "bugreport.zip".
## If no --bugreport is given, `fx bugreport` will be invoked and analyzed.
set -e
trap 'echo Failed: ${BASH_COMMAND}' ERR
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"\
/../lib/image_build_vars.sh
# Defaults.
config_paths=( )
testit=""
directories=( )
tags=( )
exclude_tags=( )
flags=""
# Flag parsing.
while [[ "$1" =~ ^- ]]; do
case "$1" in
-h|--help)
fx-command-help
exit 0
;;
--config)
shift
config_paths+=( "$1" )
;;
--bugreport)
shift
directories+=( "$1" )
;;
--tag)
shift
tags+=( "$1" )
;;
--exclude-tag)
shift
exclude_tags+=( "$1" )
;;
--test)
testit="yes"
;;
*)
echo Bad option "$1"
echo
fx-command-help
exit 1
esac
shift
done
triage_exe="${HOST_OUT_DIR}/../host-tools/triage"
if [[ -n "$testit" ]]; then
echo "[ERROR] fx triage --test is deprecated!"
echo "please use 'fx test triage_lib_test' instead"
exit
fi
if (( !"${#config_paths[@]}" )); then
config_paths=( "${FUCHSIA_DIR}/src/diagnostics/config/triage/" )
fi
config_files=( )
for config_path in "${config_paths[@]}"; do
if [[ -d "${config_path}" ]] ; then
config_files+=( "${config_path}"/*.triage )
else
config_files+=( "${config_path}" )
fi
done
for config_file in "${config_files[@]}"
do
flags="${flags} --config ${config_file}"
done
if [ -z "${directories}" ]; then
temp_dir=$(mktemp -d)
trap 'rm -rf "${temp_dir}"' EXIT
fx-command-run bugreport --output-directory "${temp_dir}" > /dev/null
unzip "${temp_dir}/bugreport.zip" -d "${temp_dir}" > /dev/null
directories+="${temp_dir}"
fi
for directory in "${directories[@]}"
do
flags="${flags} --bugreport ${directory}"
done
for tag in "${tags[@]}"
do
flags="${flags} --tag ${tag}"
done
for tag in "${exclude_tags[@]}"
do
flags="${flags} --exclude-tag ${tag}"
done
if [[ ! -f "$triage_exe" ]]; then
echo "Building Triage..."
fx-command-run build triage
fi
echo "${triage_exe} ${flags}"
$triage_exe ${flags}