Fix #7515: bazel_rules_test fails on Windows.

The test had a couple of problems:
- A misunderstanding of how PATH looks like in MSYS on Windows - it's not delimited by ';', but by ':'. Drive letters are not a problem, because MSYS represents these as virtual directories (e.g. C:\TEST becomes /c/TEST). By using a ';', the first entry in the PATH became invalid, which lead to the Bazel wrapper no longer being found.
- "export env variables and then try to restore them later" instead of just calling exactly the program that should use them with the env vars explicitly set. This is problematic, because the env vars do not get restored in case of failure and also because it's overly broad.
- Rewriting the existing tool "env" using "echo" and a select() construct.
- Didn't redirect output of "bazel" into $TEST_log.

By setting PATH to a wrong value on Windows, this caused the "bazel" command in the test to accidentally run the "bazel" binary from the system instead of the runfiles, so the test didn't test the correct Bazel version. We only noticed this when we replaced the "bazel" binary on the CI machines with Bazelisk, which crashed, because $HOME (Linux, macOS) and %LocalAppDir% were not set and Bazelisk requires these.

RELNOTES: None.
PiperOrigin-RevId: 235490629
diff --git a/src/test/shell/bazel/bazel_rules_test.sh b/src/test/shell/bazel/bazel_rules_test.sh
index cd55a1c..0676d27 100755
--- a/src/test/shell/bazel/bazel_rules_test.sh
+++ b/src/test/shell/bazel/bazel_rules_test.sh
@@ -293,50 +293,34 @@
 
 function test_genrule_default_env() {
   mkdir -p pkg
-  cat <<'EOF' >pkg/BUILD
+  cat >pkg/BUILD  <<'EOF'
 genrule(
     name = "test",
     outs = ["test.out"],
-    cmd = select({
-        "@bazel_tools//src/conditions:windows":
-            "(echo \"PATH=$$PATH\"; echo \"TMPDIR=$$TMP\") > $@",
-        "//conditions:default":
-            "(echo \"PATH=$$PATH\"; echo \"TMPDIR=$$TMPDIR\") > $@",
-    }),
+    cmd = "env > $@",
 )
 EOF
-  local old_path="${PATH}"
+
   local new_tmpdir="$(mktemp -d "${TEST_TMPDIR}/newfancytmpdirXXXXXX")"
-  [ -d "${new_tmpdir}" ] || \
-    fail "Could not create new temporary directory ${new_tmpdir}"
   if $is_windows; then
-    export PATH="$PATH_TO_BAZEL_WRAPPER;/bin;/usr/bin;/random/path;${old_path}"
-    local old_tmpdir="${TMP:-}"
-    export TMP="${new_tmpdir}"
-  else
-    export PATH="$PATH_TO_BAZEL_WRAPPER:/bin:/usr/bin:/random/path"
-    local old_tmpdir="${TMPDIR:-}"
-    export TMPDIR="${new_tmpdir}"
-  fi
-  bazel build //pkg:test --spawn_strategy=standalone --action_env=PATH \
-    || fail "Failed to build //pkg:test"
-  if $is_windows; then
-    local -r EXPECTED_PATH="$PATH_TO_BAZEL_WRAPPER:.*/random/path"
+    PATH="/random/path:$PATH" TMP="${new_tmpdir}" \
+      bazel build //pkg:test --spawn_strategy=standalone --action_env=PATH \
+      &> $TEST_log || fail "Failed to build //pkg:test"
+
+    # Test that Bazel respects the client environment's TMP.
     # new_tmpdir is based on $TEST_TMPDIR which is not Unix-style -- convert it.
-    local -r EXPECTED_TMP="$(cygpath -u "$new_tmpdir")"
+    assert_contains "TMP=$(cygpath -u "${new_tmpdir}")" bazel-genfiles/pkg/test.out
   else
-    local -r EXPECTED_PATH="$PATH_TO_BAZEL_WRAPPER:/bin:/usr/bin:/random/path"
-    local -r EXPECTED_TMP="$new_tmpdir"
+    PATH="/random/path:$PATH" TMPDIR="${new_tmpdir}" \
+      bazel build //pkg:test --spawn_strategy=standalone --action_env=PATH \
+      &> $TEST_log || fail "Failed to build //pkg:test"
+
+    # Test that Bazel respects the client environment's TMPDIR.
+    assert_contains "TMPDIR=${new_tmpdir}" bazel-genfiles/pkg/test.out
   fi
-  assert_contains "PATH=$EXPECTED_PATH" bazel-genfiles/pkg/test.out
-  # Bazel respects the client environment's TMPDIR.
-  assert_contains "TMPDIR=${EXPECTED_TMP}$" bazel-genfiles/pkg/test.out
-  if $is_windows; then
-    export TMP="${old_tmpdir}"
-  else
-    export TMPDIR="${old_tmpdir}"
-  fi
-  export PATH="${old_path}"
+
+  # Test that Bazel passed through the PATH from --action_env.
+  assert_contains "PATH=/random/path" bazel-genfiles/pkg/test.out
 }
 
 function test_genrule_remote() {