Skip to content

Commit

Permalink
chore: rename rules for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Nov 18, 2024
1 parent ce79162 commit a1b5fe3
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 48 deletions.
8 changes: 4 additions & 4 deletions apt/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ bzl_library(
srcs = ["apt.bzl"],
visibility = ["//visibility:public"],
deps = [
"//apt/private:index",
"//apt/private:resolve",
"//apt/private:deb_resolve",
"//apt/private:deb_translate_lock",
],
)

Expand All @@ -31,8 +31,8 @@ bzl_library(
visibility = ["//visibility:public"],
deps = [
"//apt/private:deb_import",
"//apt/private:index",
"//apt/private:deb_resolve",
"//apt/private:deb_translate_lock",
"//apt/private:lockfile",
"//apt/private:resolve",
],
)
6 changes: 3 additions & 3 deletions apt/apt.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ repository macro to create Debian repositories with packages "installed" in
them and available to use in Bazel.
"""

load("//apt/private:index.bzl", _deb_package_index = "deb_package_index")
load("//apt/private:resolve.bzl", _deb_resolve = "deb_resolve")
load("//apt/private:deb_resolve.bzl", _deb_resolve = "deb_resolve")
load("//apt/private:deb_translate_lock.bzl", _deb_translate_lock = "deb_translate_lock")

def _apt_install(
name,
Expand Down Expand Up @@ -129,7 +129,7 @@ def _apt_install(
# buildifier: disable=print
print("\nNo lockfile was given, please run `bazel run @%s//:lock` to create the lockfile." % name)

_deb_package_index(
_deb_translate_lock(
name = name,
lock = lock if lock else "@" + name + "_resolve//:lock.json",
package_template = package_template,
Expand Down
6 changes: 3 additions & 3 deletions apt/extensions.bzl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"apt extensions"

load("//apt/private:deb_import.bzl", "deb_import")
load("//apt/private:index.bzl", "deb_package_index")
load("//apt/private:deb_resolve.bzl", "deb_resolve", "internal_resolve")
load("//apt/private:deb_translate_lock.bzl", "deb_translate_lock")
load("//apt/private:lockfile.bzl", "lockfile")
load("//apt/private:resolve.bzl", "deb_resolve", "internal_resolve")

def _distroless_extension(module_ctx):
root_direct_deps = []
Expand Down Expand Up @@ -45,7 +45,7 @@ def _distroless_extension(module_ctx):
resolve_transitive = install.resolve_transitive,
)

deb_package_index(
deb_translate_lock(
name = install.name,
lock = install.lock,
lock_content = lockf.as_json(),
Expand Down
20 changes: 10 additions & 10 deletions apt/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ bzl_library(
)

bzl_library(
name = "index",
srcs = ["index.bzl"],
name = "deb_translate_lock",
srcs = ["deb_translate_lock.bzl"],
visibility = ["//apt:__subpackages__"],
deps = [
":lockfile",
Expand All @@ -41,15 +41,15 @@ bzl_library(
)

bzl_library(
name = "package_index",
srcs = ["package_index.bzl"],
name = "apt_deb_repository",
srcs = ["apt_deb_repository.bzl"],
visibility = ["//apt:__subpackages__"],
deps = [":util"],
)

bzl_library(
name = "package_resolution",
srcs = ["package_resolution.bzl"],
name = "apt_dep_resolver",
srcs = ["apt_dep_resolver.bzl"],
visibility = ["//apt:__subpackages__"],
deps = [
":version",
Expand All @@ -58,13 +58,13 @@ bzl_library(
)

bzl_library(
name = "resolve",
srcs = ["resolve.bzl"],
name = "deb_resolve",
srcs = ["deb_resolve.bzl"],
visibility = ["//apt:__subpackages__"],
deps = [
":apt_deb_repository",
":apt_dep_resolver",
":lockfile",
":package_index",
":package_resolution",
"@aspect_bazel_lib//lib:repo_utils",
],
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"package index"
"https://wiki.debian.org/DebianRepository"

load(":util.bzl", "util")
load(":version_constraint.bzl", "version_constraint")
Expand Down Expand Up @@ -54,7 +54,7 @@ def _fetch_package_index(rctx, url, dist, comp, arch, integrity):

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

def _parse_package_index(state, contents, root):
def _parse_repository(state, contents, root):
last_key = ""
pkg = {}
for group in contents.split("\n\n"):
Expand Down Expand Up @@ -127,19 +127,19 @@ def _create(rctx, sources, archs):

# TODO: this is expensive to perform.
rctx.report_progress("Parsing package index: {}/{} for {}".format(dist, comp, arch))
_parse_package_index(state, rctx.read(output), url)
_parse_repository(state, rctx.read(output), url)

return struct(
package_versions = lambda **kwargs: _package_versions(state, **kwargs),
virtual_packages = lambda **kwargs: _virtual_packages(state, **kwargs),
package = lambda **kwargs: _package(state, **kwargs),
)

package_index = struct(
deb_repository = struct(
new = _create,
)

# Testonly functions:
# TESTONLY: DO NOT DEPEND ON THIS
def _create_test_only():
state = struct(
packages = dict(),
Expand All @@ -150,7 +150,7 @@ def _create_test_only():
package_versions = lambda **kwargs: _package_versions(state, **kwargs),
virtual_packages = lambda **kwargs: _virtual_packages(state, **kwargs),
package = lambda **kwargs: _package(state, **kwargs),
parse_package_index = lambda contents: _parse_package_index(state, contents, "http://nowhere"),
parse_repository = lambda contents: _parse_repository(state, contents, "http://nowhere"),
packages = state.packages,
reset = lambda: state.packages.clear(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ load(":version_constraint.bzl", "version_constraint")

def _resolve_package(state, name, version, arch):
# First check if the constraint is satisfied by a virtual package
virtual_packages = state.index.virtual_packages(name = name, arch = arch)
virtual_packages = state.repository.virtual_packages(name = name, arch = arch)
for (provides, package) in virtual_packages:
provided_version = provides["version"]
if not provided_version and version:
Expand All @@ -15,8 +15,8 @@ def _resolve_package(state, name, version, arch):
return package

# Get available versions of the package
versions_by_arch = state.index.package_versions(name = name, arch = arch)
versions_by_any_arch = state.index.package_versions(name = name, arch = "all")
versions_by_arch = state.repository.package_versions(name = name, arch = arch)
versions_by_any_arch = state.repository.package_versions(name = name, arch = "all")

# Order packages by highest to lowest
versions = version_lib.sort(versions_by_arch + versions_by_any_arch, reverse = True)
Expand All @@ -36,9 +36,9 @@ def _resolve_package(state, name, version, arch):
# First element in the versions list is the latest version.
selected_version = versions[0]

package = state.index.package(name = name, version = selected_version, arch = arch)
package = state.repository.package(name = name, version = selected_version, arch = arch)
if not package:
package = state.index.package(name = name, version = selected_version, arch = "all")
package = state.repository.package(name = name, version = selected_version, arch = "all")

return package

Expand Down Expand Up @@ -124,13 +124,13 @@ def _resolve_all(state, name, version, arch, include_transitive = True):

return (root_package, dependencies, unmet_dependencies)

def _create_resolution(index):
state = struct(index = index)
def _create_resolution(repository):
state = struct(repository = repository)
return struct(
resolve_all = lambda **kwargs: _resolve_all(state, **kwargs),
resolve_package = lambda **kwargs: _resolve_package(state, **kwargs),
)

package_resolution = struct(
dependency_resolver = struct(
new = _create_resolution,
)
10 changes: 5 additions & 5 deletions apt/private/resolve.bzl → apt/private/deb_resolve.bzl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"repository rule for resolving and generating lockfile"

load("@aspect_bazel_lib//lib:repo_utils.bzl", "repo_utils")
load(":apt_deb_repository.bzl", "deb_repository")
load(":apt_dep_resolver.bzl", "dependency_resolver")
load(":lockfile.bzl", "lockfile")
load(":package_index.bzl", "package_index")
load(":package_resolution.bzl", "package_resolution")
load(":util.bzl", "util")
load(":version_constraint.bzl", "version_constraint")

Expand Down Expand Up @@ -50,8 +50,8 @@ def internal_resolve(rctx, yq_toolchain_prefix, manifest, include_transitive):
comp,
))

pkgindex = package_index.new(rctx, sources = sources, archs = manifest["archs"])
pkgresolution = package_resolution.new(index = pkgindex)
repository = deb_repository.new(rctx, sources = sources, archs = manifest["archs"])
resolver = dependency_resolver.new(repository)
lockf = lockfile.empty(rctx)

for arch in manifest["archs"]:
Expand All @@ -64,7 +64,7 @@ def internal_resolve(rctx, yq_toolchain_prefix, manifest, include_transitive):
constraint = version_constraint.parse_depends(dep_constraint).pop()

rctx.report_progress("Resolving %s" % dep_constraint)
(package, dependencies, unmet_dependencies) = pkgresolution.resolve_all(
(package, dependencies, unmet_dependencies) = resolver.resolve_all(
name = constraint["name"],
version = constraint["version"],
arch = arch,
Expand Down
8 changes: 4 additions & 4 deletions apt/private/index.bzl → apt/private/deb_translate_lock.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"apt-get"
"repository rule for generating a dependency graph from a lockfile."

load(":lockfile.bzl", "lockfile")

Expand Down Expand Up @@ -29,7 +29,7 @@ alias(
)
"""

def _deb_package_index_impl(rctx):
def _deb_translate_lock_impl(rctx):
lock_content = rctx.attr.lock_content
package_template = rctx.read(rctx.attr.package_template)
lockf = lockfile.from_json(rctx, lock_content if lock_content else rctx.read(rctx.attr.lock))
Expand Down Expand Up @@ -81,8 +81,8 @@ def _deb_package_index_impl(rctx):
rctx.file("packages.bzl", "\n".join(package_defs))
rctx.file("BUILD.bazel", _BUILD_TMPL.format(rctx.attr.name.split("~")[-1]))

deb_package_index = repository_rule(
implementation = _deb_package_index_impl,
deb_translate_lock = repository_rule(
implementation = _deb_translate_lock_impl,
attrs = {
"lock": attr.label(),
"lock_content": attr.string(doc = "INTERNAL: DO NOT USE"),
Expand Down
10 changes: 5 additions & 5 deletions apt/tests/resolution_test.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"unit tests for resolution of package dependencies"

load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
load("//apt/private:package_index.bzl", package_index = "DO_NOT_DEPEND_ON_THIS_TEST_ONLY")
load("//apt/private:package_resolution.bzl", "package_resolution")
load("//apt/private:apt_deb_repository.bzl", deb_repository = "DO_NOT_DEPEND_ON_THIS_TEST_ONLY")
load("//apt/private:apt_dep_resolver.bzl", "dependency_resolver")
load("//apt/private:version_constraint.bzl", "version_constraint")

def _parse_depends_test(ctx):
Expand Down Expand Up @@ -109,14 +109,14 @@ _test_version = "2.38.1-5"
_test_arch = "amd64"

def _make_index():
idx = package_index.new()
resolution = package_resolution.new(idx)
idx = deb_repository.new()
resolution = dependency_resolver.new(idx)

def _add_package(idx, **kwargs):
kwargs["architecture"] = kwargs.get("architecture", _test_arch)
kwargs["version"] = kwargs.get("version", _test_version)
r = "\n".join(["{}: {}".format(item[0].title(), item[1]) for item in kwargs.items()])
idx.parse_package_index(r)
idx.parse_repository(r)

return struct(
add_package = lambda **kwargs: _add_package(idx, **kwargs),
Expand Down

0 comments on commit a1b5fe3

Please sign in to comment.