@@ -96,6 +96,7 @@ def codeql_pkg_files(
9696
9797def _extract_pkg_filegroup_impl (ctx ):
9898 src = ctx .attr .src [PackageFilegroupInfo ]
99+ arch_overrides = ctx .attr .arch_overrides
99100 platform = _detect_platform (ctx )
100101
101102 if src .pkg_dirs or src .pkg_symlinks :
@@ -106,8 +107,11 @@ def _extract_pkg_filegroup_impl(ctx):
106107 dest_src_map = {}
107108 for dest , file in pfi .dest_src_map .items ():
108109 file_kind , expanded_dest = _expand_path (dest , platform )
110+ if file_kind == "generic" and dest in arch_overrides :
111+ file_kind = "arch"
109112 if file_kind == ctx .attr .kind :
110113 dest_src_map [expanded_dest ] = file
114+
111115 if dest_src_map :
112116 pkg_files .append ((PackageFilesInfo (dest_src_map = dest_src_map , attributes = pfi .attributes ), origin ))
113117
@@ -125,12 +129,14 @@ _extract_pkg_filegroup = rule(
125129 destination paths to the relevant codeql platform (linux64, win64 or osx64).
126130 The distinction between generic and arch contents is given on a per-file basis depending on the install path
127131 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`.
128133 No `pkg_dirs` or `pkg_symlink` must have been used for assembling the source mapping information: we could
129134 easily add support for that, but we don't require it for now.
130135 """ ,
131136 attrs = {
132137 "src" : attr .label (providers = [PackageFilegroupInfo , DefaultInfo ]),
133138 "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" ),
134140 } | _PLAT_DETECTION_ATTRS ,
135141)
136142
@@ -277,6 +283,8 @@ def codeql_pack(
277283 visibility = None ,
278284 install_dest = "extractor-pack" ,
279285 compression_level = None ,
286+ arch_overrides = None ,
287+ prefix_override = None ,
280288 ** kwargs ):
281289 """
282290 Define a codeql pack. This macro accepts `pkg_files`, `pkg_filegroup` or their `codeql_*` counterparts as `srcs`.
@@ -288,17 +296,23 @@ def codeql_pack(
288296 * defines a runnable `<name>-installer` target that will install the pack in `install_dest`, relative to where the
289297 rule is used. The install destination can be overridden appending `-- --destdir=...` to the `bazel run`
290298 invocation. This installation _does not_ prefix the contents with `name`.
299+ The prefix for the zip files can be overriden with `prefix_override`.
291300
292301 The distinction between arch-specific and generic contents is made based on whether the paths (including possible
293302 prefixes added by rules) contain the special `{CODEQL_PLATFORM}` placeholder, which in case it is present will also
294303 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.
295306
296307 `compression_level` can be used to tweak the compression level used when creating archives. Consider that this
297308 does not affect the contents of `zips`, only `srcs`.
298309 """
299310 internal = _make_internal (name )
300311 zip_filename = zip_filename or name
301312 zips = zips or {}
313+ prefix = name
314+ if prefix_override != None :
315+ prefix = prefix_override
302316 pkg_filegroup (
303317 name = internal ("all" ),
304318 srcs = srcs ,
@@ -316,6 +330,7 @@ def codeql_pack(
316330 name = internal (kind ),
317331 src = internal ("all" ),
318332 kind = kind ,
333+ arch_overrides = arch_overrides ,
319334 visibility = ["//visibility:private" ],
320335 )
321336 if zips :
@@ -335,15 +350,15 @@ def codeql_pack(
335350 name = internal (kind , "zip" ),
336351 srcs = [internal (kind , "zip-base" ), internal (kind , "zip-info" )],
337352 out = _get_zip_filename (name , kind ),
338- prefix = name ,
353+ prefix = prefix ,
339354 visibility = visibility ,
340355 )
341356 else :
342357 pkg_zip (
343358 name = internal (kind , "zip" ),
344359 srcs = [internal (kind )],
345360 visibility = visibility ,
346- package_dir = name ,
361+ package_dir = prefix ,
347362 package_file_name = _get_zip_filename (name , kind ),
348363 compression_level = compression_level ,
349364 )
0 commit comments