Make `TEST_REPOSITORY_HOME` stable for macOS and Windows We used to pass `--test_env=TEST_REPOSITORY_HOME=$OUTPUT_BASE/external` for running tests, but the $OUTPUT_BASE is calculated based on the current working directory. For Linux, the working directory is stable as we run tests inside docker. For macOS and Windows, the working directory contains the machine name, which caused TEST_REPOSITORY_HOME to be different from one presubmit to another and led to low cache hit rate on those two platforms. This PR fixes the issue by creating a symlink to $OUTPUT_BASE/external, and always pass the same path to TEST_REPOSITORY_HOME RELNOTES: None PiperOrigin-RevId: 427738284
diff --git a/.bazelci/postsubmit.yml b/.bazelci/postsubmit.yml index 2431c4a..017e46e 100644 --- a/.bazelci/postsubmit.yml +++ b/.bazelci/postsubmit.yml
@@ -161,9 +161,11 @@ - rm -f WORKSPACE.bak - rm -rf $HOME/bazeltest - mkdir $HOME/bazeltest + - ln -sf $OUTPUT_BASE/external $HOME/bazeltest/external build_flags: - "--test_env=TEST_INSTALL_BASE=$HOME/bazeltest/install_base" - "--test_env=TEST_REPOSITORY_HOME=$OUTPUT_BASE/external" + - "--test_env=TEST_REPOSITORY_HOME=$HOME/bazeltest/external" - "--test_env=REMOTE_NETWORK_ADDRESS=bazel.build:80" - "--noremote_accept_cached" build_targets: @@ -174,7 +176,7 @@ - "--sandbox_default_allow_network=false" - "--sandbox_writable_path=$HOME/bazeltest" - "--test_env=TEST_INSTALL_BASE=$HOME/bazeltest/install_base" - - "--test_env=TEST_REPOSITORY_HOME=$OUTPUT_BASE/external" + - "--test_env=TEST_REPOSITORY_HOME=$HOME/bazeltest/external" # Configure and enable tests that require access to the network. - "--test_env=REMOTE_NETWORK_ADDRESS=bazel.build:80" test_targets: @@ -196,12 +198,14 @@ windows: batch_commands: - powershell -Command "(Get-Content WORKSPACE) -Replace '# android_', 'android_' | Set-Content WORKSPACE" + - mkdir C:\b + - mklink /J C:\b\bazeltest_external %OUTPUT_BASE:/=\%\external build_flags: - "--copt=-w" - "--host_copt=-w" - "--test_env=JAVA_HOME" - "--test_env=TEST_INSTALL_BASE=$HOME/bazeltest_install_base" - - "--test_env=TEST_REPOSITORY_HOME=$OUTPUT_BASE/external" + - "--test_env=TEST_REPOSITORY_HOME=C:/b/bazeltest_external" - "--noremote_accept_cached" build_targets: - "//src:bazel.exe" @@ -213,7 +217,7 @@ - "--test_tag_filters=-no_windows,-slow" - "--test_env=JAVA_HOME" - "--test_env=TEST_INSTALL_BASE=$HOME/bazeltest_install_base" - - "--test_env=TEST_REPOSITORY_HOME=$OUTPUT_BASE/external" + - "--test_env=TEST_REPOSITORY_HOME=C:/b/bazeltest_external" test_targets: - "//src:embedded_tools_size_test" - "//src/test/cpp/..."
diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index f96dbda..a430ab9 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml
@@ -152,9 +152,10 @@ - rm -f WORKSPACE.bak - rm -rf $HOME/bazeltest - mkdir $HOME/bazeltest + - ln -sf $OUTPUT_BASE/external $HOME/bazeltest/external build_flags: - "--test_env=TEST_INSTALL_BASE=$HOME/bazeltest/install_base" - - "--test_env=TEST_REPOSITORY_HOME=$OUTPUT_BASE/external" + - "--test_env=TEST_REPOSITORY_HOME=$HOME/bazeltest/external" - "--test_env=REMOTE_NETWORK_ADDRESS=bazel.build:80" build_targets: - "//src:bazel" @@ -164,7 +165,7 @@ - "--sandbox_default_allow_network=false" - "--sandbox_writable_path=$HOME/bazeltest" - "--test_env=TEST_INSTALL_BASE=$HOME/bazeltest/install_base" - - "--test_env=TEST_REPOSITORY_HOME=$OUTPUT_BASE/external" + - "--test_env=TEST_REPOSITORY_HOME=$HOME/bazeltest/external" # Configure and enable tests that require access to the network. - "--test_env=REMOTE_NETWORK_ADDRESS=bazel.build:80" test_targets: @@ -188,12 +189,14 @@ shards: 4 batch_commands: - powershell -Command "(Get-Content WORKSPACE) -Replace '# android_', 'android_' | Set-Content WORKSPACE" + - mkdir C:\b + - mklink /J C:\b\bazeltest_external %OUTPUT_BASE:/=\%\external build_flags: - "--copt=-w" - "--host_copt=-w" - "--test_env=JAVA_HOME" - "--test_env=TEST_INSTALL_BASE=$HOME/bazeltest_install_base" - - "--test_env=TEST_REPOSITORY_HOME=$OUTPUT_BASE/external" + - "--test_env=TEST_REPOSITORY_HOME=C:/b/bazeltest_external" build_targets: - "//src:bazel.exe" - "//src:bazel_jdk_minimal" @@ -204,7 +207,7 @@ - "--test_tag_filters=-no_windows,-slow" - "--test_env=JAVA_HOME" - "--test_env=TEST_INSTALL_BASE=$HOME/bazeltest_install_base" - - "--test_env=TEST_REPOSITORY_HOME=$OUTPUT_BASE/external" + - "--test_env=TEST_REPOSITORY_HOME=C:/b/bazeltest_external" test_targets: - "//src:embedded_tools_size_test" - "//src/main/starlark/tests/builtins_bzl/..."