From 5909d9dc9ee0248a45cfbbc0ed2123e84824c2a1 Mon Sep 17 00:00:00 2001 From: Julio Merino Date: Thu, 25 Feb 2016 21:44:31 +0000 Subject: Allow outputting the progress of Bazel's build. 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 --- compile.sh | 5 +++++ scripts/bootstrap/bootstrap.sh | 4 ++-- scripts/bootstrap/buildenv.sh | 29 +++++++++++++++++++++++------ scripts/bootstrap/compile.sh | 8 ++++---- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/compile.sh b/compile.sh index 485d54c5fa..24a179f05a 100755 --- a/compile.sh +++ b/compile.sh @@ -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() { diff --git a/scripts/bootstrap/bootstrap.sh b/scripts/bootstrap/bootstrap.sh index 13e71c0e6f..2fea800680 100755 --- a/scripts/bootstrap/bootstrap.sh +++ b/scripts/bootstrap/bootstrap.sh @@ -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 \ diff --git a/scripts/bootstrap/buildenv.sh b/scripts/bootstrap/buildenv.sh index fa692046ee..98eacf7a26 100755 --- a/scripts/bootstrap/buildenv.sh +++ b/scripts/bootstrap/buildenv.sh @@ -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= @@ -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() { diff --git a/scripts/bootstrap/compile.sh b/scripts/bootstrap/compile.sh index 9195e7a48c..e5857195ba 100755 --- a/scripts/bootstrap/compile.sh +++ b/scripts/bootstrap/compile.sh @@ -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 } @@ -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}" -- cgit v1.2.3