message: Modify kokoro/testutils/run_bazel_tests.sh to optionally run only manually-supplied  targets
diff: # a set of additional manual targets to run.
  #
  # Usage:
  -# ./kokoro/testutils/run_bazel_tests.sh \
  -# <workspace directory> \
  +# ./kokoro/testutils/run_bazel_tests.sh [-mh] <workspace directory> \
  # [<manual target> <manual target> ...]
  # Note: -E extends the trap to shell functions, command substitutions, and
  @@ -31,10 +30,16 @@ set -eEo pipefail
  trap print_debug_output ERR
  usage() {
  - echo "Usage: $0 <workspace directory> [<manual target> <manual target> ...]"
  + echo "Usage: $0 [-mh] <workspace directory> \\"
  + echo " [<manual target> <manual target> ...]"
  + echo " -m: Runs only the manual targets. If set, manual targets must be"
  + echo " provided."
  + echo " -h: Help. Print this usage information."
  exit 1
  }
  +readonly PLATFORM="$(uname | tr '[:upper:]' '[:lower:]')"
  +MANUAL_ONLY="false"
  WORKSPACE_DIR=
  MANUAL_TARGETS=
  @@ -46,6 +51,16 @@ MANUAL_TARGETS=
  # MANUAL_TARGETS
  #######################################
  process_args() {
  + # Parse options.
  + while getopts "mh" opt; do
  + case "${opt}" in
  + d) MANUAL_ONLY="true" ;;
  + h) usage ;;
  + *) usage ;;
  + esac
  + done
  + shift $((OPTIND - 1))
  +
  WORKSPACE_DIR="$1"
  readonly WORKSPACE_DIR
  @@ -56,6 +71,10 @@ process_args() {
  shift 1
  MANUAL_TARGETS=("$@")
  readonly MANUAL_TARGETS
  +
  + if [[ "${MANUAL_ONLY}" == "true" ]] && (( ${#MANUAL_TARGETS[@]} == 0 )); then
  + usage
  + fi
  }
  #######################################
  @@ -69,26 +88,30 @@ print_debug_output() {
  main() {
  process_args "$@"
  - readonly PLATFORM="$(uname | tr '[:upper:]' '[:lower:]')"
  -
  - local -a TEST_FLAGS=( --strategy=TestRunner=standalone --test_output=all )
  + local -a test_flags=(
  + --strategy=TestRunner=standalone
  + --test_output=all
  + )
  if [[ "${PLATFORM}" == 'darwin' ]]; then
  - TEST_FLAGS+=( --jvmopt="-Djava.net.preferIPv6Addresses=true" )
  + test_flags+=( --jvmopt="-Djava.net.preferIPv6Addresses=true" )
  fi
  - readonly TEST_FLAGS
  + readonly test_flags
  (
  cd "${WORKSPACE_DIR}"
  + if [[ "${MANUAL_ONLY}" == "false" ]]; then
  time bazel build -- ...
  # Exit code 4 means targets build correctly but no tests were found. See
  # https://bazel.build/docs/scripts#exit-codes.
  bazel_test_return=0
  - time bazel test "${TEST_FLAGS[@]}" -- ... || bazel_test_return="$?"
  + time bazel test "${test_flags[@]}" -- ... || bazel_test_return="$?"
  if (( $bazel_test_return != 0 && $bazel_test_return != 4 )); then
  return "${bazel_test_return}"
  fi
  + fi
  # Run specific manual targets.
  if (( ${#MANUAL_TARGETS[@]} > 0 )); then
  - time bazel test "${TEST_FLAGS[@]}" -- "${MANUAL_TARGETS[@]}"
  + time bazel build -- "${MANUAL_TARGETS[@]}"
  + time bazel test "${test_flags[@]}" -- "${MANUAL_TARGETS[@]}"
  fi
  )
  }
  