Skip to content

Commit 33c06c2

Browse files
committed
bazel: simplify lock file usage
When using the lockfile don't put the prefix in the alias repository
1 parent 26241d4 commit 33c06c2

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

bazeldnf/extensions.bzl

+20-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ load(":repositories.bzl", "bazeldnf_register_toolchains")
1212
_ALIAS_TEMPLATE = """\
1313
alias(
1414
name = "{name}",
15-
actual = "@{name}//rpm",
15+
actual = "@{actual_name}//rpm",
1616
visibility = ["//visibility:public"],
1717
)
1818
"""
@@ -54,13 +54,24 @@ def _alias_repository_impl(repository_ctx):
5454
),
5555
)
5656
for rpm in repository_ctx.attr.rpms:
57-
repo_name = rpm.repo_name
58-
repository_ctx.file("%s/BUILD.bazel" % repo_name, _ALIAS_TEMPLATE.format(name = repo_name))
57+
actual_name = rpm.repo_name
58+
name = actual_name.split(repository_ctx.attr.repository_prefix, 1)[1]
59+
repository_ctx.file(
60+
"%s/BUILD.bazel" % name,
61+
_ALIAS_TEMPLATE.format(
62+
name = name,
63+
actual_name = actual_name,
64+
),
65+
)
66+
5967
if not repository_ctx.attr.rpms:
6068
for rpm in repository_ctx.attr.rpms_to_install:
6169
repository_ctx.file(
6270
"%s/BUILD.bazel" % rpm,
63-
_UPDATE_LOCK_FILE_TEMPLATE.format(repo = repository_ctx.name.rsplit("~", 1)[-1]),
71+
_UPDATE_LOCK_FILE_TEMPLATE.format(
72+
repo = repository_ctx.name.rsplit("~", 1)[-1]
73+
.split(repository_ctx.attr.repository_prefix, 1)[1],
74+
),
6475
)
6576

6677
_alias_repository = repository_rule(
@@ -71,6 +82,7 @@ _alias_repository = repository_rule(
7182
"rpms_to_install": attr.string_list(),
7283
"excludes": attr.string_list(),
7384
"repofile": attr.label(),
85+
"repository_prefix": attr.string(),
7486
},
7587
)
7688

@@ -86,6 +98,7 @@ def _handle_lock_file(config, module_ctx, registered_rpms = {}):
8698
"rpms_to_install": config.rpms,
8799
"excludes": config.excludes,
88100
"repofile": config.repofile,
101+
"repository_prefix": config.rpm_repository_prefix,
89102
}
90103

91104
if not module_ctx.path(config.lock_file).exists:
@@ -97,13 +110,11 @@ def _handle_lock_file(config, module_ctx, registered_rpms = {}):
97110
content = module_ctx.read(config.lock_file)
98111
lock_file_json = json.decode(content)
99112

100-
rpms = []
101-
102113
for rpm in lock_file_json.get("packages", []):
103114
dependencies = rpm.pop("dependencies", [])
104-
dependencies = [x.replace("+", "pp") for x in dependencies]
115+
dependencies = [x.replace("+", "plus") for x in dependencies]
105116
dependencies = ["@{}{}//rpm".format(config.rpm_repository_prefix, x) for x in dependencies]
106-
name = rpm.pop("name").replace("+", "pp")
117+
name = rpm.pop("name").replace("+", "plus")
107118
name = "{}{}".format(config.rpm_repository_prefix, name)
108119
if name in registered_rpms:
109120
continue
@@ -120,9 +131,8 @@ def _handle_lock_file(config, module_ctx, registered_rpms = {}):
120131
urls = urls,
121132
**rpm
122133
)
123-
rpms.append(name)
124134

125-
repository_args["rpms"] = ["@@%s//rpm" % x for x in rpms]
135+
repository_args["rpms"] = ["@@%s//rpm" % x for x in registered_rpms.keys()]
126136

127137
_alias_repository(
128138
**repository_args

0 commit comments

Comments
 (0)