Start of logging subsystem

This commit is contained in:
T. Joseph Carter 2015-03-27 16:45:38 -07:00
parent 12c13eb55d
commit 910a8010f8
5 changed files with 79 additions and 44 deletions

View File

@ -1,5 +1,6 @@
# vim: set ts=3 sw=3 noet ft=sh : bash
. "$BASE_DIR/script-modules/log.sh"
. "$BASE_DIR/script-modules/util.sh"
. "$BASE_DIR/script-modules/fetch-rules.sh"
. "$BASE_DIR/script-modules/cpu.sh"
@ -58,8 +59,6 @@ build_summary_log() {
else
export build_fail="$build_fail$2 "
fi
echo "Called with \"$@\""
echo "Build success: $build_success"
}
copy_core_to_dist() {
@ -350,44 +349,40 @@ build_libretro_test() {
}
build_summary() {
echo "Build success: $build_success"
summary() {
fmt_output="$(find_tool "fmt" "cat")"
local num_success="$(echo $build_success | wc -w)"
local fmt_success="$(echo " $build_success" | $fmt_output)"
local num_fail="$(echo $build_fail | wc -w)"
local fmt_fail="$(echo " $build_fail" | $fmt_output)"
echo ""
if [[ -z "$build_success" && -z "$build_fail" ]]; then
echo "No build actions performed."
return
fi
if [ -n "$build_success" ]; then
echo "$(color 32)$num_success core(s)$(color) successfully built:"
echo "$fmt_success"
fi
if [ -n "$build_fail" ]; then
echo "$(color 31)$num_fail core(s)$(color) failed to build:"
echo "$fmt_fail"
fi
if [ -n "$LIBRETRO_LOGDIR" ]; then
for output in "" ${LIBRETRO_LOG_SUPER:+$super_log}; do
if [ -n "$output" ]; then
exec 6>&1
exec > $output
use_color=""
fi
{
echo ""
if [[ -z "$build_success" && -z "$build_fail" ]]; then
echo "No build actions performed."
continue
fi
if [ -n "$build_success" ]; then
echo "$num_success core(s) successfully built:"
echo "$(color 32)$num_success core(s)$(color) successfully processed:"
echo "$fmt_success"
fi
if [ -n "$build_fail" ]; then
echo "$num_fail core(s) failed to build:"
echo "$(color 31)$num_fail core(s)$(color) failed:"
echo "$fmt_fail"
fi
} > $LIBRETRO_LOGDIR/build_summary.log 2>&1
fi
}
summary() {
build_summary
}
if [ -n "$output" ]; then
exec 1>&6 6>&-
use_color="$want_color"
fi
done
}
create_dist_dir() {

View File

@ -268,12 +268,36 @@ if [[ "$FORMAT_COMPILER_TARGET" = "osx" && -z "$NOUNIVERSAL" ]]; then
esac
fi
#LOGGING
#=======
# OUTPUT AND LOGGING
# ==================
#
# libretro-super has two kinds of output, the basic kind showing what the
# script is doing in a big-picture sense, and the commands and output from
# individual commands. End-users don't necessarily need to see this more
# detailed output, except when we're talking about huge cores like mame.
#
# If each can be directed to null, to the screen, to a log file, or to both
# the screen and a log file, you end up with the following truth table, along
# with my assessment of the usefulness of each combination:
#
# Basic Detailed Usefulness
# screen screen developer
# screen both developer
# both both developer
# screen log end-user
# log log buildbot
# Uncomment this to enable per-core logging
#LIBRETRO_LOGDIR=$WORKDIR/log
# Uncomment this to avoid clobbering logs
#LIBRETRO_LOG_APPEND=1
# Change this to adjust where logs are written
#LIBRETRO_LOG_DIR="$WORKDIR/log"
# Change this to rename the libretro-super main log file
#LIBRETRO_LOG_SUPER="libretro-super.txt"
# Change this to rename core log files (%s for core's "safe" name)
#LIBRETRO_LOG_CORE="%s.txt"
# BUILD_REVISIONS
# ===============

View File

@ -15,6 +15,7 @@ else
fi
. "$BASE_DIR/libretro-config.sh"
. "$BASE_DIR/script-modules/log.sh"
. "$BASE_DIR/script-modules/util.sh"
. "$BASE_DIR/script-modules/fetch-rules.sh"
. "$BASE_DIR/script-modules/modules.sh"

28
script-modules/log.sh Normal file
View File

@ -0,0 +1,28 @@
# vim: set ts=3 sw=3 noet ft=sh : bash
color() {
[ -n "$use_color" ] && echo -n "[0;${1:-0}m"
}
lecho() {
if [ -n "$LIBRETRO_LOG_SUPER" ]; then
echo "$@" >> $super_log
fi
}
LIBRETRO_LOG_DIR="${LIBRETRO_LOG_DIR:-$WORKDIR/log}"
LIBRETRO_LOG_SUPER="${LIBRETRO_LOG_SUPER:-libretro-super.txt}"
LIBRETRO_LOG_CORE="${LIBRETRO_LOG_CORE:-%s.txt}"
mkdir -p "$LIBRETRO_LOG_DIR"
if [ -n "$LIBRETRO_LOG_SUPER" ]; then
super_log="$LIBRETRO_LOG_DIR/$LIBRETRO_LOG_SUPER"
fi
if [[ -t 1 || -n $FORCE_COLOR ]]; then
want_color=1
use_color=1
else
want_color=""
use_color=""
fi

View File

@ -15,16 +15,3 @@ find_tool() {
shift
done
}
color() {
[ -n "$NO_COLOR" ] && return
echo -n "[0;${1:-0}m"
}
if [ ! -t 1 ]; then
if [ -z "$FORCE_COLOR" ]; then
NO_COLOR=1
fi
fi