Skip to content

Commit 2f3624b

Browse files
authored
Merge pull request github#18023 from github/redsun82/installer-shortcut
Bazel: add an `install` shortcut and an `experimental` attribute to `codeql_pack`
2 parents 45458ed + 918b0bf commit 2f3624b

File tree

7 files changed

+74
-44
lines changed

7 files changed

+74
-44
lines changed

.github/workflows/cpp-swift-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
- name: "Build Swift extractor using Bazel"
4949
run: |
5050
bazel clean --expunge
51-
bazel run //swift:create-extractor-pack --nouse_action_cache --noremote_accept_cached --noremote_upload_local_results --spawn_strategy=local
51+
bazel run //swift:install --nouse_action_cache --noremote_accept_cached --noremote_upload_local_results --spawn_strategy=local
5252
bazel shutdown
5353
5454
- name: Perform CodeQL Analysis

actions/BUILD.bazel

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,8 @@ load("//misc/bazel:pkg.bzl", "codeql_pack")
22

33
package(default_visibility = ["//visibility:public"])
44

5-
[
6-
codeql_pack(
7-
name = "-".join(parts),
8-
srcs = [
9-
"//actions/extractor",
10-
],
11-
pack_prefix = "/".join(parts),
12-
)
13-
for parts in (
14-
[
15-
"experimental",
16-
"actions",
17-
],
18-
["actions"],
19-
)
20-
]
5+
codeql_pack(
6+
name = "actions",
7+
srcs = ["//actions/extractor"],
8+
experimental = True,
9+
)

misc/bazel/pkg.bzl

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,8 @@ def codeql_pack(
429429
arch_overrides = None,
430430
pack_prefix = None,
431431
install_dest = "extractor-pack",
432+
installer_alias = "install",
433+
experimental = False,
432434
**kwargs):
433435
"""
434436
Define a codeql pack.
@@ -448,21 +450,64 @@ def codeql_pack(
448450
contain the `{CODEQL_PLATFORM}` marker.
449451
All files in the pack will be prefixed with `name`, unless `pack_prefix` is set, then is used instead.
450452
451-
This rule also provides a convenient installer target, with a path governed by `install_dest`.
452-
This installer is used for installing this pack into the source-tree, relative to the directory where the rule is used.
453-
See `codeql_pack_install` for more details.
453+
This rule also provides a convenient installer target named `<name>-installer`, with a path governed by `install_dest`,
454+
unless `install_dest == None`. This installer is used for installing this pack into the source-tree, relative to the
455+
directory where the rule is used. See `codeql_pack_install` for more details. If present, `installer_alias` is used
456+
to define a shorthand alias for `<name>-installer`. Be sure to change `installer_alias` or set it to `None` if a
457+
bazel package defines multiple `codeql_pack`s.
458+
459+
If `experimental = True`, a second `codeql_pack` named `<name>-experimental` is defined alongside the primary one with
460+
an `experimental` pack prefix and no installer, intended to be used when packaging the full distribution.
454461
455462
This function does not accept `visibility`, as packs are always public to make it easy to define pack groups.
456463
"""
457-
internal = _make_internal(name)
458-
zips = zips or {}
459464
if pack_prefix == None:
460465
pack_prefix = name
466+
_codeql_pack_impl(
467+
name,
468+
srcs,
469+
zips,
470+
arch_overrides,
471+
pack_prefix,
472+
install_dest,
473+
installer_alias,
474+
pkg_filegroup_kwargs = kwargs,
475+
)
476+
if experimental:
477+
_codeql_pack_impl(
478+
"%s-experimental" % name,
479+
srcs,
480+
zips,
481+
arch_overrides,
482+
pack_prefix = "experimental/%s" % pack_prefix,
483+
install_dest = None,
484+
installer_alias = None,
485+
pkg_filegroup_kwargs = kwargs,
486+
)
487+
488+
# TODO: remove this after internal repo update
489+
native.alias(
490+
name = "experimental-%s" % name,
491+
actual = "%s-experimental" % name,
492+
visibility = ["//visibility:public"],
493+
)
494+
495+
def _codeql_pack_impl(
496+
name,
497+
srcs,
498+
zips,
499+
arch_overrides,
500+
pack_prefix,
501+
install_dest,
502+
installer_alias,
503+
pkg_filegroup_kwargs):
504+
internal = _make_internal(name)
505+
zips = zips or {}
461506
pkg_filegroup(
462507
name = internal("all"),
463508
srcs = srcs,
464509
visibility = ["//visibility:private"],
465-
**kwargs
510+
**pkg_filegroup_kwargs
466511
)
467512
_codeql_pack_info(
468513
name = name,
@@ -473,7 +518,12 @@ def codeql_pack(
473518
# packs are always public, so that we can easily bundle them into groups
474519
visibility = ["//visibility:public"],
475520
)
476-
_codeql_pack_install(internal("installer"), [name], install_dest = install_dest, apply_pack_prefix = False)
521+
if install_dest:
522+
_codeql_pack_install(internal("installer"), [name], install_dest = install_dest, apply_pack_prefix = False)
523+
524+
# TODO: remove deprecated `native.existing_rule(installer_alias)` after internal repo update
525+
if installer_alias and not native.existing_rule(installer_alias):
526+
native.alias(name = installer_alias, actual = internal("installer"))
477527

478528
strip_prefix = _strip_prefix
479529

rust/BUILD.bazel

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,11 @@ codeql_pkg_files(
4646
],
4747
)
4848

49-
[
50-
codeql_pack(
51-
name = "-".join(parts),
52-
srcs = [
53-
":root-files",
54-
":tools",
55-
],
56-
pack_prefix = "/".join(parts),
57-
)
58-
for parts in (
59-
[
60-
"experimental",
61-
"rust",
62-
],
63-
["rust"],
64-
)
65-
]
49+
codeql_pack(
50+
name = "rust",
51+
srcs = [
52+
":root-files",
53+
":tools",
54+
],
55+
experimental = True,
56+
)

rust/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ If you don't have the `semmle-code` repo you may need to install Bazel manually,
1313

1414
This approach uses a released `codeql` version and is simpler to use for QL development. From your `semmle-code` directory run:
1515
```bash
16-
bazel run @codeql//rust:rust-installer
16+
bazel run @codeql//rust:install
1717
```
1818
You now need to create a [per-user CodeQL configuration file](https://docs.github.com/en/code-security/codeql-cli/using-the-advanced-functionality-of-the-codeql-cli/specifying-command-options-in-a-codeql-configuration-file#using-a-codeql-configuration-file) and specify the option:
1919
```

swift/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ brew install bazelisk
1313
then from the `ql` directory run
1414

1515
```bash
16-
bazel run //swift:create-extractor-pack
16+
bazel run //swift:install
1717
```
1818

1919
If you are running on macOS and you encounter errors mentioning `XXX is unavailable: introduced in macOS YY.ZZ`,

swift/actions/build-and-test/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ runs:
4848
- name: Build Swift extractor
4949
shell: bash
5050
run: |
51-
bazel run //swift:create-extractor-pack
51+
bazel run //swift:install
5252
- name: Run codegen tests
5353
if : ${{ github.event_name == 'pull_request' }}
5454
shell: bash

0 commit comments

Comments
 (0)