From 1f927b5c5153e6098cb438259e352df24a0bd9c9 Mon Sep 17 00:00:00 2001 From: Manuel Naranjo Date: Wed, 17 Jan 2024 00:02:49 +0100 Subject: [PATCH] extension: improve * stop reporting non defined repos, this feature is not very useful * downloaded file matches the rpm it self --- MODULE.bazel | 13 ++++++------- internal/bzlmod/rpm.bzl | 29 ++++++----------------------- internal/rpm.bzl | 7 ++++++- pkg/bazel/BUILD.bazel | 2 +- 4 files changed, 19 insertions(+), 32 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 115a394..6ae9ba5 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -14,27 +14,26 @@ go_deps.from_file(go_mod = "//:go.mod") # override from go.mod, this is not supported by gazelle as of 0.35.0 go_deps.archive_override( path = "github.com/sassoftware/go-rpmutils", + sha256 = "41953067dcc570723f21296728aec19b4967567db0f8a1323aed9633ce37eb9a", + strip_prefix = "go-rpmutils-5acf7436c00dee9caf9367340b35d8c52961d240", urls = [ "https://github.com/rmohr/go-rpmutils/archive/5acf7436c00dee9caf9367340b35d8c52961d240.tar.gz", ], - strip_prefix = "go-rpmutils-5acf7436c00dee9caf9367340b35d8c52961d240", - sha256 = "41953067dcc570723f21296728aec19b4967567db0f8a1323aed9633ce37eb9a" ) # dependencies from the override go_deps.module( + indirect = True, path = "github.com/DataDog/zstd", - version = "v1.4.5", sum = "h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=", - indirect = True + version = "v1.4.5", ) go_deps.module( + indirect = True, path = "github.com/ulikunitz/xz", - version = "v0.5.9", sum = "h1:RsKRIA2MO8x56wkkcd3LbtcE/uMszhb6DpRf+3uwa3I=", - indirect = True + version = "v0.5.9", ) - use_repo( go_deps, "com_github_bazelbuild_buildtools", diff --git a/internal/bzlmod/rpm.bzl b/internal/bzlmod/rpm.bzl index 88ff7fa..e6e0611 100644 --- a/internal/bzlmod/rpm.bzl +++ b/internal/bzlmod/rpm.bzl @@ -1,6 +1,5 @@ load("//:deps.bzl", _rpm_repository = "rpm") - __BUILD_FILE_CONTENT__ = """ load("@{repository_name}//:deps.bzl", "rpmtree") @@ -25,16 +24,16 @@ def _rpm_repo_impl(repo_ctx): visibility = ", \n ".join(['"%s"' % x for x in repo_ctx.attr.generated_visibility]) for rpm in repo_ctx.attr.rpms: rpms.append('"%s"' % rpm) - alias = 'rpm_%s' % rpm.replace('-', '_').replace('@', '').split('//', 1)[0] + alias = "rpm_%s" % rpm.replace("-", "_").replace("@", "").split("//", 1)[0] list_of_rpm.append( - '"@{repo}//:{alias}"'.format(repo = repo_ctx.name.rsplit('~',1)[-1], alias = alias) + '"@{repo}//:{alias}"'.format(repo = repo_ctx.name.rsplit("~", 1)[-1], alias = alias), ) rpm_aliases.append( 'alias( name = "{alias}", actual = "{rpm}", visibility = [ {visibility}] )'.format( alias = alias, rpm = rpm, - visibility = visibility - ) + visibility = visibility, + ), ) rpms = ", \n ".join(rpms) @@ -82,20 +81,13 @@ def _handle_lock_file(module_ctx, lock_file, repositories): return lock_file.rpm_tree_name, module_ctx.is_dev_dependency(lock_file) def _rpm_deps_impl(module_ctx): - public_repos = [] - is_dev_dependency = False repositories = dict() for module in module_ctx.modules: - if module.tags.lock_file: - for lock_file in module.tags.lock_file: - repo_name, _is_dev_dependency = _handle_lock_file(module_ctx, lock_file, repositories) - public_repos.append(repo_name) - is_dev_dependency = is_dev_dependency or _is_dev_dependency + for lock_file in module.tags.lock_file: + _handle_lock_file(module_ctx, lock_file, repositories) for rpm in module.tags.rpm: - is_dev_dependency = is_dev_dependency or module_ctx.is_dev_dependency(rpm) - if rpm.name not in repositories: _rpm_repository( name = rpm.name, @@ -105,15 +97,6 @@ def _rpm_deps_impl(module_ctx): dependencies = rpm.dependencies, ) repositories[rpm.name] = rpm - public_repos.append(rpm.name) - - if not hasattr(module_ctx, "extension_metadata") or is_dev_dependency: - return None - - return module_ctx.extension_metadata( - root_module_direct_deps = public_repos, - root_module_direct_dev_deps = [], - ) _rpm_tag = tag_class( attrs = { diff --git a/internal/rpm.bzl b/internal/rpm.bzl index b19ac69..21213ac 100644 --- a/internal/rpm.bzl +++ b/internal/rpm.bzl @@ -54,11 +54,16 @@ rpm_rule( rpm_file = "{downloaded_file_path}", dependencies = [{dependencies}] ) + +alias( + name = "downloaded", + actual = ":{downloaded_file_path}" +) """ def _rpm_impl(ctx): if ctx.attr.urls: - downloaded_file_path = "downloaded" + downloaded_file_path = ctx.attr.urls[0].rsplit("/", 1)[-1] download_info = ctx.download( url = ctx.attr.urls, output = "rpm/" + downloaded_file_path, diff --git a/pkg/bazel/BUILD.bazel b/pkg/bazel/BUILD.bazel index 03c8190..9b8a837 100644 --- a/pkg/bazel/BUILD.bazel +++ b/pkg/bazel/BUILD.bazel @@ -4,7 +4,7 @@ go_library( name = "bazel", srcs = [ "bazel.go", - "bzlmod.go" + "bzlmod.go", ], importpath = "github.com/rmohr/bazeldnf/pkg/bazel", visibility = ["//visibility:public"],