-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: apt.deb_index should work without a lock (#70)
* fix: apt.deb_index should work without a lock * chore: rename the extension * make package_template a label * typo
- Loading branch information
Showing
19 changed files
with
268 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,75 @@ | ||
"extensions for bzlmod" | ||
"apt extensions" | ||
|
||
load("//apt/private:index.bzl", _deb_package_index = "deb_package_index", _deb_package_index_bzlmod = "deb_package_index_bzlmod") | ||
load("//apt/private:resolve.bzl", _deb_resolve = "deb_resolve") | ||
|
||
deb_index = tag_class(attrs = { | ||
"name": attr.string(doc = "Name of the generated repository"), | ||
"lock": attr.label(doc = """The lock file to use for the index."""), | ||
"manifest": attr.label(doc = """The file used to generate the lock file"""), | ||
"resolve_transitive": attr.bool( | ||
doc = """Whether dependencies of dependencies should be resolved and added to the lockfile.""", | ||
default = True, | ||
), | ||
}) | ||
load("//apt/private:deb_import.bzl", "deb_import") | ||
load("//apt/private:index.bzl", _deb_package_index = "deb_package_index") | ||
load("//apt/private:lockfile.bzl", "lockfile") | ||
load("//apt/private:resolve.bzl", "internal_resolve") | ||
|
||
def _distroless_extension(module_ctx): | ||
root_direct_deps = [] | ||
root_direct_dev_deps = [] | ||
for mod in module_ctx.modules: | ||
for deb_index in mod.tags.deb_index: | ||
_deb_package_index_bzlmod( | ||
module_ctx = module_ctx, | ||
name = deb_index.name, | ||
lock = deb_index.lock, | ||
) | ||
|
||
_deb_resolve( | ||
name = deb_index.name + "_resolution", | ||
manifest = deb_index.manifest, | ||
resolve_transitive = deb_index.resolve_transitive, | ||
) | ||
for install in mod.tags.install: | ||
lockf = None | ||
if not install.lock: | ||
lockf = internal_resolve( | ||
module_ctx, | ||
"yq", | ||
install.manifest, | ||
install.resolve_transitive, | ||
) | ||
|
||
if not deb_index.lock: | ||
# buildifier: disable=print | ||
print("\nNo lockfile was given, please run `bazel run @%s//:lock` to create the lockfile." % deb_index.name) | ||
print("\nNo lockfile was given, please run `bazel run @%s//:lock` to create the lockfile." % install.name) | ||
else: | ||
lockf = lockfile.from_json(module_ctx, module_ctx.read(install.lock)) | ||
|
||
for (package) in lockf.packages(): | ||
package_key = lockfile.make_package_key( | ||
package["name"], | ||
package["version"], | ||
package["arch"], | ||
) | ||
|
||
deb_import( | ||
name = "%s_%s" % (install.name, package_key), | ||
urls = [package["url"]], | ||
sha256 = package["sha256"], | ||
) | ||
|
||
_deb_package_index( | ||
name = deb_index.name, | ||
lock = deb_index.lock if deb_index.lock else "@" + deb_index.name + "_resolution//:lock.json", | ||
bzlmod = True, | ||
name = install.name, | ||
lock = install.lock, | ||
manifest = install.manifest, | ||
package_template = install.package_template, | ||
lock_content = lockf.as_json(), | ||
) | ||
|
||
if mod.is_root: | ||
if module_ctx.is_dev_dependency(deb_index): | ||
root_direct_dev_deps.append(deb_index.name) | ||
if module_ctx.is_dev_dependency(install): | ||
root_direct_dev_deps.append(install.name) | ||
else: | ||
root_direct_deps.append(deb_index.name) | ||
root_direct_deps.append(install.name) | ||
|
||
return module_ctx.extension_metadata( | ||
root_module_direct_deps = root_direct_deps, | ||
root_module_direct_dev_deps = root_direct_dev_deps, | ||
) | ||
|
||
install = tag_class(attrs = { | ||
"name": attr.string(doc = "Name of the generated repository"), | ||
"lock": attr.label(doc = """The lock file to use for the index."""), | ||
"manifest": attr.label(doc = """The file used to generate the lock file"""), | ||
"resolve_transitive": attr.bool( | ||
doc = """Whether dependencies of dependencies should be resolved and added to the lockfile.""", | ||
default = True, | ||
), | ||
"package_template": attr.label(doc = "(EXPERIMENTAL!) a template file for generated BUILD files."), | ||
}) | ||
|
||
apt = module_extension( | ||
implementation = _distroless_extension, | ||
tag_classes = { | ||
"deb_index": deb_index, | ||
"install": install, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"deb_import" | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
# BUILD.bazel template | ||
_DEB_IMPORT_BUILD_TMPL = """ | ||
# TODO: https://github.com/bazel-contrib/rules_oci/pull/523 | ||
_RECOMPRESS_CMD = "$(ZSTD_BIN) -f --decompress $< --stdout | $(ZSTD_BIN) - --format=gzip >$@" | ||
genrule( | ||
name = "data", | ||
srcs = glob(["data.tar.*"]), | ||
outs = ["data.tar.gz"], | ||
cmd = _RECOMPRESS_CMD, | ||
toolchains = ["@zstd_toolchains//:resolved_toolchain"], | ||
visibility = ["//visibility:public"], | ||
) | ||
filegroup( | ||
name = "control", | ||
srcs = glob(["control.tar.*"]), | ||
visibility = ["//visibility:public"], | ||
) | ||
""" | ||
|
||
def deb_import(**kwargs): | ||
http_archive( | ||
build_file_content = _DEB_IMPORT_BUILD_TMPL, | ||
**kwargs | ||
) |
Oops, something went wrong.