Skip to content

Commit fc3460e

Browse files
sluongngcopybara-github
authored andcommitted
Stablize and flip repository_cache_urls_as_default_canonical_id
Introduced in bazelbuild#14268, this flag is very useful for bigger enterprise context where folks often version bumping dependencies without remembering to update the SHA256 of the downloaded file, leading to Bazel picking up older download entries from the repository cache. As we get more questions about this flag in Slack, marking it as stable and flip the default seems to be the right move. Closes bazelbuild#19549. PiperOrigin-RevId: 567356017 Change-Id: I6402e33f569789545e3ce17ebb42c51a8d56126f
1 parent 3b20aaa commit fc3460e

File tree

6 files changed

+54
-6
lines changed

6 files changed

+54
-6
lines changed

scripts/bootstrap/bootstrap.sh

+3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ fi
3131

3232
: ${JAVA_VERSION:="11"}
3333

34+
# TODO: remove `norepository_cache_urls_as_default_canonical_id` once all dependencies are mirrored.
35+
# See https://github.com/bazelbuild/bazel/pull/19549 for more context.
3436
_BAZEL_ARGS="--spawn_strategy=standalone \
3537
--nojava_header_compilation \
3638
--strategy=Javac=worker --worker_quit_after_build --ignore_unsupported_sandboxing \
3739
--compilation_mode=opt \
3840
--repository_cache=derived/repository_cache \
41+
--norepository_cache_urls_as_default_canonical_id \
3942
--extra_toolchains=//scripts/bootstrap:all \
4043
--extra_toolchains=@bazel_tools//tools/python:autodetecting_toolchain \
4144
--enable_bzlmod \

src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,9 @@ public Converter() {
287287
public CheckDirectDepsMode checkDirectDependencies;
288288

289289
@Option(
290-
name = "experimental_repository_cache_urls_as_default_canonical_id",
291-
defaultValue = "false",
290+
name = "repository_cache_urls_as_default_canonical_id",
291+
oldName = "experimental_repository_cache_urls_as_default_canonical_id",
292+
defaultValue = "true",
292293
documentationCategory = OptionDocumentationCategory.BAZEL_CLIENT_OPTIONS,
293294
effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
294295
metadataTags = {OptionMetadataTag.EXPERIMENTAL},

src/test/java/com/google/devtools/build/lib/blackbox/bazel/DefaultToolsSetup.java

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public void setup(BlackBoxTestContext context) throws IOException {
7878
String sharedRepoCache = System.getenv("REPOSITORY_CACHE");
7979
if (sharedRepoCache != null) {
8080
lines.add("common --repository_cache=" + sharedRepoCache);
81+
// TODO(sluongng): Remove this flag once all dependencies are mirrored.
82+
// See https://github.com/bazelbuild/bazel/pull/19549 for more context.
83+
lines.add("common --norepository_cache_urls_as_default_canonical_id");
8184
if (OS.getCurrent() == OS.DARWIN) {
8285
// For reducing SSD usage on our physical Mac machines.
8386
lines.add("common --experimental_repository_cache_hardlinks");

src/test/py/bazel/test_base.py

+3
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ def setUp(self):
127127
shared_repo_cache = os.environ.get('REPOSITORY_CACHE')
128128
if shared_repo_cache:
129129
f.write('common --repository_cache={}\n'.format(shared_repo_cache))
130+
# TODO(sluongng): Remove this flag once all dependencies are mirrored.
131+
# See https://github.com/bazelbuild/bazel/pull/19549 for more context.
132+
f.write('common --norepository_cache_urls_as_default_canonical_id\n')
130133
if TestBase.IsDarwin():
131134
# For reducing SSD usage on our physical Mac machines.
132135
f.write('common --experimental_repository_cache_hardlinks\n')

src/test/shell/bazel/bazel_repository_cache_test.sh

+39-4
Original file line numberDiff line numberDiff line change
@@ -494,18 +494,18 @@ EOF
494494
|| echo "Expected fetch to succeed"
495495
}
496496

497-
function test_experimental_repository_cache_urls_as_default_canonical_id() {
497+
function test_repository_cache_urls_as_default_canonical_id() {
498498
setup_repository
499499

500500
bazel fetch --repository_cache="$repo_cache_dir" \
501-
--experimental_repository_cache_urls_as_default_canonical_id \
501+
--repository_cache_urls_as_default_canonical_id \
502502
//zoo:breeding-program >& $TEST_log \
503503
|| echo "Expected fetch to succeed"
504504

505505
shutdown_server
506506

507507
bazel fetch --repository_cache="$repo_cache_dir" \
508-
--experimental_repository_cache_urls_as_default_canonical_id \
508+
--repository_cache_urls_as_default_canonical_id \
509509
//zoo:breeding-program >& $TEST_log \
510510
|| echo "Expected fetch to succeed"
511511

@@ -524,9 +524,44 @@ EOF
524524

525525
# As repository cache key should depend on urls, we expect fetching to fail now.
526526
bazel fetch --repository_cache="$repo_cache_dir" \
527-
--experimental_repository_cache_urls_as_default_canonical_id \
527+
--repository_cache_urls_as_default_canonical_id \
528528
//zoo:breeding-program >& $TEST_log \
529529
&& fail "expected failure" || :
530530
}
531531

532+
function test_repository_legacy_default_canonical_id() {
533+
setup_repository
534+
535+
bazel fetch --repository_cache="$repo_cache_dir" \
536+
--norepository_cache_urls_as_default_canonical_id \
537+
//zoo:breeding-program >& $TEST_log \
538+
|| echo "Expected fetch to succeed"
539+
540+
shutdown_server
541+
542+
bazel fetch --repository_cache="$repo_cache_dir" \
543+
--norepository_cache_urls_as_default_canonical_id \
544+
//zoo:breeding-program >& $TEST_log \
545+
|| echo "Expected fetch to succeed"
546+
547+
# Break url in WORKSPACE
548+
rm WORKSPACE
549+
cat >> $(create_workspace_with_default_repos WORKSPACE) <<EOF
550+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
551+
552+
http_archive(
553+
name = 'endangered',
554+
url = 'http://localhost:$nc_port/bleh.broken',
555+
sha256 = '$sha256',
556+
type = 'zip',
557+
)
558+
EOF
559+
560+
# As repository cache key should depend on urls, we expect fetching to fail now.
561+
bazel fetch --repository_cache="$repo_cache_dir" \
562+
--norepository_cache_urls_as_default_canonical_id \
563+
//zoo:breeding-program >& $TEST_log \
564+
|| echo "Expected fetch to succeed"
565+
}
566+
532567
run_suite "repository cache tests"

src/test/shell/testenv.sh.tmpl

+3
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ EOF
324324
if [[ -n ${REPOSITORY_CACHE:-} ]]; then
325325
echo "testenv.sh: Using repository cache at $REPOSITORY_CACHE."
326326
echo "common --repository_cache=$REPOSITORY_CACHE" >> $TEST_TMPDIR/bazelrc
327+
# TODO(sluongng): Remove this flag once all dependencies are mirrored.
328+
# See https://github.com/bazelbuild/bazel/pull/19549 for more context.
329+
echo "common --norepository_cache_urls_as_default_canonical_id" >> $TEST_TMPDIR/bazelrc
327330
if is_darwin; then
328331
# For reducing SSD usage on our physical Mac machines.
329332
echo "testenv.sh: Enabling --experimental_repository_cache_hardlinks"

0 commit comments

Comments
 (0)