]> git.feebdaed.xyz Git - 0xmirror/grpc.git/commitdiff
[Bazel] Fixes the issue of copt cache discarded between test and build (#41038)
authorSergii Tkachenko <sergiitk@google.com>
Fri, 14 Nov 2025 17:05:42 +0000 (09:05 -0800)
committerCopybara-Service <copybara-worker@google.com>
Fri, 14 Nov 2025 17:09:54 +0000 (09:09 -0800)
This solves the issue with with copt cache dropped between `bazel build` and `bazel test`:

```
WARNING: Build option --copt has changed, discarding analysis cache.
```

This issue was introduced in #39945, which added `--copt=-DGRPC_POSTMORTEM_CHECKS` unconditionally to all `basel test`, but not `build`:

https://github.com/grpc/grpc/blob/1d6841f7d83881a7cfe63b25219d81de2abf8653/tools/bazel.rc#L155-L156

This PR moves the macro to a separate bazel profile config called `postmortem`, which is not enabled by default.
Instead, this config will be enabled in all remote CIs via tools/remote_build/include/test_config_common.bazelrc: https://github.com/grpc/grpc/blob/ba4984e8a0d21270a6cfc0481efd2de1595601d9/tools/remote_build/include/test_config_common.bazelrc#L26-L27

For the list of affected CI jobs, see my comment on this PR.

Closes #41038

PiperOrigin-RevId: 832339240

tools/bazel.rc
tools/bazelify_tests/test/bazel_build_with_bzlmod_linux.sh
tools/remote_build/include/test_config_common.bazelrc
tools/remote_build/linux_bzlmod.bazelrc [new file with mode: 0644]

index 2da26fef391c101f2116030e0b96dc8d4ede8e8d..8a80f18d1e3c39125c79239e594be49c1a15eb21 100644 (file)
@@ -153,4 +153,4 @@ build --@io_opentelemetry_cpp//api:with_abseil
 test --nozip_undeclared_test_outputs
 
 # Custom checks
-test --copt=-DGRPC_POSTMORTEM_CHECKS
\ No newline at end of file
+test:postmortem --copt=-DGRPC_POSTMORTEM_CHECKS
index 2526245218ed9ce98aa90e937c25fbf97883c628..d60523bcc9333ecdc317166c2485b98d82f3221b 100755 (executable)
@@ -17,20 +17,16 @@ set -ex
 
 # Test if public targets are buildable without dev dependencies.
 tools/bazel \
+    --bazelrc=tools/remote_build/linux_bzlmod.bazelrc \
     build \
-    --enable_bzlmod=true \
-    --enable_workspace=false \
-    --ignore_dev_dependency \
     -- \
     :all \
     -:grpcpp_csm_observability  # Needs google_cloud_cpp to be added to BCR
 
 # Test if examples are buildable without dev dependencies.
 tools/bazel \
+    --bazelrc=tools/remote_build/linux_bzlmod.bazelrc \
     build \
-    --enable_bzlmod=true \
-    --enable_workspace=false \
-    --ignore_dev_dependency \
     -- \
     //examples/cpp/... \
     -//examples/cpp/csm/...  # Needs grpcpp_csm_observability
@@ -39,9 +35,8 @@ tools/bazel \
 # This is a temporary sanity check covering essential features,
 # to be replaced by a comprehensive test suite once the bzlmod migration is finished.
 tools/bazel \
+    --bazelrc=tools/remote_build/linux_bzlmod.bazelrc \
     test \
-    --enable_bzlmod=true \
-    --enable_workspace=false \
     -- \
     //test/core/config:all \
     //test/cpp/common:all
@@ -49,10 +44,8 @@ tools/bazel \
 # Test if public targets are buildable with openssl and without dev
 # dependencies.
 tools/bazel \
+    --bazelrc=tools/remote_build/linux_bzlmod.bazelrc \
     build \
-    --enable_bzlmod=true \
-    --enable_workspace=false \
-    --ignore_dev_dependency \
     --define=//third_party:grpc_use_openssl=true \
     -- \
     :all \
index 2ee79da78227f66f0b78c4434973b9481527c169..63b5b50c08e74e66dba4b0afc236ab8a8e2776ce 100644 (file)
@@ -22,3 +22,6 @@ test --test_env=GRPC_VERBOSITY=debug
 
 # print output for tests that fail (default is "summary")
 build --test_output=errors
+
+# Custom checks
+test --config=postmortem
diff --git a/tools/remote_build/linux_bzlmod.bazelrc b/tools/remote_build/linux_bzlmod.bazelrc
new file mode 100644 (file)
index 0000000..f4bf6d0
--- /dev/null
@@ -0,0 +1,24 @@
+# Copyright 2025 The gRPC Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# bazelrc file for running bzlmod essentials on Kokoro (on Linux)
+# see bazel_build_with_bzlmod_linux.sh
+
+import %workspace%/tools/remote_build/include/test_config_common.bazelrc
+
+common --enable_bzlmod=true
+common --enable_workspace=false
+common --ignore_dev_dependency
+
+build --jobs=200