From db8bc560b01fdec474bd20cfb1928fb2ebf52999 Mon Sep 17 00:00:00 2001 From: David Terry Date: Tue, 21 Sep 2021 14:27:34 +0200 Subject: [PATCH] dapp: build: strip escape chars and colorize output - strips '\' chars from the output - colors errors in red, and warnings in yellow --- src/dapp/CHANGELOG.md | 4 ++++ src/dapp/libexec/dapp/dapp-build | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/dapp/CHANGELOG.md b/src/dapp/CHANGELOG.md index 1fe63feb0..3cf8a1fd9 100644 --- a/src/dapp/CHANGELOG.md +++ b/src/dapp/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- The output from `dapp build` now uses color to differentiate warnings and errors + ### Changed - Dapp remappings ignores non-directories in `DAPP_LIB` diff --git a/src/dapp/libexec/dapp/dapp-build b/src/dapp/libexec/dapp/dapp-build index 2e9497067..4dbc52980 100755 --- a/src/dapp/libexec/dapp/dapp-build +++ b/src/dapp/libexec/dapp/dapp-build @@ -27,6 +27,13 @@ info() { echo >&2 "$FLAGS" "${0##*/}: $ARGS" } +colorize() { + awk '{ +gsub("Warning:", "\033[1;33m&\033[0m"); +gsub(".*Error:", "\033[1;31m&\033[0m"); +print }' +} + cd "$DAPP_ROOT" # use a custom path if DAPP_SOLC is set @@ -68,7 +75,7 @@ if [[ -z "$DAPP_BUILD_LEGACY" && -z "$DAPP_BUILD_EXTRACT" ]]; then # pipe errors to stderr jq -r 'if .errors then .errors | map(."formattedMessage") | @sh else empty end' "$DAPP_JSON" \ - | sed -e "s/' //g" -e "s/'//g" 1>&2 + | sed -e "s/' //g" -e "s/'//g" -e 's/\\\(.\)\\/\1 /g' | colorize 1>&2 # if sources is empty, the compilation failed [[ $(jq -r '.sources' "$DAPP_JSON") = "null" || $(jq -r '.sources' "$DAPP_JSON") = {} ]] && exit 1 || exit 0