Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel: add an install shortcut and an experimental attribute to codeql_pack #18023

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cpp-swift-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: "Build Swift extractor using Bazel"
run: |
bazel clean --expunge
bazel run //swift:create-extractor-pack --nouse_action_cache --noremote_accept_cached --noremote_upload_local_results --spawn_strategy=local
bazel run //swift:install --nouse_action_cache --noremote_accept_cached --noremote_upload_local_results --spawn_strategy=local
bazel shutdown

- name: Perform CodeQL Analysis
Expand Down
21 changes: 5 additions & 16 deletions actions/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,8 @@ load("//misc/bazel:pkg.bzl", "codeql_pack")

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

[
codeql_pack(
name = "-".join(parts),
srcs = [
"//actions/extractor",
],
pack_prefix = "/".join(parts),
)
for parts in (
[
"experimental",
"actions",
],
["actions"],
)
]
codeql_pack(
name = "actions",
srcs = ["//actions/extractor"],
experimental = True,
)
64 changes: 57 additions & 7 deletions misc/bazel/pkg.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ def codeql_pack(
arch_overrides = None,
pack_prefix = None,
install_dest = "extractor-pack",
installer_alias = "install",
experimental = False,
**kwargs):
"""
Define a codeql pack.
Expand All @@ -448,21 +450,64 @@ def codeql_pack(
contain the `{CODEQL_PLATFORM}` marker.
All files in the pack will be prefixed with `name`, unless `pack_prefix` is set, then is used instead.

This rule also provides a convenient installer target, with a path governed by `install_dest`.
This installer is used for installing this pack into the source-tree, relative to the directory where the rule is used.
See `codeql_pack_install` for more details.
This rule also provides a convenient installer target named `<name>-installer`, with a path governed by `install_dest`,
unless `install_dest == None`. This installer is used for installing this pack into the source-tree, relative to the
directory where the rule is used. See `codeql_pack_install` for more details. If present, `installer_alias` is used
to define a shorthand alias for `<name>-installer`. Be sure to change `installer_alias` or set it to `None` if a
bazel package defines multiple `codeql_pack`s.

If `experimental = True`, a second `codeql_pack` named `<name>-experimental` is defined alongside the primary one with
an `experimental` pack prefix and no installer, intended to be used when packaging the full distribution.

This function does not accept `visibility`, as packs are always public to make it easy to define pack groups.
"""
internal = _make_internal(name)
zips = zips or {}
if pack_prefix == None:
pack_prefix = name
_codeql_pack_impl(
name,
srcs,
zips,
arch_overrides,
pack_prefix,
install_dest,
installer_alias,
pkg_filegroup_kwargs = kwargs,
)
if experimental:
_codeql_pack_impl(
"%s-experimental" % name,
srcs,
zips,
arch_overrides,
pack_prefix = "experimental/%s" % pack_prefix,
install_dest = None,
installer_alias = None,
pkg_filegroup_kwargs = kwargs,
)

# TODO: remove this after internal repo update
native.alias(
name = "experimental-%s" % name,
actual = "%s-experimental" % name,
visibility = ["//visibility:public"],
)

def _codeql_pack_impl(
name,
srcs,
zips,
arch_overrides,
pack_prefix,
install_dest,
installer_alias,
pkg_filegroup_kwargs):
internal = _make_internal(name)
zips = zips or {}
pkg_filegroup(
name = internal("all"),
srcs = srcs,
visibility = ["//visibility:private"],
**kwargs
**pkg_filegroup_kwargs
)
_codeql_pack_info(
name = name,
Expand All @@ -473,7 +518,12 @@ def codeql_pack(
# packs are always public, so that we can easily bundle them into groups
visibility = ["//visibility:public"],
)
_codeql_pack_install(internal("installer"), [name], install_dest = install_dest, apply_pack_prefix = False)
if install_dest:
_codeql_pack_install(internal("installer"), [name], install_dest = install_dest, apply_pack_prefix = False)

# TODO: remove deprecated `native.existing_rule(installer_alias)` after internal repo update
if installer_alias and not native.existing_rule(installer_alias):
native.alias(name = installer_alias, actual = internal("installer"))

strip_prefix = _strip_prefix

Expand Down
25 changes: 8 additions & 17 deletions rust/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,11 @@ codeql_pkg_files(
],
)

[
codeql_pack(
name = "-".join(parts),
srcs = [
":root-files",
":tools",
],
pack_prefix = "/".join(parts),
)
for parts in (
[
"experimental",
"rust",
],
["rust"],
)
]
codeql_pack(
name = "rust",
srcs = [
":root-files",
":tools",
],
experimental = True,
)
2 changes: 1 addition & 1 deletion rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ If you don't have the `semmle-code` repo you may need to install Bazel manually,

This approach uses a released `codeql` version and is simpler to use for QL development. From your `semmle-code` directory run:
```bash
bazel run @codeql//rust:rust-installer
bazel run @codeql//rust:install
```
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:
```
Expand Down
2 changes: 1 addition & 1 deletion swift/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ brew install bazelisk
then from the `ql` directory run

```bash
bazel run //swift:create-extractor-pack
bazel run //swift:install
```

If you are running on macOS and you encounter errors mentioning `XXX is unavailable: introduced in macOS YY.ZZ`,
Expand Down
2 changes: 1 addition & 1 deletion swift/actions/build-and-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ runs:
- name: Build Swift extractor
shell: bash
run: |
bazel run //swift:create-extractor-pack
bazel run //swift:install
- name: Run codegen tests
if : ${{ github.event_name == 'pull_request' }}
shell: bash
Expand Down