Skip to content

Commit

Permalink
feat: support debian flat repository format
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Conrey committed Jun 3, 2024
1 parent f81f6c8 commit 7a64d96
Show file tree
Hide file tree
Showing 9 changed files with 8,313 additions and 3,129 deletions.
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "aspect_bazel_lib", version = "2.7.3")
bazel_dep(name = "container_structure_test", version = "1.16.0")
bazel_dep(name = "rules_oci", version = "1.7.4")
bazel_dep(name = "rules_pkg", version = "0.10.1")

bazel_lib_toolchains = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "toolchains")
use_repo(bazel_lib_toolchains, "bsd_tar_toolchains")
Expand Down
20 changes: 19 additions & 1 deletion apt/private/lockfile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,29 @@ def _add_package(lock, package, arch):
k = _package_key(package, arch)
if k in lock.fast_package_lookup:
return

filename = package["Filename"]
url_root = package["Root"]

# Takes element following last '/' in string, evaluates if it is a known archive type
url_last_elem = package["Root"].rsplit("/", 1)[-1]
if url_last_elem.endswith(".gz") or url_last_elem.endswith(".xz"):
url_root = url_root.replace(url_last_elem, "")

# Package filename may be parsed as a relative path. Deconstruct the string, see if there is overlap with the URL
if filename.split("/", 1)[0] in url_root:
filename = filename.replace(filename.split("/", 1)[0], "")

url_root = url_root.removesuffix("/")
filename = filename.removeprefix("/")

url = "%s/%s" % (url_root, filename)

lock.packages.append({
"key": k,
"name": package["Package"],
"version": package["Version"],
"url": "%s/%s" % (package["Root"], package["Filename"]),
"url": url,
"sha256": package["SHA256"],
"arch": arch,
"dependencies": [],
Expand Down
37 changes: 26 additions & 11 deletions apt/private/package_index.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,34 @@ def _fetch_package_index(rctx, url, dist, comp, arch, integrity):
r = {"success": False, "integrity": None}

decompression_successful = False

for file_type, tool in file_types.items():
output = "{}/Packages.{}".format(target_triple, file_type)
r = rctx.download(
url = "{}/dists/{}/{}/binary-{}/Packages.{}".format(url, dist, comp, arch, file_type),
output = output,
integrity = integrity,
allow_fail = True,
)
if r.success:
re = rctx.execute(tool + [output])
if re.return_code == 0:
decompression_successful = True
break

# Attempt to pull Packages archive from within the `dists` hierarchy first,
# if that fails - assume the repository is of type "flat"
try_urls = [
"{}/dists/{}/{}/binary-{}/Packages.{}".format(url, dist, comp, arch, file_type),
"{}/Packages.{}".format(url, file_type),
]

for try_url in try_urls:
r = rctx.download(
url = try_url,
output = output,
integrity = integrity,
allow_fail = True,
)
if r.success:
re = rctx.execute(tool + [output])
if re.return_code == 0:
decompression_successful = True
break
# If we've set `decompression_successful` to true at any point in the iteration loop,
# break out of the loop as we have found and extracted the Package archive and have what is
# needed to continue.
if decompression_successful:
break

if not r.success:
fail("unable to download package index")
Expand Down
Loading

0 comments on commit 7a64d96

Please sign in to comment.