summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-06-23 21:21:12 +0200
committertomsmeding <tom.smeding@gmail.com>2017-06-23 21:21:12 +0200
commit858caaa0abd38434308dba5ffdb71441a3aee39e (patch)
treeb7f69a5ae15e80406c8116beba6c6cd0e63b9380
InitialHEADmaster
-rwxr-xr-xcargo-build-succinct.sh65
1 files changed, 65 insertions, 0 deletions
diff --git a/cargo-build-succinct.sh b/cargo-build-succinct.sh
new file mode 100755
index 0000000..83ccb29
--- /dev/null
+++ b/cargo-build-succinct.sh
@@ -0,0 +1,65 @@
+#!/usr/bin/env bash
+
+colour_output=0
+test -t 1 && colour_output=1
+
+function bold() {
+ if [[ $colour_output = 1 ]]; then
+ printf "\x1B[1;33m$*\x1B[0m\n"
+ else
+ printf "$*\n"
+ fi
+}
+
+function bold_err() {
+ if [[ $colour_output = 1 ]]; then
+ printf "\x1B[1;31m$*\x1B[0m\n"
+ else
+ printf "$*\n"
+ fi
+}
+
+function succinct_output() {
+ local in_err errprefix errloc errsuffix missing_string
+ in_err=0
+ missing_string="$(bold_err '???')"
+ errprefix="$missing_string"
+ errloc="$missing_string"
+ errsuffix="$missing_string"
+
+ function output_reset() {
+ if [[ $3 =~ due\ to\ .*previous\ error ||
+ $3 =~ ^Could\ not\ compile\ ]]; then
+ return
+ fi
+ echo "$1: $2: $(bold "$3")"
+ errprefix="$missing_string"
+ errloc="$missing_string"
+ errsuffix="$missing_string"
+ }
+
+ while IFS=$'\n' read line; do
+ if [[ $line =~ ^(error|warning|help|note) ]]; then
+ if [[ $in_err = 1 ]]; then
+ output_reset "$errprefix" "$errloc" "$errsuffix"
+ fi
+
+ in_err=1
+ errprefix="$(cut -d: -f1 <<<"$line")"
+ errsuffix="$(cut -d: -f2- <<<"$line" | cut -c 2-)"
+ elif [[ $in_err = 1 && $line =~ ^[\ \t]*--\> ]]; then
+ errloc="$(sed 's/^.*--> //' <<<"$line")"
+ elif [[ $in_err = 1 && $line = "" ]]; then
+ output_reset "$errprefix" "$errloc" "$errsuffix"
+ in_err=0
+ elif [[ $in_err = 0 &&
+ $line != "To learn more, run the command again with --verbose." ]]; then
+ echo "$line"
+ fi
+ done
+ if [[ $in_err = 1 ]]; then
+ output_reset "$errprefix" "$errloc" "$errsuffix"
+ fi
+}
+
+cargo build "$@" 2>&1 | succinct_output