windows,test: add logging to bootstrap test

Add logging to bazel_bootstrap_distfile_test in
case it is running on Windows. The logging will
help collect basic performance stats.

Also remove the %N placeholder from `date` format
string in the log messages, because macOS doesn't
support it.

See https://github.com/bazelbuild/bazel/issues/4503

Change-Id: Idf00bf1512d02a793b27e1cc761fbcd630e79618
PiperOrigin-RevId: 183642578
diff --git a/src/test/shell/bazel/bazel_bootstrap_distfile_test.sh b/src/test/shell/bazel/bazel_bootstrap_distfile_test.sh
index 9ae1a2c..9b0375a 100755
--- a/src/test/shell/bazel/bazel_bootstrap_distfile_test.sh
+++ b/src/test/shell/bazel/bazel_bootstrap_distfile_test.sh
@@ -30,20 +30,32 @@
 source $(rlocation io_bazel/src/test/shell/integration_test_setup.sh) \
   || { echo "integration_test_setup.sh not found!" >&2; exit 1; }
 
+function _log_progress() {
+  if [[ "$PLATFORM" =~ msys ]]; then
+    log_info "test_bootstrap: $*"
+  fi
+}
+
 function test_bootstrap()  {
+    _log_progress "start"
     local olddir=$(pwd)
     WRKDIR=$(mktemp -d ${TEST_TMPDIR}/bazelbootstrap.XXXXXXXX)
     mkdir -p "${WRKDIR}" || fail "Could not create workdir"
     trap "rm -rf \"$WRKDIR\"" EXIT
     cd "${WRKDIR}" || fail "Could not change to work directory"
     export SOURCE_DATE_EPOCH=1501234567
+    _log_progress "unzip"
     unzip -q "${DISTFILE}"
+    _log_progress "bootstrap"
     env EXTRA_BAZEL_ARGS="--curses=no --strategy=Javac=standalone" ./compile.sh \
         || fail "Expected to be able to bootstrap bazel"
+    _log_progress "run"
     ./output/bazel version > "${TEST_log}" || fail "Generated bazel not working"
     ./output/bazel shutdown
+    _log_progress "assert"
     expect_log "${SOURCE_DATE_EPOCH}"
     cd "${olddir}"
+    _log_progress "done"
 }
 
 run_suite "bootstrap test"
diff --git a/src/test/shell/testenv.sh b/src/test/shell/testenv.sh
index 6a7476c..5293f3f 100755
--- a/src/test/shell/testenv.sh
+++ b/src/test/shell/testenv.sh
@@ -33,7 +33,7 @@
 function _log_base() {
   prefix=$1
   shift
-  echo >&2 "${prefix}[$(basename "$0") $(date "+%H:%M:%S.%N (%z)")] $*"
+  echo >&2 "${prefix}[$(basename "$0") $(date "+%Y-%m-%d %H:%M:%S (%z)")] $*"
 }
 
 function log_info() {
@@ -45,6 +45,9 @@
   exit 1
 }
 
+if ! type rlocation &> /dev/null; then
+  log_fatal "rlocation() is undefined"
+fi
 
 # Set some environment variables needed on Windows.
 if is_windows; then
@@ -98,17 +101,6 @@
 [ -z "$TEST_SRCDIR" ] && log_fatal "TEST_SRCDIR not set!"
 BAZEL_RUNFILES="$TEST_SRCDIR/io_bazel"
 
-if ! type rlocation &> /dev/null; then
-  function rlocation() {
-    if [[ "$1" = /* ]]; then
-      echo $1
-    else
-      echo "$TEST_SRCDIR/$1"
-    fi
-  }
-  export -f rlocation
-fi
-
 # WORKSPACE file
 workspace_file="${BAZEL_RUNFILES}/WORKSPACE"
 
@@ -463,10 +455,11 @@
 # Clean-up the bazel install base
 function cleanup() {
   if [ -d "${BAZEL_INSTALL_BASE:-__does_not_exists__}" ]; then
+    log_info "Cleaning up BAZEL_INSTALL_BASE under $BAZEL_INSTALL_BASE"
     # Windows takes its time to shut down Bazel and we can't delete A-server.jar
     # until then, so just give it time and keep trying for 2 minutes.
     for i in {1..120}; do
-      if rm -fr "${BAZEL_INSTALL_BASE}" ; then
+      if rm -fr "${BAZEL_INSTALL_BASE}" >&/dev/null ; then
         break
       fi
       if (( i == 10 )) || (( i == 30 )) || (( i == 60 )) ; then
diff --git a/tools/test/test-setup.sh b/tools/test/test-setup.sh
index 3b7ce2d..aa6f722 100755
--- a/tools/test/test-setup.sh
+++ b/tools/test/test-setup.sh
@@ -105,12 +105,12 @@
 
 RUNFILES_MANIFEST_FILE="${TEST_SRCDIR}/MANIFEST"
 
-if [ -z "$RUNFILES_MANIFEST_ONLY" ]; then
+if [[ "${RUNFILES_MANIFEST_ONLY:-}" != "1" ]]; then
   function rlocation() {
     if is_absolute "$1" ; then
       echo "$1"
     else
-      echo "$(dirname $RUNFILES_MANIFEST_FILE)/$1"
+      echo "$TEST_SRCDIR/$1"
     fi
   }
 else
@@ -118,7 +118,7 @@
     if is_absolute "$1" ; then
       echo "$1"
     else
-      echo $(grep "^$1 " "${RUNFILES_MANIFEST_FILE}" | sed 's/[^ ]* //')
+      echo "$(grep "^$1 " "${RUNFILES_MANIFEST_FILE}" | sed 's/[^ ]* //')"
     fi
   }
 fi