Skip to content

Commit

Permalink
Allow Bzlmod downloads with --registry_disable_download
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed May 7, 2024
1 parent ac73e15 commit 14ecf1d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ private Optional<byte[]> doGrabFile(
try (SilentCloseable c =
Profiler.instance().profile(ProfilerTask.BZLMOD, () -> "download file: " + url)) {
return Optional.of(
downloadManager.downloadAndReadOneUrl(new URL(url), eventHandler, clientEnv, checksum));
downloadManager.downloadAndReadOneUrlForBzlmod(
new URL(url), eventHandler, clientEnv, checksum));
} catch (FileNotFoundException e) {
return Optional.empty();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ private Path downloadInExecutor(
/**
* Downloads the contents of one URL and reads it into a byte array.
*
* <p>This is only meant to be used for Bzlmod registry downloads as it ignores the value of
* <code>--repository_disable_download</code>.
*
* <p>If the checksum and path to the repository cache is specified, attempt to load the file from
* the {@link RepositoryCache}. If it doesn't exist, proceed to download the file and load it into
* the cache prior to returning the value.
Expand All @@ -388,7 +391,7 @@ private Path downloadInExecutor(
* @throws IOException if download was attempted and ended up failing
* @throws InterruptedException if this thread is being cast into oblivion
*/
public byte[] downloadAndReadOneUrl(
public byte[] downloadAndReadOneUrlForBzlmod(
URL originalUrl,
ExtendedEventHandler eventHandler,
Map<String, String> clientEnv,
Expand Down Expand Up @@ -439,11 +442,6 @@ public byte[] downloadAndReadOneUrl(
authHeaders = rewriter.updateAuthHeaders(rewrittenUrlMappings, authHeaders, netrcCreds);
}

if (disableDownload) {
throw new IOException(
String.format("Failed to download %s: download is disabled.", originalUrl));
}

if (rewrittenUrls.isEmpty()) {
throw new IOException(getRewriterBlockedAllUrlsMessage(ImmutableList.of(originalUrl)));
}
Expand Down
3 changes: 0 additions & 3 deletions src/test/shell/bazel/starlark_repository_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2327,9 +2327,6 @@ genrule(
)
EOF

# Ensure that all Bzlmod-related downloads have happened before disabling
# downloads.
bazel mod deps || fail "Failed to cache Bazel modules"
bazel build --repository_disable_download //:it > "${TEST_log}" 2>&1 \
&& fail "Expected failure" || :
expect_log "Failed to download repository @.*: download is disabled"
Expand Down

0 comments on commit 14ecf1d

Please sign in to comment.