Skip to content

Commit 15497ff

Browse files
meteorcloudycopybara-github
authored andcommitted
Allow mirror_urls in source.json
Context: bazelbuild/bazel-central-registry#4320 RELNTOES[NEW]: source.json now supports a new attribute `mirror_urls` as backup URLs for the source archive. Closes bazelbuild#25928. PiperOrigin-RevId: 750663220 Change-Id: I23ed94200ad555f7b1a756d76f3621fc0bd1b50f
1 parent 56fbf26 commit 15497ff

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

site/en/external/registry.md

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ field, which defaults to `archive`.
8383
by downloading an archive from a given URL and extracting its contents. It
8484
supports the following fields:
8585
* `url`: A string, the URL of the source archive
86+
* `mirror_urls`: A list of string, the mirror URLs of the source archive.
87+
The URLs are tried in order after `url` as backups.
8688
* `integrity`: A string, the [Subresource
8789
Integrity][subresource-integrity] checksum of the archive
8890
* `strip_prefix`: A string, the directory prefix to strip when extracting

src/main/java/com/google/devtools/build/lib/bazel/bzlmod/IndexRegistry.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.net.MalformedURLException;
4545
import java.net.URI;
4646
import java.net.URL;
47+
import java.util.List;
4748
import java.util.Map;
4849
import java.util.Map.Entry;
4950
import java.util.Optional;
@@ -259,6 +260,7 @@ private static class SourceJson {
259260
/** Represents fields in {@code source.json} for each archive-type version of a module. */
260261
private static class ArchiveSourceJson {
261262
URL url;
263+
List<String> mirrorUrls;
262264
String integrity;
263265
String stripPrefix;
264266
Map<String, String> patches;
@@ -446,9 +448,14 @@ private RepoSpec createArchiveRepoSpec(
446448
urls.add(constructUrl(mirror, sourceUrl.getAuthority(), sourceUrl.getFile()));
447449
}
448450
}
449-
// Finally add the original source URL itself.
451+
// Add the original source URL itself.
450452
urls.add(sourceUrl.toString());
451453

454+
// Add mirror_urls from source.json as backups after the primary url.
455+
if (sourceJson.mirrorUrls != null) {
456+
urls.addAll(sourceJson.mirrorUrls);
457+
}
458+
452459
// Build remote patches as key-value pairs of "url" => "integrity".
453460
ImmutableMap.Builder<String, String> remotePatches = new ImmutableMap.Builder<>();
454461
if (sourceJson.patches != null) {

src/test/java/com/google/devtools/build/lib/bazel/bzlmod/IndexRegistryTest.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ public void testGetArchiveRepoSpec() throws Exception {
182182
"/modules/foo/1.0/source.json",
183183
"{",
184184
" \"url\": \"http://mysite.com/thing.zip\",",
185+
" \"mirror_urls\":"
186+
+ " [\"http://my.mirror/mysite.com/thing.zip\",\"http://another.mirror/mysite.com/thing.zip\"],",
185187
" \"integrity\": \"sha256-blah\",",
186188
" \"strip_prefix\": \"pref\"",
187189
"}");
@@ -223,7 +225,9 @@ public void testGetArchiveRepoSpec() throws Exception {
223225
ImmutableList.of(
224226
"https://mirror.bazel.build/mysite.com/thing.zip",
225227
"file:///home/bazel/mymirror/mysite.com/thing.zip",
226-
"http://mysite.com/thing.zip"))
228+
"http://mysite.com/thing.zip",
229+
"http://my.mirror/mysite.com/thing.zip",
230+
"http://another.mirror/mysite.com/thing.zip"))
227231
.setIntegrity("sha256-blah")
228232
.setStripPrefix("pref")
229233
.setRemotePatches(ImmutableMap.of())

0 commit comments

Comments
 (0)