Skip to content

Commit

Permalink
extension: improve
Browse files Browse the repository at this point in the history
* stop reporting non defined repos, this feature is not very useful
* downloaded file matches the rpm it self
  • Loading branch information
manuelnaranjo committed Jan 16, 2024
1 parent 8e110d3 commit 1f927b5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 32 deletions.
13 changes: 6 additions & 7 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 6 additions & 23 deletions internal/bzlmod/rpm.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
load("//:deps.bzl", _rpm_repository = "rpm")


__BUILD_FILE_CONTENT__ = """
load("@{repository_name}//:deps.bzl", "rpmtree")
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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 = {
Expand Down
7 changes: 6 additions & 1 deletion internal/rpm.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkg/bazel/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit 1f927b5

Please sign in to comment.