Skip to content

Commit f27d48d

Browse files
authored
Merge pull request github#16622 from github/criemen/pkg-lib-nolang
`pkg.bzl`: Add features to support the nolang dist.
2 parents be4fce2 + 1498800 commit f27d48d

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

misc/bazel/pkg.bzl

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def codeql_pkg_files(
9696

9797
def _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,28 +283,35 @@ def codeql_pack(
277283
visibility = None,
278284
install_dest = "extractor-pack",
279285
compression_level = None,
286+
arch_overrides = None,
287+
zip_prefix = None,
280288
**kwargs):
281289
"""
282290
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.
284292
* 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`
286294
* 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`
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`
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.
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+
if zip_prefix == None:
314+
zip_prefix = name
302315
pkg_filegroup(
303316
name = internal("all"),
304317
srcs = srcs,
@@ -316,6 +329,7 @@ def codeql_pack(
316329
name = internal(kind),
317330
src = internal("all"),
318331
kind = kind,
332+
arch_overrides = arch_overrides,
319333
visibility = ["//visibility:private"],
320334
)
321335
if zips:
@@ -335,15 +349,15 @@ def codeql_pack(
335349
name = internal(kind, "zip"),
336350
srcs = [internal(kind, "zip-base"), internal(kind, "zip-info")],
337351
out = _get_zip_filename(name, kind),
338-
prefix = name,
352+
prefix = zip_prefix,
339353
visibility = visibility,
340354
)
341355
else:
342356
pkg_zip(
343357
name = internal(kind, "zip"),
344358
srcs = [internal(kind)],
345359
visibility = visibility,
346-
package_dir = name,
360+
package_dir = zip_prefix,
347361
package_file_name = _get_zip_filename(name, kind),
348362
compression_level = compression_level,
349363
)

0 commit comments

Comments
 (0)