Skip to content

Commit

Permalink
Allow outputting the progress of Bazel's build.
Browse files Browse the repository at this point in the history
Rename run_silent to run and add a global VERBOSE variable that tunes
whether the run function prints its output or not.

This is for better debugging possibilities of Bazel's self-build, though
compile.sh remains silent as before and only displays the command's output
in case of an error.

--
MOS_MIGRATED_REVID=115599355
  • Loading branch information
jmmv authored and philwo committed Feb 26, 2016
1 parent cdf3160 commit 5909d9d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
5 changes: 5 additions & 0 deletions compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ set -o errexit

cd "$(dirname "$0")"

# Set the default verbose mode in buildenv.sh so that we do not display command
# output unless there is a failure. We do this conditionally to offer the user
# a chance of overriding this in case they want to do so.
: ${VERBOSE:=no}

source scripts/bootstrap/buildenv.sh

function usage() {
Expand Down
4 changes: 2 additions & 2 deletions scripts/bootstrap/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ function bootstrap_test() {
local BAZEL_SUM=$2
local BAZEL_TARGET=${3:-src:bazel}
[ -x "${BAZEL_BIN}" ] || fail "syntax: bootstrap bazel-binary"
run_silent ${BAZEL_BIN} --nomaster_bazelrc --bazelrc=${BAZELRC} clean \
run ${BAZEL_BIN} --nomaster_bazelrc --bazelrc=${BAZELRC} clean \
--expunge || return $?
run_silent ${BAZEL_BIN} --nomaster_bazelrc --bazelrc=${BAZELRC} build \
run ${BAZEL_BIN} --nomaster_bazelrc --bazelrc=${BAZELRC} build \
${EXTRA_BAZEL_ARGS-} \
--strategy=Javac=worker --worker_quit_after_build \
--fetch --nostamp \
Expand Down
29 changes: 23 additions & 6 deletions scripts/bootstrap/buildenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ msys*|mingw*)
EXE_EXT=".exe"
esac

# Whether we display build messages or not. We set this conditionally because
# the file including us or the user may already have defined VERBOSE to their
# liking.
: ${VERBOSE:=yes}

# List of functions to invoke on exit.
ATEXIT_HANDLERS=

Expand Down Expand Up @@ -109,12 +114,24 @@ eval "cleanup_phasefile() {
}"
atexit cleanup_phasefile

function run_silent() {
echo "${@}" >${errfile}
# TODO(kchodorow): figure out why this doesn't exit on a non-zero exit code,
# even though errexit is set.
"${@}" >>${errfile} 2>&1 || exit $?
rm ${errfile}
# Excutes a command respecting the current verbosity settings.
#
# If VERBOSE is yes, the command itself and its output are printed.
# If VERBOSE is no, the command's output is only displayed in case of failure.
#
# Exits the script if the command fails.
function run() {
if [ "${VERBOSE}" = yes ]; then
echo "${@}"
"${@}" || exit $?
else
echo "${@}" >"${errfile}"
# The exit here is needed because "set -e" on the shell does not cause
# errors in functions to exit in all cases. We should probably disable
# "set -e" altogether and add explicit error handling where necessary.
"${@}" >>"${errfile}" 2>&1 || exit $?
rm "${errfile}"
fi
}

function fail() {
Expand Down
8 changes: 4 additions & 4 deletions scripts/bootstrap/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ function java_compilation() {
cat "$paramfile" >&2
fi

run_silent "${JAVAC}" -classpath "${classpath}" -sourcepath "${sourcepath}" \
run "${JAVAC}" -classpath "${classpath}" -sourcepath "${sourcepath}" \
-d "${output}/classes" -source "$JAVA_VERSION" -target "$JAVA_VERSION" \
-encoding UTF-8 "@${paramfile}"

log "Extracting helper classes for $name..."
for f in ${library_jars} ; do
run_silent unzip -qn ${f} -d "${output}/classes"
run unzip -qn ${f} -d "${output}/classes"
done
}

Expand All @@ -151,13 +151,13 @@ function create_deploy_jar() {

log "Creating $name.jar..."
echo "Main-Class: $mainClass" > $output/MANIFEST.MF
run_silent "$JAR" cmf $output/MANIFEST.MF $output/$name.jar $packages "$@"
run "$JAR" cmf $output/MANIFEST.MF $output/$name.jar $packages "$@"
}

if [ -z "${BAZEL_SKIP_JAVA_COMPILATION}" ]; then
log "Compiling Java stubs for protocol buffers..."
for f in $PROTO_FILES ; do
run_silent "${PROTOC}" -Isrc/main/protobuf/ --java_out=${OUTPUT_DIR}/src "$f"
run "${PROTOC}" -Isrc/main/protobuf/ --java_out=${OUTPUT_DIR}/src "$f"
done

java_compilation "Bazel Java" "$DIRS" "$LIBRARY_JARS" "${OUTPUT_DIR}"
Expand Down

0 comments on commit 5909d9d

Please sign in to comment.