diff --git a/apt/private/index.bzl b/apt/private/index.bzl index ac76fe4..2dd5952 100644 --- a/apt/private/index.bzl +++ b/apt/private/index.bzl @@ -85,17 +85,19 @@ def _deb_package_index_impl(rctx): ), ) + deps = depset([ + '"//%s/%s"' % (dep["name"], package["arch"]) + for dep in package["dependencies"] + ]) repo_name = "%s%s_%s" % ("@" if rctx.attr.bzlmod else "", rctx.attr.name, package_key) rctx.file( "%s/%s/BUILD.bazel" % (package["name"], package["arch"]), rctx.attr.package_template.format( target_name = package["arch"], + src = '"@%s//:data"' % repo_name, - deps = ",\n ".join([ - '"//%s/%s"' % (dep["name"], package["arch"]) - for dep in package["dependencies"] - ]), + deps = ",\n ".join(deps.to_list()), urls = [package["url"]], name = package["name"], arch = package["arch"], diff --git a/apt/private/lockfile.bzl b/apt/private/lockfile.bzl index fc76ab0..37cfd6f 100644 --- a/apt/private/lockfile.bzl +++ b/apt/private/lockfile.bzl @@ -16,11 +16,14 @@ def _add_package(lock, package, arch): k = _package_key(package, arch) if k in lock.fast_package_lookup: return + filename = package["Filename"] + if filename.startswith("./"): + filename = filename[2:] lock.packages.append({ "key": k, "name": package["Package"], "version": package["Version"], - "url": "%s/%s" % (package["Root"], package["Filename"]), + "url": "%s/%s" % (package["Root"], filename), "sha256": package["SHA256"], "arch": arch, "dependencies": [], diff --git a/apt/private/package_index.bzl b/apt/private/package_index.bzl index c633a4d..1c48bed 100644 --- a/apt/private/package_index.bzl +++ b/apt/private/package_index.bzl @@ -3,7 +3,13 @@ load(":util.bzl", "util") def _fetch_package_index(rctx, url, dist, comp, arch, integrity): - target_triple = "{dist}/{comp}/{arch}".format(dist = dist, comp = comp, arch = arch) + # Split the URL by the '://' delimiter + protocol, rest = url.split("://") + + # Split the rest of the URL by the '/' delimiter and take the first part + domain = rest.split("/")[0] + + target_triple = "{domain}/{dist}/{comp}/{arch}".format(domain = domain, dist = dist, comp = comp, arch = arch) file_types = {"xz": ["xz", "--decompress"], "gz": ["gzip", "-d"]} r = {"success": False, "integrity": None} @@ -11,17 +17,22 @@ def _fetch_package_index(rctx, url, dist, comp, arch, integrity): 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 + urls = [ + "{}/dists/{}/{}/binary-{}/Packages.{}".format(url, dist, comp, arch, file_type), + "{}/Packages.{}".format(url, file_type), + ] + for package_index_url in urls: + r = rctx.download( + url = package_index_url, + output = output, + integrity = integrity, + allow_fail = True, + ) + if r.success: + re = rctx.execute(tool + [output]) + if re.return_code == 0: + decompression_successful = True + return ("{}/Packages".format(target_triple), r.integrity) if not r.success: fail("unable to download package index")