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
test --nozip_undeclared_test_outputs
# Custom checks
-test --copt=-DGRPC_POSTMORTEM_CHECKS
\ No newline at end of file
+test:postmortem --copt=-DGRPC_POSTMORTEM_CHECKS
# 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
# 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
# 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 \
# print output for tests that fail (default is "summary")
build --test_output=errors
+
+# Custom checks
+test --config=postmortem
--- /dev/null
+# 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