| 1 |
"""This module provides the gcs_mirror_url macro.""" |
| 2 |
|
| 3 |
# Set to True to force the macro to only return the mirror URL. |
| 4 |
_TEST_GCS_MIRROR = False |
| 5 |
|
| 6 |
# Must be kept in sync with the suffixes supported by gcs_mirror (e.g. |
| 7 |
# https://skia.googlesource.com/skia/+/8ad66c2340713234df6b249e793415233337a103/bazel/gcs_mirror/gcs_mirror.go#140). |
| 8 |
_SUPPORTED_SUFFIXES = [".tar.gz", ".tgz", ".tar.xz", ".deb", ".zip"] |
| 9 |
|
| 10 |
_GCS_MIRROR_PREFIX = "https://cdn.skia.org/bazel" |
| 11 |
|
| 12 |
def gcs_mirror_url(url, sha256, ext = None): |
| 13 |
"""Takes the URL of an external resource and computes its GCS mirror URL. |
| 14 |
|
| 15 |
We store backup copies of external resources in cdn.skia.org. This macro |
| 16 |
returns a list with two elements: the original URL, and the mirrored URL. |
| 17 |
|
| 18 |
To mirror a new URL, please use the `gcs_mirror` utility found at |
| 19 |
https://skia.googlesource.com/skia/+/8ad66c2340713234df6b249e793415233337a103/bazel/gcs_mirror/gcs_mirror.go. |
| 20 |
e.g. go run ./bazel/gcs_mirror/gcs_mirror.go --url https://github.com/emscripten-core/emsdk/archive/refs/tags/3.1.44.tar.gz --sha256 cb8cded78f6953283429d724556e89211e51ac4d871fcf38e0b32405ee248e91 |
| 21 |
|
| 22 |
Args: |
| 23 |
url: URL of the mirrored resource. |
| 24 |
sha256: SHA256 hash of the mirrored resource. |
| 25 |
ext: string matching the extension, if not provided, it will be gleaned from the URL. |
| 26 |
The auto-detected suffix must match a list. An arbitrarily provided one does not. |
| 27 |
Returns: |
| 28 |
A list of the form [original URL, mirror URL]. |
| 29 |
""" |
| 30 |
if ext == None: |
| 31 |
for suffix in _SUPPORTED_SUFFIXES: |
| 32 |
if url.endswith(suffix): |
| 33 |
ext = suffix |
| 34 |
break |
| 35 |
if ext == "": |
| 36 |
fail("URL %s has an unsupported suffix." % url) |
| 37 |
|
| 38 |
mirror_url = "%s/%s%s" % (_GCS_MIRROR_PREFIX, sha256, ext) |
| 39 |
return [mirror_url] if _TEST_GCS_MIRROR else [mirror_url, url] |