@@ -10,6 +10,60 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_jar")
1010load ("//internal:rpm.bzl" , rpm_repository = "rpm" )
1111load (":repositories.bzl" , "bazeldnf_register_toolchains" )
1212
13+ _DEFAULT_NAME = "bazeldnf"
14+
15+ def _bazeldnf_toolchain_extension (module_ctx ):
16+ repos = []
17+ for mod in module_ctx .modules :
18+ for toolchain in mod .tags .register :
19+ if toolchain .name != _DEFAULT_NAME and not mod .is_root :
20+ fail ("""\
21+ Only the root module may override the default name for the bazeldnf toolchain.
22+ This prevents conflicting registrations in the global namespace of external repos.
23+ """ )
24+ if mod .is_root and toolchain .disable :
25+ break
26+ bazeldnf_register_toolchains (
27+ name = toolchain .name ,
28+ register = False ,
29+ )
30+ if mod .is_root :
31+ repos .append (toolchain .name + "_toolchains" )
32+
33+ kwargs = {}
34+ if bazel_features .external_deps .extension_metadata_has_reproducible :
35+ kwargs ["reproducible" ] = True
36+
37+ if module_ctx .root_module_has_non_dev_dependency :
38+ kwargs ["root_module_direct_deps" ] = repos
39+ kwargs ["root_module_direct_dev_deps" ] = []
40+ else :
41+ kwargs ["root_module_direct_deps" ] = []
42+ kwargs ["root_module_direct_dev_deps" ] = repos
43+
44+ return module_ctx .extension_metadata (** kwargs )
45+
46+ _toolchain_tag = tag_class (
47+ attrs = {
48+ "name" : attr .string (
49+ doc = """\
50+ Base name for generated repositories, allowing more than one bazeldnf toolchain to be registered.
51+ Overriding the default is only permitted in the root module.
52+ """ ,
53+ default = _DEFAULT_NAME ,
54+ ),
55+ "disable" : attr .bool (default = False ),
56+ },
57+ doc = "Allows registering a prebuilt bazeldnf toolchain" ,
58+ )
59+
60+ bazeldnf_toolchain = module_extension (
61+ implementation = _bazeldnf_toolchain_extension ,
62+ tag_classes = {
63+ "register" : _toolchain_tag ,
64+ },
65+ )
66+
1367_ALIAS_TEMPLATE = """\
1468 alias(
1569 name = "{name}",
@@ -32,8 +86,6 @@ _alias_repository = repository_rule(
3286 },
3387)
3488
35- _DEFAULT_NAME = "bazeldnf"
36-
3789def _handle_lock_file (lock_file , module_ctx ):
3890 content = module_ctx .read (lock_file )
3991 lock_file_json = json .decode (content )
@@ -58,25 +110,10 @@ def _handle_lock_file(lock_file, module_ctx):
58110
59111 return name
60112
61- def _toolchain_extension (module_ctx ):
113+ def _bazeldnf_extension (module_ctx ):
62114 repos = []
63115
64116 for mod in module_ctx .modules :
65- for toolchain in mod .tags .toolchain :
66- if toolchain .name != _DEFAULT_NAME and not mod .is_root :
67- fail ("""\
68- Only the root module may override the default name for the bazeldnf toolchain.
69- This prevents conflicting registrations in the global namespace of external repos.
70- """ )
71- if mod .is_root and toolchain .disable :
72- break
73- bazeldnf_register_toolchains (
74- name = toolchain .name ,
75- register = False ,
76- )
77- if mod .is_root :
78- repos .append (toolchain .name + "_toolchains" )
79-
80117 legacy = True
81118 name = "bazeldnf_rpms"
82119 for config in mod .tags .config :
@@ -121,20 +158,6 @@ def _toolchain_extension(module_ctx):
121158
122159 return module_ctx .extension_metadata (** kwargs )
123160
124- _toolchain_tag = tag_class (
125- attrs = {
126- "name" : attr .string (
127- doc = """\
128- Base name for generated repositories, allowing more than one bazeldnf toolchain to be registered.
129- Overriding the default is only permitted in the root module.
130- """ ,
131- default = _DEFAULT_NAME ,
132- ),
133- "disable" : attr .bool (default = False ),
134- },
135- doc = "Allows registering a prebuilt bazeldnf toolchain" ,
136- )
137-
138161_rpm_tag = tag_class (
139162 attrs = {
140163 "name" : attr .string (doc = "Name of the generated repository" ),
@@ -198,9 +221,8 @@ The lock file content is as:
198221)
199222
200223bazeldnf = module_extension (
201- implementation = _toolchain_extension ,
224+ implementation = _bazeldnf_extension ,
202225 tag_classes = {
203- "toolchain" : _toolchain_tag ,
204226 "rpm" : _rpm_tag ,
205227 "config" : _config_tag ,
206228 },
0 commit comments