Skip to content

Commit ee7d299

Browse files
authored
Updated clippy and rustfmt failure tests to use bzlmod (#3131)
1 parent 088209e commit ee7d299

File tree

6 files changed

+56
-24
lines changed

6 files changed

+56
-24
lines changed

.bazelci/presubmit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,12 @@ tasks:
397397
name: Negative Clippy Tests
398398
platform: ubuntu2004
399399
run_targets:
400-
- "//test/clippy:clippy_failure_test"
400+
- "//test/clippy:clippy_failure_tester"
401401
rustfmt_failure:
402402
name: Negative Rustfmt Tests
403403
platform: ubuntu2004
404404
run_targets:
405-
- "//test/rustfmt:rustfmt_integration_test_suite.test_runner"
405+
- "//test/rustfmt:rustfmt_failure_tester"
406406
rust_analyzer_tests:
407407
name: Rust-Analyzer Tests
408408
platform: ubuntu2004

test/clippy/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ load(
1010
)
1111
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
1212

13-
package(default_visibility = ["//test:__subpackages__"])
13+
package(default_visibility = ["//test/unit/clippy:__pkg__"])
1414

1515
# Declaration of passing targets.
1616

@@ -167,6 +167,6 @@ rust_clippy(
167167
)
168168

169169
sh_binary(
170-
name = "clippy_failure_test",
171-
srcs = ["clippy_failure_test.sh"],
170+
name = "clippy_failure_tester",
171+
srcs = ["clippy_failure_tester.sh"],
172172
)

test/clippy/clippy_failure_test.sh renamed to test/clippy/clippy_failure_tester.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,32 @@ function test_all() {
6161

6262
mkdir -p "${NEW_WORKSPACE}/test/clippy" && \
6363
cp -r test/clippy/* "${NEW_WORKSPACE}/test/clippy/" && \
64-
cat << EOF > "${NEW_WORKSPACE}/WORKSPACE.bazel"
65-
workspace(name = "rules_rust_test_clippy")
66-
local_repository(
67-
name = "rules_rust",
64+
cat << EOF > "${NEW_WORKSPACE}/MODULE.bazel"
65+
module(name = "rules_rust_test_clippy")
66+
bazel_dep(name = "rules_rust", version = "0.0.0")
67+
local_path_override(
68+
module_name = "rules_rust",
6869
path = "${BUILD_WORKSPACE_DIRECTORY}",
6970
)
70-
load("@rules_rust//rust:repositories.bzl", "rust_repositories")
71-
rust_repositories()
71+
72+
bazel_dep(
73+
name = "bazel_skylib",
74+
version = "1.7.1",
75+
)
76+
bazel_dep(
77+
name = "rules_shell",
78+
version = "0.3.0",
79+
)
80+
81+
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
82+
use_repo(rust, "rust_toolchains")
83+
register_toolchains("@rust_toolchains//:all")
7284
EOF
7385

86+
if [[ -f "${BUILD_WORKSPACE_DIRECTORY}/.bazelversion" ]]; then
87+
cp "${BUILD_WORKSPACE_DIRECTORY}/.bazelversion" "${NEW_WORKSPACE}/.bazelversion"
88+
fi
89+
7490
# Drop the 'noclippy' tags
7591
if [ "$(uname)" == "Darwin" ]; then
7692
SEDOPTS=(-i '' -e)

test/rustfmt/BUILD.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@bazel_skylib//rules:write_file.bzl", "write_file")
2+
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
23
load(":rustfmt_integration_test_suite.bzl", "rustfmt_integration_test_suite")
34

45
exports_files([
@@ -19,3 +20,9 @@ pub fn greeting() {
1920
rustfmt_integration_test_suite(
2021
name = "rustfmt_integration_test_suite",
2122
)
23+
24+
sh_binary(
25+
name = "rustfmt_failure_tester",
26+
testonly = True,
27+
srcs = ["rustfmt_failure_tester.sh"],
28+
)

test/rustfmt/rustfmt_failure_test.sh renamed to test/rustfmt/rustfmt_failure_tester.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,34 @@ function test_all_and_apply() {
4343

4444
mkdir -p "${new_workspace}/test/rustfmt" && \
4545
cp -r test/rustfmt/* "${new_workspace}/test/rustfmt/" && \
46-
cat << EOF > "${new_workspace}/WORKSPACE.bazel"
47-
workspace(name = "rules_rust_test_rustfmt")
48-
local_repository(
49-
name = "rules_rust",
46+
cat << EOF > "${new_workspace}/MODULE.bazel"
47+
module(name = "rules_rust_test_rustfmt")
48+
bazel_dep(name = "rules_rust", version = "0.0.0")
49+
local_path_override(
50+
module_name = "rules_rust",
5051
path = "${BUILD_WORKSPACE_DIRECTORY}",
5152
)
52-
load("@rules_rust//rust:repositories.bzl", "rust_repositories")
53-
rust_repositories()
53+
54+
bazel_dep(
55+
name = "bazel_skylib",
56+
version = "1.7.1",
57+
)
58+
bazel_dep(
59+
name = "rules_shell",
60+
version = "0.3.0",
61+
)
62+
63+
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
64+
use_repo(rust, "rust_toolchains")
65+
register_toolchains("@rust_toolchains//:all")
5466
EOF
5567
# See github.com/bazelbuild/rules_rust/issues/2317.
5668
echo "build --noincompatible_sandbox_hermetic_tmp" > "${new_workspace}/.bazelrc"
5769

70+
if [[ -f "${BUILD_WORKSPACE_DIRECTORY}/.bazelversion" ]]; then
71+
cp "${BUILD_WORKSPACE_DIRECTORY}/.bazelversion" "${new_workspace}/.bazelversion"
72+
fi
73+
5874
# Drop the 'norustfmt' tags
5975
if [ "$(uname)" == "Darwin" ]; then
6076
SEDOPTS=(-i '' -e)

test/rustfmt/rustfmt_integration_test_suite.bzl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ load(
88
"rust_static_library",
99
"rustfmt_test",
1010
)
11-
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
1211

1312
_VARIANTS = {
1413
"rust_binary": rust_binary,
@@ -115,9 +114,3 @@ def rustfmt_integration_test_suite(name, **kwargs):
115114
tests = tests,
116115
**kwargs
117116
)
118-
119-
sh_binary(
120-
name = "{}.test_runner".format(name),
121-
srcs = ["rustfmt_failure_test.sh"],
122-
testonly = True,
123-
)

0 commit comments

Comments
 (0)