Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support multiple URLs in sources #134

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions apt/private/apt_deb_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
load(":util.bzl", "util")
load(":version_constraint.bzl", "version_constraint")

def _fetch_package_index(rctx, url, dist, comp, arch, integrity):
def _fetch_package_index(rctx, urls, dist, comp, arch, integrity):
target_triple = "{dist}/{comp}/{arch}".format(dist = dist, comp = comp, arch = arch)

# See https://linux.die.net/man/1/xz , https://linux.die.net/man/1/gzip , and https://linux.die.net/man/1/bzip2
Expand All @@ -20,25 +20,29 @@ def _fetch_package_index(rctx, url, dist, comp, arch, integrity):

failed_attempts = []

for (ext, cmd) in supported_extensions.items():
output = "{}/Packages{}".format(target_triple, ext)
dist_url = "{}/dists/{}/{}/binary-{}/Packages{}".format(url, dist, comp, arch, ext)
download = rctx.download(
url = dist_url,
output = output,
integrity = integrity,
allow_fail = True,
)
decompress_r = None
if download.success:
decompress_r = rctx.execute(cmd + [output])
if decompress_r.return_code == 0:
integrity = download.integrity
break
for url in urls:
for (ext, cmd) in supported_extensions.items():
output = "{}/Packages{}".format(target_triple, ext)
dist_url = "{}/dists/{}/{}/binary-{}/Packages{}".format(url, dist, comp, arch, ext)
download = rctx.download(
url = dist_url,
output = output,
integrity = integrity,
allow_fail = True,
)
decompress_r = None
if download.success:
decompress_r = rctx.execute(cmd + [output])
if decompress_r.return_code == 0:
integrity = download.integrity
break

failed_attempts.append((dist_url, download, decompress_r))

failed_attempts.append((dist_url, download, decompress_r))
if download.success:
break

if len(failed_attempts) == len(supported_extensions):
if len(failed_attempts) == len(supported_extensions) * len(urls):
attempt_messages = []
for (url, download, decompress) in failed_attempts:
reason = "unknown"
Expand All @@ -55,7 +59,7 @@ def _fetch_package_index(rctx, url, dist, comp, arch, integrity):
{}
""".format(len(failed_attempts), "\n".join(attempt_messages)))

return ("{}/Packages".format(target_triple), integrity)
return ("{}/Packages".format(target_triple), url, integrity)

def _parse_repository(state, contents, root):
last_key = ""
Expand Down Expand Up @@ -117,16 +121,16 @@ def _create(rctx, sources, archs):
)

for arch in archs:
for (url, dist, comp) in sources:
for (urls, dist, comp) in sources:
# We assume that `url` does not contain a trailing forward slash when passing to
# functions below. If one is present, remove it. Some HTTP servers do not handle
# redirects properly when a path contains "//"
# (ie. https://mymirror.com/ubuntu//dists/noble/stable/... may return a 404
# on misconfigured HTTP servers)
url = url.rstrip("/")
urls = [url.rstrip("/") for url in urls]

rctx.report_progress("Fetching package index: {}/{} for {}".format(dist, comp, arch))
(output, _) = _fetch_package_index(rctx, url, dist, comp, arch, "")
(output, url, _) = _fetch_package_index(rctx, urls, dist, comp, arch, "")

# TODO: this is expensive to perform.
rctx.report_progress("Parsing package index: {}/{} for {}".format(dist, comp, arch))
Expand Down
9 changes: 8 additions & 1 deletion apt/private/deb_resolve.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,15 @@ def internal_resolve(rctx, yq_toolchain_prefix, manifest, include_transitive):
for src in manifest["sources"]:
distr, components = src["channel"].split(" ", 1)
for comp in components.split(" "):
if "urls" in src:
urls = src["urls"]
elif "url" in src:
urls = [src["url"]]
else:
fail("Source missing 'url' or 'urls' field")

sources.append((
src["url"],
urls,
distr,
comp,
))
Expand Down
Loading