@@ -205,6 +205,7 @@ _CODEQL_PACK_GROUP_EXTRACT_ATTRS = {
205
205
"srcs" : attr .label_list (providers = [_CodeQLPackInfo ], mandatory = True , doc = "List of `_codeql_pack_info` rules (generated by `codeql_pack`)." ),
206
206
"apply_pack_prefix" : attr .bool (doc = "Set to `False` to skip adding the per-pack prefix to all file paths." , default = True ),
207
207
"kind" : attr .string (doc = "Extract only the commmon, arch-specific, or all files from the pack group." , values = ["common" , "arch" , "all" ]),
208
+ "prefix" : attr .string (doc = "Prefix to add to all files, is prefixed after the per-pack prefix has been applied." , default = "" ),
208
209
} | OS_DETECTION_ATTRS
209
210
210
211
# common option parsing for _codeql_pack_group_extract_* rules
@@ -222,15 +223,15 @@ def _codeql_pack_group_extract_files_impl(ctx):
222
223
src = src [_CodeQLPackInfo ]
223
224
if src .files .pkg_dirs or src .files .pkg_symlinks :
224
225
fail ("`pkg_dirs` and `pkg_symlinks` are not supported for codeql packaging rules" )
225
- pack_prefix = src .pack_prefix if apply_pack_prefix else ""
226
+ prefix = paths . join ( ctx . attr . prefix , src .pack_prefix ) if apply_pack_prefix else ctx . attr . prefix
226
227
227
228
arch_overrides = src .arch_overrides
228
229
229
230
# for each file, resolve whether it's filtered out or not by the current kind, and add the pack prefix
230
231
for pfi , origin in src .files .pkg_files :
231
232
dest_src_map = {}
232
233
for dest , file in pfi .dest_src_map .items ():
233
- pack_dest = paths .join (pack_prefix , dest )
234
+ pack_dest = paths .join (prefix , dest )
234
235
file_kind , expanded_dest = _expand_path (pack_dest , platform )
235
236
if file_kind == "common" and dest in arch_overrides :
236
237
file_kind = "arch"
@@ -263,11 +264,11 @@ def _codeql_pack_group_extract_zips_impl(ctx):
263
264
platform , apply_pack_prefix , include_all_files = _codeql_pack_group_extract_options (ctx )
264
265
for src in ctx .attr .srcs :
265
266
src = src [_CodeQLPackInfo ]
266
- pack_prefix = src .pack_prefix if apply_pack_prefix else ""
267
+ prefix = paths . join ( ctx . attr . prefix , src .pack_prefix ) if apply_pack_prefix else ctx . attr . prefix
267
268
268
269
# for each zip file, resolve whether it's filtered out or not by the current kind, and add the pack prefix
269
- for zip , prefix in src .zips .zips_to_prefixes .items ():
270
- zip_kind , expanded_prefix = _expand_path (paths .join (pack_prefix , prefix ), platform )
270
+ for zip , zip_prefix in src .zips .zips_to_prefixes .items ():
271
+ zip_kind , expanded_prefix = _expand_path (paths .join (prefix , zip_prefix ), platform )
271
272
if include_all_files or zip_kind == ctx .attr .kind :
272
273
zips_to_prefixes [zip ] = expanded_prefix
273
274
@@ -286,7 +287,7 @@ _codeql_pack_group_extract_zips = rule(
286
287
provides = [_ZipInfo ],
287
288
)
288
289
289
- def _codeql_pack_install (name , srcs , install_dest = None , build_file_label = None , apply_pack_prefix = True ):
290
+ def _codeql_pack_install (name , srcs , install_dest = None , build_file_label = None , prefix = "" , apply_pack_prefix = True ):
290
291
"""
291
292
Create a runnable target `name` that installs the list of codeql packs given in `srcs` in `install_dest`,
292
293
relative to the directory where the rule is used.
@@ -301,6 +302,7 @@ def _codeql_pack_install(name, srcs, install_dest = None, build_file_label = Non
301
302
_codeql_pack_group_extract_files (
302
303
name = internal ("all-files" ),
303
304
srcs = srcs ,
305
+ prefix = prefix ,
304
306
kind = "all" ,
305
307
apply_pack_prefix = apply_pack_prefix ,
306
308
visibility = ["//visibility:private" ],
@@ -309,6 +311,7 @@ def _codeql_pack_install(name, srcs, install_dest = None, build_file_label = Non
309
311
name = internal ("all-extra-zips" ),
310
312
kind = "all" ,
311
313
srcs = srcs ,
314
+ prefix = prefix ,
312
315
apply_pack_prefix = apply_pack_prefix ,
313
316
visibility = ["//visibility:private" ],
314
317
)
@@ -351,7 +354,7 @@ def _codeql_pack_install(name, srcs, install_dest = None, build_file_label = Non
351
354
(["--destdir" , "\" %s\" " % install_dest ] if install_dest else []),
352
355
)
353
356
354
- def codeql_pack_group (name , srcs , visibility = None , skip_installer = False , install_dest = None , build_file_label = None , compression_level = 6 ):
357
+ def codeql_pack_group (name , srcs , visibility = None , skip_installer = False , prefix = "" , install_dest = None , build_file_label = None , compression_level = 6 ):
355
358
"""
356
359
Create a group of codeql packs of name `name`.
357
360
Accepts a list of `codeql_pack`s in `srcs` (essentially, `_codeql_pack_info` instantiations).
@@ -363,6 +366,8 @@ def codeql_pack_group(name, srcs, visibility = None, skip_installer = False, ins
363
366
The install destination can be overridden appending `-- --destdir=...` to the `bazel run` invocation.
364
367
The installer target will be omitted if `skip_installer` is set to `True`.
365
368
369
+ Prefixes all paths in the pack group with `prefix`.
370
+
366
371
The compression level of the generated zip files can be set with `compression_level`. Note that this doesn't affect the compression
367
372
level of extra zip files that are added to a pack, as thes files will not be re-compressed.
368
373
"""
@@ -373,6 +378,7 @@ def codeql_pack_group(name, srcs, visibility = None, skip_installer = False, ins
373
378
name = internal (kind ),
374
379
srcs = srcs ,
375
380
kind = kind ,
381
+ prefix = prefix ,
376
382
visibility = ["//visibility:private" ],
377
383
)
378
384
pkg_zip (
@@ -385,6 +391,7 @@ def codeql_pack_group(name, srcs, visibility = None, skip_installer = False, ins
385
391
name = internal (kind , "extra-zips" ),
386
392
kind = kind ,
387
393
srcs = srcs ,
394
+ prefix = prefix ,
388
395
visibility = ["//visibility:private" ],
389
396
)
390
397
_zipmerge (
@@ -394,7 +401,7 @@ def codeql_pack_group(name, srcs, visibility = None, skip_installer = False, ins
394
401
visibility = visibility ,
395
402
)
396
403
if not skip_installer :
397
- _codeql_pack_install (name , srcs , build_file_label = build_file_label , install_dest = install_dest , apply_pack_prefix = True )
404
+ _codeql_pack_install (name , srcs , build_file_label = build_file_label , install_dest = install_dest , prefix = prefix , apply_pack_prefix = True )
398
405
399
406
def codeql_pack (
400
407
* ,
0 commit comments