In Bazel, a successful build should be a quiet build. While build failures
should, of course, print ample information to stderr to aide in troubleshooting,
any custom Bazel code you write should not output progress information to stdout
or stderr. Let Bazel be responsible for overall build progress reporting.
For genrule or bash-based targets, I’ll often implement this by capturing
all output to a log file and only printing the log file if the target fails.
For example:
#!/bin/bash
## This is a bash build script that may be invoked in something like# ctx.actions.run() in a custom bazel ruleset -euo pipefail
# Perform all cleanupcleanup(){# Output the build log on failuresif["$1" !="0"]; thenif[[ -v LOG_FILE ]]; thenif[[ -r $LOG_FILE]]; thenecho"Build log:" 1>&2 cat $LOG_FILE 1>&2fififiif[[ -v TMP_DIR ]]; then rm -rf $TMP_DIRfi}trap'cleanup $?' EXIT
# Ensure all build steps log stdout and stderr to LOG_FILETMP_DIR=$(mktemp -d)LOG_FILE=$TMP_DIR/build.log
# Perform build stepsbuild_step1 >> $LOG_FILE 2>&1build_step2 >> $LOG_FILE 2>&1...