@@ -96,6 +96,7 @@ def codeql_pkg_files(
96
96
97
97
def _extract_pkg_filegroup_impl (ctx ):
98
98
src = ctx .attr .src [PackageFilegroupInfo ]
99
+ arch_overrides = ctx .attr .arch_overrides
99
100
platform = _detect_platform (ctx )
100
101
101
102
if src .pkg_dirs or src .pkg_symlinks :
@@ -106,8 +107,11 @@ def _extract_pkg_filegroup_impl(ctx):
106
107
dest_src_map = {}
107
108
for dest , file in pfi .dest_src_map .items ():
108
109
file_kind , expanded_dest = _expand_path (dest , platform )
110
+ if file_kind == "generic" and dest in arch_overrides :
111
+ file_kind = "arch"
109
112
if file_kind == ctx .attr .kind :
110
113
dest_src_map [expanded_dest ] = file
114
+
111
115
if dest_src_map :
112
116
pkg_files .append ((PackageFilesInfo (dest_src_map = dest_src_map , attributes = pfi .attributes ), origin ))
113
117
@@ -125,12 +129,14 @@ _extract_pkg_filegroup = rule(
125
129
destination paths to the relevant codeql platform (linux64, win64 or osx64).
126
130
The distinction between generic and arch contents is given on a per-file basis depending on the install path
127
131
containing {CODEQL_PLATFORM}, which will typically have been added by a `prefix` attribute to a `pkg_*` rule.
132
+ Files that are arch-specific, but outside of the `CODEQL_PLATFORM` path can be specified in `arch_overrides`.
128
133
No `pkg_dirs` or `pkg_symlink` must have been used for assembling the source mapping information: we could
129
134
easily add support for that, but we don't require it for now.
130
135
""" ,
131
136
attrs = {
132
137
"src" : attr .label (providers = [PackageFilegroupInfo , DefaultInfo ]),
133
138
"kind" : attr .string (doc = "What part to extract" , values = ["generic" , "arch" ]),
139
+ "arch_overrides" : attr .string_list (doc = "A list of files that should be included in the arch package regardless of the path" ),
134
140
} | _PLAT_DETECTION_ATTRS ,
135
141
)
136
142
@@ -277,28 +283,35 @@ def codeql_pack(
277
283
visibility = None ,
278
284
install_dest = "extractor-pack" ,
279
285
compression_level = None ,
286
+ arch_overrides = None ,
287
+ zip_prefix = None ,
280
288
** kwargs ):
281
289
"""
282
290
Define a codeql pack. This macro accepts `pkg_files`, `pkg_filegroup` or their `codeql_*` counterparts as `srcs`.
283
- `zips` is a map from prefixes to `.zip` files to import.
291
+ `zips` is a map from `.zip` files to prefixes to import.
284
292
* defines a `<name>-generic-zip` target creating a `<zip_filename>-generic.zip` archive with the generic bits,
285
- prefixed with `name `
293
+ prefixed with `zip_prefix `
286
294
* defines a `<name>-arch-zip` target creating a `<zip_filename>-<codeql_platform>.zip` archive with the
287
- arch-specific bits, prefixed with `name `
295
+ arch-specific bits, prefixed with `zip_prefix `
288
296
* defines a runnable `<name>-installer` target that will install the pack in `install_dest`, relative to where the
289
297
rule is used. The install destination can be overridden appending `-- --destdir=...` to the `bazel run`
290
- invocation. This installation _does not_ prefix the contents with `name`.
298
+ invocation. This installation _does not_ prefix the contents with `zip_prefix`.
299
+ The prefix for the zip files can be set with `zip_prefix`, it is `name` by default.
291
300
292
301
The distinction between arch-specific and generic contents is made based on whether the paths (including possible
293
302
prefixes added by rules) contain the special `{CODEQL_PLATFORM}` placeholder, which in case it is present will also
294
303
be replaced by the appropriate platform (`linux64`, `win64` or `osx64`).
304
+ Specific file paths can be placed in the arch-specific package by adding them to `arch_overrides`, even if their
305
+ path doesn't contain the `CODEQL_PLATFORM` placeholder.
295
306
296
307
`compression_level` can be used to tweak the compression level used when creating archives. Consider that this
297
308
does not affect the contents of `zips`, only `srcs`.
298
309
"""
299
310
internal = _make_internal (name )
300
311
zip_filename = zip_filename or name
301
312
zips = zips or {}
313
+ if zip_prefix == None :
314
+ zip_prefix = name
302
315
pkg_filegroup (
303
316
name = internal ("all" ),
304
317
srcs = srcs ,
@@ -316,6 +329,7 @@ def codeql_pack(
316
329
name = internal (kind ),
317
330
src = internal ("all" ),
318
331
kind = kind ,
332
+ arch_overrides = arch_overrides ,
319
333
visibility = ["//visibility:private" ],
320
334
)
321
335
if zips :
@@ -335,15 +349,15 @@ def codeql_pack(
335
349
name = internal (kind , "zip" ),
336
350
srcs = [internal (kind , "zip-base" ), internal (kind , "zip-info" )],
337
351
out = _get_zip_filename (name , kind ),
338
- prefix = name ,
352
+ prefix = zip_prefix ,
339
353
visibility = visibility ,
340
354
)
341
355
else :
342
356
pkg_zip (
343
357
name = internal (kind , "zip" ),
344
358
srcs = [internal (kind )],
345
359
visibility = visibility ,
346
- package_dir = name ,
360
+ package_dir = zip_prefix ,
347
361
package_file_name = _get_zip_filename (name , kind ),
348
362
compression_level = compression_level ,
349
363
)
0 commit comments