@@ -10,6 +10,60 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_jar")
10
10
load ("//internal:rpm.bzl" , rpm_repository = "rpm" )
11
11
load (":repositories.bzl" , "bazeldnf_register_toolchains" )
12
12
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
+
13
67
_ALIAS_TEMPLATE = """\
14
68
alias(
15
69
name = "{name}",
@@ -32,8 +86,6 @@ _alias_repository = repository_rule(
32
86
},
33
87
)
34
88
35
- _DEFAULT_NAME = "bazeldnf"
36
-
37
89
def _handle_lock_file (lock_file , module_ctx ):
38
90
content = module_ctx .read (lock_file )
39
91
lock_file_json = json .decode (content )
@@ -58,25 +110,10 @@ def _handle_lock_file(lock_file, module_ctx):
58
110
59
111
return name
60
112
61
- def _toolchain_extension (module_ctx ):
113
+ def _bazeldnf_extension (module_ctx ):
62
114
repos = []
63
115
64
116
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
-
80
117
legacy = True
81
118
name = "bazeldnf_rpms"
82
119
for config in mod .tags .config :
@@ -121,20 +158,6 @@ def _toolchain_extension(module_ctx):
121
158
122
159
return module_ctx .extension_metadata (** kwargs )
123
160
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
-
138
161
_rpm_tag = tag_class (
139
162
attrs = {
140
163
"name" : attr .string (doc = "Name of the generated repository" ),
@@ -198,9 +221,8 @@ The lock file content is as:
198
221
)
199
222
200
223
bazeldnf = module_extension (
201
- implementation = _toolchain_extension ,
224
+ implementation = _bazeldnf_extension ,
202
225
tag_classes = {
203
- "toolchain" : _toolchain_tag ,
204
226
"rpm" : _rpm_tag ,
205
227
"config" : _config_tag ,
206
228
},
0 commit comments