Skip to content

Commit 98220a5

Browse files
committed
fix: Wire the CI remote cache into the nested joern/dicer build
1 parent d44eb94 commit 98220a5

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

.bazelci/presubmit.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ tasks:
3838
# the //src/java worker/compileoptions unit tests and //tools:lint_check.
3939
- "//..."
4040
- "-//test_expect_failure/..."
41+
test_flags:
42+
# Bazel gives test actions a fixed, curated environment regardless of
43+
# sandboxing -- BUILDKITE reaches downstream_test_driver.sh (see
44+
# test/community_build/downstream_test.bzl) only with this forward.
45+
- "--test_env=BUILDKITE"
4146
macos:
4247
name: "bazel test //..."
4348
platform: macos

test/community_build/downstream_test_driver.sh

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,13 @@ mkdir -p "${_nested_bazel_output_base}"
109109
cd "${NESTED_BAZEL_WORKSPACE}"
110110
# This driver always uses the developer's home directory. `nested_bazel_setup`
111111
# does so only when asked, because a `~/.bazelrc` outside the repo could then
112-
# decide the result of a test whose pass is cached and reused. The tests here
113-
# are tagged `external`, so Bazel re-runs them every time and there is no such
114-
# stale pass to worry about. The paths built below need a home directory anyway.
112+
# decide the result of a cached, reused test pass. That risk is real here too
113+
# now that `downstream_test` dropped `external` for `source_fingerprint`-based
114+
# caching (see downstream_test.bzl): a developer's own `~/.bazelrc` still
115+
# isn't a declared input, so a `~/.bazelrc` edit between two runs with an
116+
# otherwise-unchanged fingerprint can go unnoticed by the cache. Scrubbing or
117+
# pinning the home configuration this nested invocation reads is follow-up
118+
# work. The paths built below need a home directory regardless.
115119
_nested_bazel_real_home="$(eval echo "~$(id -un)" 2>/dev/null || true)"
116120
_nested_bazel_common_opts=()
117121
repository_cache="$(dirname "${parent_output_base}")/cache/repos/v1"
@@ -120,6 +124,27 @@ if [[ -d "${repository_cache}" ]]; then
120124
fi
121125
_nested_bazel_common_opts+=("--symlink_prefix=${_nested_bazel_output_base}/convenience_symlinks/")
122126

127+
# CI's own `bazel` already builds against a shared remote cache (see
128+
# .bazelci/presubmit.yml's runner) -- extend the same cache to this nested
129+
# invocation's ~1000 build actions too (joern/dicer's own frontends and
130+
# deps, stable across most rules_scala PRs since the consumer commit is
131+
# pinned); `source_fingerprint` already covers the outer `sh_test`'s own
132+
# cached-or-not decision, a separate layer. `BUILDKITE` is set by every
133+
# buildkite-agent job, so this only ever activates on CI. A distinct
134+
# `cache-silo-key` (rather than reusing whatever the outer invocation set)
135+
# keeps this nested-build cache namespace independent of the outer one, so
136+
# a poisoned or stale entry in one stays isolated to that one.
137+
if [[ "${BUILDKITE:-}" == "true" ]]; then
138+
_nested_bazel_common_opts+=(
139+
"--remote_cache=remotebuildexecution.googleapis.com"
140+
"--remote_instance_name=projects/bazel-untrusted/instances/default_instance"
141+
"--google_default_credentials"
142+
"--remote_timeout=60"
143+
"--remote_max_connections=200"
144+
"--remote_default_exec_properties=cache-silo-key=rules-scala-downstream-nested-v1"
145+
)
146+
fi
147+
123148
# Some consumers' own build/test actions write outside the sandbox: joern's
124149
# javasrc2cpg to `~/.shiftleft`, and its codepropertygraph dep's run_codegen
125150
# genrule shells out to scalafmt's dynamic Coursier downloader, which writes
@@ -204,7 +229,16 @@ grep -oE 'lock_file = "//[^"]*"' MODULE.bazel | sed -E 's/lock_file = "(.*)"/\1/
204229
fi
205230
done
206231

232+
# --cache_test_results=no: the remote cache above (when active) scopes to
233+
# the build actions underneath these targets, keeping the test run itself
234+
# real every time -- `downstream_test`'s whole point is that its targets
235+
# (9 for joern, 163 for dicer) actually execute against the toolchain under
236+
# test on every real `sh_test` run, the same guarantee `source_fingerprint`
237+
# gives at the outer level by forcing a real re-run instead of serving a
238+
# stale PASS. The cost of a retry-attempt rerun scales with that count.
239+
#
207240
# shellcheck disable=SC2086 # intentional word-splitting: extra_bazel_flags
208241
# and targets are each meant to expand to multiple words/patterns.
209-
nested_bazel_run test --test_output=errors --repo_env=SCALA_VERSION="${scala_version}" \
242+
nested_bazel_run test --test_output=errors --cache_test_results=no \
243+
--repo_env=SCALA_VERSION="${scala_version}" \
210244
${extra_bazel_flags} -- "${targets[@]}"

0 commit comments

Comments
 (0)