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

Return dependency metadata from module extension #95

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions apko/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ apko_translate_lock = tag_class(attrs = {
})

def _apko_extension_impl(module_ctx):
root_direct_deps = []
root_direct_dev_deps = []
registrations = {}
for mod in module_ctx.modules:
for lock in mod.tags.translate_lock:
Expand Down Expand Up @@ -70,6 +72,10 @@ def _apko_extension_impl(module_ctx):

translate_apko_lock(name = lock.name, target_name = lock.name, lock = lock.lock)

if mod.is_root:
deps = root_direct_dev_deps if module_ctx.is_dev_dependency(lock) else root_direct_deps
deps.append(lock.name)

for toolchain in mod.tags.toolchain:
if toolchain.name != _DEFAULT_NAME and not mod.is_root:
fail("""\
Expand All @@ -78,6 +84,11 @@ def _apko_extension_impl(module_ctx):
""")
if toolchain.name not in registrations.keys():
registrations[toolchain.name] = []

if mod.is_root:
deps = root_direct_dev_deps if module_ctx.is_dev_dependency(toolchain) else root_direct_deps
deps.append(toolchain.name + "_toolchains")

registrations[toolchain.name].append(toolchain.apko_version)

for name, versions in registrations.items():
Expand All @@ -96,6 +107,13 @@ def _apko_extension_impl(module_ctx):
register = False,
)

# Allow use_repo calls to be automatically managed by `bazel mod tidy`
return module_ctx.extension_metadata(
root_module_direct_deps = root_direct_deps,
root_module_direct_dev_deps = root_direct_dev_deps,
)


apko = module_extension(
implementation = _apko_extension_impl,
tag_classes = {
Expand Down
Loading