@@ -33,6 +33,30 @@ _alias_repository = repository_rule(
33
33
34
34
_DEFAULT_NAME = "bazeldnf"
35
35
36
+ def _handle_lock_file (lock_file , module_ctx ):
37
+ content = module_ctx .read (lock_file )
38
+ lock_file_json = json .decode (content )
39
+ name = lock_file_json .get ("name" , lock_file .name .rsplit (".json" , 1 )[0 ])
40
+
41
+ rpms = []
42
+
43
+ for rpm in lock_file_json .get ("rpms" , []):
44
+ rpm_name = rpm .pop ("name" , None )
45
+ if not rpm_name :
46
+ urls = rpm .get ("urls" , [])
47
+ if len (urls ) < 1 :
48
+ fail ("invalid entry in %s for %s" % (lock_file , rpm_name ))
49
+ rpm_name = urls [0 ].rsplit ("/" , 1 )[- 1 ]
50
+ rpm_repository (name = rpm_name , ** rpm )
51
+ rpms .append (rpm_name )
52
+
53
+ _alias_repository (
54
+ name = name ,
55
+ rpms = ["@@%s//rpm" % x for x in rpms ],
56
+ )
57
+
58
+ return name
59
+
36
60
def _toolchain_extension (module_ctx ):
37
61
repos = []
38
62
@@ -58,6 +82,8 @@ def _toolchain_extension(module_ctx):
58
82
if not config .legacy_mode :
59
83
legacy = False
60
84
name = config .name or name
85
+ if config .lock_file :
86
+ repos .append (_handle_lock_file (config .lock_file , module_ctx ))
61
87
62
88
rpms = []
63
89
@@ -74,7 +100,7 @@ def _toolchain_extension(module_ctx):
74
100
else :
75
101
rpms .append (rpm .name )
76
102
77
- if not legacy :
103
+ if not legacy and rpms :
78
104
_alias_repository (
79
105
name = name ,
80
106
rpms = ["@@%s//rpm" % x for x in rpms ],
@@ -145,6 +171,28 @@ per rpm entry in this invocation of the bazel extension.
145
171
doc = "Name of the generated proxy repository" ,
146
172
default = "bazeldnf_rpms" ,
147
173
),
174
+ "lock_file" : attr .label (
175
+ doc = """\
176
+ Label of the JSON file that contains the RPMs to expose, there's no legacy mode \
177
+ for RPMs defined by a lock file.
178
+
179
+ The lock file content is as:
180
+ ```json
181
+ {
182
+ "name": "optional name for the proxy repository, defaults to the file name",
183
+ "rpms": [
184
+ {
185
+ "name": "<name of the rpm>",
186
+ "urls": ["<url0>", ...],
187
+ "sha256": "<sha256 of the file>",
188
+ "integrity": "<integrity of the file>"
189
+ }
190
+ ]
191
+ }
192
+ ```
193
+ """ ,
194
+ allow_single_file = [".json" ],
195
+ ),
148
196
},
149
197
)
150
198
0 commit comments