Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8f1b658

Browse files
committedAug 26, 2023
Use _validation output group for rustfmt/clippy
1 parent 8861598 commit 8f1b658

File tree

18 files changed

+16
-42
lines changed

18 files changed

+16
-42
lines changed
 

‎.bazelrc

-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ coverage --experimental_fetch_all_coverage_outputs
2626

2727
# Enable rustfmt for all targets in the workspace
2828
build:rustfmt --aspects=//rust:defs.bzl%rustfmt_aspect
29-
build:rustfmt --output_groups=+rustfmt_checks
3029

3130
# Enable clippy for all targets in the workspace
3231
build:clippy --aspects=//rust:defs.bzl%rust_clippy_aspect
33-
build:clippy --output_groups=+clippy_checks
3432

3533
###############################################################################
3634
## Incompatibility flags

‎docs/flatten.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,7 @@ rust_test(
21802180
Then the targets can be analyzed with clippy using the following command:
21812181

21822182
```output
2183-
$ bazel build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect --output_groups=clippy_checks //hello_lib:all
2183+
$ bazel build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect //hello_lib:all
21842184
```
21852185

21862186

@@ -2208,7 +2208,7 @@ This aspect is used to gather information about a crate for use in rustfmt and p
22082208

22092209
Output Groups:
22102210

2211-
- `rustfmt_checks`: Executes `rustfmt --check` on the specified target.
2211+
- `_validation`: Executes `rustfmt --check` on the specified target.
22122212

22132213
The build setting `@rules_rust//:rustfmt.toml` is used to control the Rustfmt [configuration settings][cs]
22142214
used at runtime.

‎docs/rust_clippy.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Simply add the following to the `.bazelrc` file in the root of your workspace:
2222

2323
```text
2424
build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
25-
build --output_groups=+clippy_checks
2625
```
2726

2827
This will enable clippy on all [Rust targets](./defs.md).
@@ -123,7 +122,7 @@ rust_test(
123122
Then the targets can be analyzed with clippy using the following command:
124123

125124
```output
126-
$ bazel build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect --output_groups=clippy_checks //hello_lib:all
125+
$ bazel build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect //hello_lib:all
127126
```
128127

129128

‎docs/rust_clippy.vm

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Simply add the following to the `.bazelrc` file in the root of your workspace:
1616

1717
```text
1818
build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
19-
build --output_groups=+clippy_checks
2019
```
2120

2221
This will enable clippy on all [Rust targets](./defs.md).

‎docs/rust_fmt.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ in your workspace. Simply run `bazel run @rules_rust//:rustfmt` to format source
2424

2525
In addition to this formatter, a simple check can be performed using the [rustfmt_aspect](#rustfmt-aspect) aspect by running
2626
```text
27-
bazel build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect --output_groups=rustfmt_checks
27+
bazel build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
2828
```
2929

3030
Add the following to a `.bazelrc` file to enable this check during the build phase.
3131

3232
```text
3333
build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
34-
build --output_groups=+rustfmt_checks
3534
```
3635

3736
It's recommended to only enable this aspect in your CI environment so formatting issues do not
@@ -103,7 +102,7 @@ This aspect is used to gather information about a crate for use in rustfmt and p
103102

104103
Output Groups:
105104

106-
- `rustfmt_checks`: Executes `rustfmt --check` on the specified target.
105+
- `_validation`: Executes `rustfmt --check` on the specified target.
107106

108107
The build setting `@rules_rust//:rustfmt.toml` is used to control the Rustfmt [configuration settings][cs]
109108
used at runtime.

‎docs/rust_fmt.vm

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ in your workspace. Simply run `bazel run @rules_rust//:rustfmt` to format source
1717

1818
In addition to this formatter, a simple check can be performed using the [rustfmt_aspect](#rustfmt-aspect) aspect by running
1919
```text
20-
bazel build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect --output_groups=rustfmt_checks
20+
bazel build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
2121
```
2222

2323
Add the following to a `.bazelrc` file to enable this check during the build phase.
2424

2525
```text
2626
build --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
27-
build --output_groups=+rustfmt_checks
2827
```
2928

3029
It's recommended to only enable this aspect in your CI environment so formatting issues do not

‎examples/.bazelrc

-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ build:windows --enable_runfiles
88

99
# Enable rustfmt for all targets in the workspace
1010
build:rustfmt --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
11-
build:rustfmt --output_groups=+rustfmt_checks
1211

1312
# Enable clippy for all targets in the workspace
1413
build:clippy --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
15-
build:clippy --output_groups=+clippy_checks
1614

1715
# This import should always be last to allow users to override
1816
# settings for local development.

‎examples/crate_universe/.bazelrc

-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ build:windows --enable_runfiles
88

99
# Enable rustfmt for all targets in the workspace
1010
build:rustfmt --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
11-
build:rustfmt --output_groups=+rustfmt_checks
1211

1312
# Enable clippy for all targets in the workspace
1413
build:clippy --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
15-
build:clippy --output_groups=+clippy_checks
1614

1715
# Confirm crate universe works without relying on the legacy
1816
# external symlink in runfiles.

‎examples/crate_universe/cargo_aliases/.bazelrc

-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ build:windows --enable_runfiles
77

88
# Enable rustfmt
99
build:strict --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
10-
build:strict --output_groups=+rustfmt_checks
1110

1211
# Enable clippy
1312
build:strict --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
14-
build:strict --output_groups=+clippy_checks
1513

1614
# This import should always be last to allow users to override
1715
# settings for local development.

‎examples/crate_universe/cargo_remote/.bazelrc

-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ build:windows --enable_runfiles
77

88
# Enable rustfmt
99
build:strict --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
10-
build:strict --output_groups=+rustfmt_checks
1110

1211
# Enable clippy
1312
build:strict --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
14-
build:strict --output_groups=+clippy_checks
1513

1614
# This import should always be last to allow users to override
1715
# settings for local development.

‎examples/crate_universe/cargo_workspace/.bazelrc

-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ build:windows --enable_runfiles
77

88
# Enable rustfmt
99
build:strict --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
10-
build:strict --output_groups=+rustfmt_checks
1110

1211
# Enable clippy
1312
build:strict --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
14-
build:strict --output_groups=+clippy_checks
1513

1614
# This import should always be last to allow users to override
1715
# settings for local development.

‎examples/crate_universe/multi_package/.bazelrc

-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ build:windows --enable_runfiles
77

88
# Enable rustfmt
99
build:strict --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
10-
build:strict --output_groups=+rustfmt_checks
1110

1211
# Enable clippy
1312
build:strict --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
14-
build:strict --output_groups=+clippy_checks
1513

1614
# This import should always be last to allow users to override
1715
# settings for local development.

‎examples/crate_universe/no_cargo_manifests/.bazelrc

-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ build:windows --enable_runfiles
77

88
# Enable rustfmt
99
build:strict --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
10-
build:strict --output_groups=+rustfmt_checks
1110

1211
# Enable clippy
1312
build:strict --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
14-
build:strict --output_groups=+clippy_checks
1513

1614
# This import should always be last to allow users to override
1715
# settings for local development.

‎examples/crate_universe_unnamed/.bazelrc

-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ build:windows --enable_runfiles
88

99
# Enable rustfmt for all targets in the workspace
1010
build:rustfmt --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
11-
build:rustfmt --output_groups=+rustfmt_checks
1211

1312
# Enable clippy for all targets in the workspace
1413
build:clippy --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
15-
build:clippy --output_groups=+clippy_checks
1614

1715
# This import should always be last to allow users to override
1816
# settings for local development.

‎rust/private/clippy.bzl

+6-9
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def _get_clippy_ready_crate_info(target, aspect_ctx = None):
8282
def _clippy_aspect_impl(target, ctx):
8383
crate_info = _get_clippy_ready_crate_info(target, ctx)
8484
if not crate_info:
85-
return [ClippyInfo(output = depset([]))]
85+
return [ClippyInfo(output = depset())]
8686

8787
toolchain = find_toolchain(ctx)
8888
cc_toolchain, feature_configuration = find_cc_toolchain(ctx)
@@ -181,14 +181,12 @@ See https://github.com/bazelbuild/rules_rust/pull/1264#discussion_r853241339 for
181181
)
182182

183183
return [
184-
OutputGroupInfo(clippy_checks = depset([clippy_out])),
184+
OutputGroupInfo(_validation = depset([clippy_out])),
185185
ClippyInfo(output = depset([clippy_out])),
186186
]
187187

188188
# Example: Run the clippy checker on all targets in the codebase.
189-
# bazel build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect \
190-
# --output_groups=clippy_checks \
191-
# //...
189+
# bazel build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect //...
192190
rust_clippy_aspect = aspect(
193191
fragments = ["cpp"],
194192
host_fragments = ["cpp"],
@@ -266,15 +264,14 @@ rust_test(
266264
Then the targets can be analyzed with clippy using the following command:
267265
268266
```output
269-
$ bazel build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect \
270-
--output_groups=clippy_checks //hello_lib:all
267+
$ bazel build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect //hello_lib:all
271268
```
272269
""",
273270
)
274271

275272
def _rust_clippy_rule_impl(ctx):
276-
clippy_ready_targets = [dep for dep in ctx.attr.deps if "clippy_checks" in dir(dep[OutputGroupInfo])]
277-
files = depset([], transitive = [dep[OutputGroupInfo].clippy_checks for dep in clippy_ready_targets])
273+
clippy_ready_targets = [dep for dep in ctx.attr.deps if ClippyInfo in dep[OutputGroupInfo]]
274+
files = depset([], transitive = [dep[OutputGroupInfo]._validation for dep in clippy_ready_targets])
278275
return [DefaultInfo(files = files)]
279276

280277
rust_clippy = rule(

‎rust/private/rustfmt.bzl

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def _rustfmt_aspect_impl(target, ctx):
111111

112112
return [
113113
OutputGroupInfo(
114-
rustfmt_checks = depset([marker]),
114+
_validation = depset([marker]),
115115
),
116116
]
117117

@@ -122,7 +122,7 @@ This aspect is used to gather information about a crate for use in rustfmt and p
122122
123123
Output Groups:
124124
125-
- `rustfmt_checks`: Executes `rustfmt --check` on the specified target.
125+
- `_validation`: Executes `rustfmt --check` on the specified target.
126126
127127
The build setting `@rules_rust//:rustfmt.toml` is used to control the Rustfmt [configuration settings][cs]
128128
used at runtime.

‎test/rust_analyzer/rust_analyzer_test_runner.sh

-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ test --test_output=errors
4040
# targets that would otherwise not run due to them being tagged as "manual".
4141
# Note that that tag is stripped for this test.
4242
build:strict --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
43-
build:strict --output_groups=+rustfmt_checks
4443
build:strict --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
45-
build:strict --output_groups=+clippy_checks
4644
EOF
4745

4846
echo "${new_workspace}"

‎test/unit/clippy/clippy_test.bzl

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
load("@bazel_skylib//lib:unittest.bzl", "analysistest")
44
load("//rust:defs.bzl", "rust_clippy_aspect")
5+
load("//rust:rust_common.bzl", "ClippyInfo")
56
load("//test/unit:common.bzl", "assert_argv_contains", "assert_list_contains_adjacent_elements")
67

78
def _find_clippy_action(actions):
@@ -24,7 +25,7 @@ def _clippy_aspect_action_has_flag_impl(ctx, flags):
2425
flag,
2526
)
2627

27-
clippy_checks = target[OutputGroupInfo].clippy_checks.to_list()
28+
clippy_checks = target[ClippyInfo].output.to_list()
2829
if len(clippy_checks) != 1:
2930
fail("clippy_checks is only expected to contain 1 file")
3031

0 commit comments

Comments
 (0)
Please sign in to comment.