Skip to content

Commit

Permalink
Stablize and flip repository_cache_urls_as_default_canonical_id
Browse files Browse the repository at this point in the history
Introduced in #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 #19549.

PiperOrigin-RevId: 567356017
Change-Id: I6402e33f569789545e3ce17ebb42c51a8d56126f
  • Loading branch information
sluongng authored and copybara-github committed Sep 21, 2023
1 parent 3b20aaa commit fc3460e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 6 deletions.
3 changes: 3 additions & 0 deletions scripts/bootstrap/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ fi

: ${JAVA_VERSION:="11"}

# TODO: remove `norepository_cache_urls_as_default_canonical_id` once all dependencies are mirrored.
# See https://github.com/bazelbuild/bazel/pull/19549 for more context.
_BAZEL_ARGS="--spawn_strategy=standalone \
--nojava_header_compilation \
--strategy=Javac=worker --worker_quit_after_build --ignore_unsupported_sandboxing \
--compilation_mode=opt \
--repository_cache=derived/repository_cache \
--norepository_cache_urls_as_default_canonical_id \
--extra_toolchains=//scripts/bootstrap:all \
--extra_toolchains=@bazel_tools//tools/python:autodetecting_toolchain \
--enable_bzlmod \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,9 @@ public Converter() {
public CheckDirectDepsMode checkDirectDependencies;

@Option(
name = "experimental_repository_cache_urls_as_default_canonical_id",
defaultValue = "false",
name = "repository_cache_urls_as_default_canonical_id",
oldName = "experimental_repository_cache_urls_as_default_canonical_id",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.BAZEL_CLIENT_OPTIONS,
effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
metadataTags = {OptionMetadataTag.EXPERIMENTAL},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public void setup(BlackBoxTestContext context) throws IOException {
String sharedRepoCache = System.getenv("REPOSITORY_CACHE");
if (sharedRepoCache != null) {
lines.add("common --repository_cache=" + sharedRepoCache);
// TODO(sluongng): Remove this flag once all dependencies are mirrored.
// See https://github.com/bazelbuild/bazel/pull/19549 for more context.
lines.add("common --norepository_cache_urls_as_default_canonical_id");
if (OS.getCurrent() == OS.DARWIN) {
// For reducing SSD usage on our physical Mac machines.
lines.add("common --experimental_repository_cache_hardlinks");
Expand Down
3 changes: 3 additions & 0 deletions src/test/py/bazel/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ def setUp(self):
shared_repo_cache = os.environ.get('REPOSITORY_CACHE')
if shared_repo_cache:
f.write('common --repository_cache={}\n'.format(shared_repo_cache))
# TODO(sluongng): Remove this flag once all dependencies are mirrored.
# See https://github.com/bazelbuild/bazel/pull/19549 for more context.
f.write('common --norepository_cache_urls_as_default_canonical_id\n')
if TestBase.IsDarwin():
# For reducing SSD usage on our physical Mac machines.
f.write('common --experimental_repository_cache_hardlinks\n')
Expand Down
43 changes: 39 additions & 4 deletions src/test/shell/bazel/bazel_repository_cache_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -494,18 +494,18 @@ EOF
|| echo "Expected fetch to succeed"
}

function test_experimental_repository_cache_urls_as_default_canonical_id() {
function test_repository_cache_urls_as_default_canonical_id() {
setup_repository

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

shutdown_server

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

Expand All @@ -524,9 +524,44 @@ EOF

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

function test_repository_legacy_default_canonical_id() {
setup_repository

bazel fetch --repository_cache="$repo_cache_dir" \
--norepository_cache_urls_as_default_canonical_id \
//zoo:breeding-program >& $TEST_log \
|| echo "Expected fetch to succeed"

shutdown_server

bazel fetch --repository_cache="$repo_cache_dir" \
--norepository_cache_urls_as_default_canonical_id \
//zoo:breeding-program >& $TEST_log \
|| echo "Expected fetch to succeed"

# Break url in WORKSPACE
rm WORKSPACE
cat >> $(create_workspace_with_default_repos WORKSPACE) <<EOF
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = 'endangered',
url = 'http://localhost:$nc_port/bleh.broken',
sha256 = '$sha256',
type = 'zip',
)
EOF

# As repository cache key should depend on urls, we expect fetching to fail now.
bazel fetch --repository_cache="$repo_cache_dir" \
--norepository_cache_urls_as_default_canonical_id \
//zoo:breeding-program >& $TEST_log \
|| echo "Expected fetch to succeed"
}

run_suite "repository cache tests"
3 changes: 3 additions & 0 deletions src/test/shell/testenv.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ EOF
if [[ -n ${REPOSITORY_CACHE:-} ]]; then
echo "testenv.sh: Using repository cache at $REPOSITORY_CACHE."
echo "common --repository_cache=$REPOSITORY_CACHE" >> $TEST_TMPDIR/bazelrc
# TODO(sluongng): Remove this flag once all dependencies are mirrored.
# See https://github.com/bazelbuild/bazel/pull/19549 for more context.
echo "common --norepository_cache_urls_as_default_canonical_id" >> $TEST_TMPDIR/bazelrc
if is_darwin; then
# For reducing SSD usage on our physical Mac machines.
echo "testenv.sh: Enabling --experimental_repository_cache_hardlinks"
Expand Down

0 comments on commit fc3460e

Please sign in to comment.