Skip to content

Commit

Permalink
Merge pull request #805 from dapphub/color-build-output
Browse files Browse the repository at this point in the history
dapp: build: strip escape chars and colorize output
  • Loading branch information
d-xo authored Sep 23, 2021
2 parents 28cb13f + db8bc56 commit f4d0fcf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/dapp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
9 changes: 8 additions & 1 deletion src/dapp/libexec/dapp/dapp-build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit f4d0fcf

Please sign in to comment.