@@ -72,6 +72,7 @@ def codeql_pkg_files(
7272
7373def _extract_pkg_filegroup_impl (ctx ):
7474 src = ctx .attr .src [PackageFilegroupInfo ]
75+ arch_overrides = ctx .attr .arch_overrides
7576 platform = _detect_platform (ctx )
7677
7778 if src .pkg_dirs or src .pkg_symlinks :
@@ -82,8 +83,11 @@ def _extract_pkg_filegroup_impl(ctx):
8283 dest_src_map = {}
8384 for dest , file in pfi .dest_src_map .items ():
8485 file_kind , expanded_dest = _expand_path (dest , platform )
86+ if file_kind == "generic" and dest in arch_overrides :
87+ file_kind = "arch"
8588 if file_kind == ctx .attr .kind :
8689 dest_src_map [expanded_dest ] = file
90+
8791 if dest_src_map :
8892 pkg_files .append ((PackageFilesInfo (dest_src_map = dest_src_map , attributes = pfi .attributes ), origin ))
8993
@@ -101,12 +105,14 @@ _extract_pkg_filegroup = rule(
101105 destination paths to the relevant codeql platform (linux64, win64 or osx64).
102106 The distinction between generic and arch contents is given on a per-file basis depending on the install path
103107 containing {CODEQL_PLATFORM}, which will typically have been added by a `prefix` attribute to a `pkg_*` rule.
108+ Files that are arch-specific, but outside of the `CODEQL_PLATFORM` path can be specified in `arch_overrides`.
104109 No `pkg_dirs` or `pkg_symlink` must have been used for assembling the source mapping information: we could
105110 easily add support for that, but we don't require it for now.
106111 """ ,
107112 attrs = {
108113 "src" : attr .label (providers = [PackageFilegroupInfo , DefaultInfo ]),
109114 "kind" : attr .string (doc = "What part to extract" , values = ["generic" , "arch" ]),
115+ "arch_overrides" : attr .string_list (doc = "A list of files that should be included in the arch package regardless of the path" ),
110116 } | OS_DETECTION_ATTRS ,
111117)
112118
@@ -253,28 +259,35 @@ def codeql_pack(
253259 visibility = None ,
254260 install_dest = "extractor-pack" ,
255261 compression_level = None ,
262+ arch_overrides = None ,
263+ zip_prefix = None ,
256264 ** kwargs ):
257265 """
258266 Define a codeql pack. This macro accepts `pkg_files`, `pkg_filegroup` or their `codeql_*` counterparts as `srcs`.
259- `zips` is a map from prefixes to `.zip` files to import.
267+ `zips` is a map from `.zip` files to prefixes to import.
260268 * defines a `<name>-generic-zip` target creating a `<zip_filename>-generic.zip` archive with the generic bits,
261- prefixed with `name `
269+ prefixed with `zip_prefix `
262270 * defines a `<name>-arch-zip` target creating a `<zip_filename>-<codeql_platform>.zip` archive with the
263- arch-specific bits, prefixed with `name `
271+ arch-specific bits, prefixed with `zip_prefix `
264272 * defines a runnable `<name>-installer` target that will install the pack in `install_dest`, relative to where the
265273 rule is used. The install destination can be overridden appending `-- --destdir=...` to the `bazel run`
266- invocation. This installation _does not_ prefix the contents with `name`.
274+ invocation. This installation _does not_ prefix the contents with `zip_prefix`.
275+ The prefix for the zip files can be set with `zip_prefix`, it is `name` by default.
267276
268277 The distinction between arch-specific and generic contents is made based on whether the paths (including possible
269278 prefixes added by rules) contain the special `{CODEQL_PLATFORM}` placeholder, which in case it is present will also
270279 be replaced by the appropriate platform (`linux64`, `win64` or `osx64`).
280+ Specific file paths can be placed in the arch-specific package by adding them to `arch_overrides`, even if their
281+ path doesn't contain the `CODEQL_PLATFORM` placeholder.
271282
272283 `compression_level` can be used to tweak the compression level used when creating archives. Consider that this
273284 does not affect the contents of `zips`, only `srcs`.
274285 """
275286 internal = _make_internal (name )
276287 zip_filename = zip_filename or name
277288 zips = zips or {}
289+ if zip_prefix == None :
290+ zip_prefix = name
278291 pkg_filegroup (
279292 name = internal ("all" ),
280293 srcs = srcs ,
@@ -292,6 +305,7 @@ def codeql_pack(
292305 name = internal (kind ),
293306 src = internal ("all" ),
294307 kind = kind ,
308+ arch_overrides = arch_overrides ,
295309 visibility = ["//visibility:private" ],
296310 )
297311 if zips :
@@ -311,15 +325,15 @@ def codeql_pack(
311325 name = internal (kind , "zip" ),
312326 srcs = [internal (kind , "zip-base" ), internal (kind , "zip-info" )],
313327 out = _get_zip_filename (name , kind ),
314- prefix = name ,
328+ prefix = zip_prefix ,
315329 visibility = visibility ,
316330 )
317331 else :
318332 pkg_zip (
319333 name = internal (kind , "zip" ),
320334 srcs = [internal (kind )],
321335 visibility = visibility ,
322- package_dir = name ,
336+ package_dir = zip_prefix ,
323337 package_file_name = _get_zip_filename (name , kind ),
324338 compression_level = compression_level ,
325339 )
0 commit comments