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

Updated clippy and rustfmt failure tests to use bzlmod #3131

Merged
merged 2 commits into from
Dec 29, 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
4 changes: 2 additions & 2 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,12 @@ tasks:
name: Negative Clippy Tests
platform: ubuntu2004
run_targets:
- "//test/clippy:clippy_failure_test"
- "//test/clippy:clippy_failure_tester"
rustfmt_failure:
name: Negative Rustfmt Tests
platform: ubuntu2004
run_targets:
- "//test/rustfmt:rustfmt_integration_test_suite.test_runner"
- "//test/rustfmt:rustfmt_failure_tester"
rust_analyzer_tests:
name: Rust-Analyzer Tests
platform: ubuntu2004
Expand Down
6 changes: 3 additions & 3 deletions test/clippy/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ load(
)
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")

package(default_visibility = ["//test:__subpackages__"])
package(default_visibility = ["//test/unit/clippy:__pkg__"])

# Declaration of passing targets.

Expand Down Expand Up @@ -167,6 +167,6 @@ rust_clippy(
)

sh_binary(
name = "clippy_failure_test",
srcs = ["clippy_failure_test.sh"],
name = "clippy_failure_tester",
srcs = ["clippy_failure_tester.sh"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,32 @@ function test_all() {

mkdir -p "${NEW_WORKSPACE}/test/clippy" && \
cp -r test/clippy/* "${NEW_WORKSPACE}/test/clippy/" && \
cat << EOF > "${NEW_WORKSPACE}/WORKSPACE.bazel"
workspace(name = "rules_rust_test_clippy")
local_repository(
name = "rules_rust",
cat << EOF > "${NEW_WORKSPACE}/MODULE.bazel"
module(name = "rules_rust_test_clippy")
bazel_dep(name = "rules_rust", version = "0.0.0")
local_path_override(
module_name = "rules_rust",
path = "${BUILD_WORKSPACE_DIRECTORY}",
)
load("@rules_rust//rust:repositories.bzl", "rust_repositories")
rust_repositories()

bazel_dep(
name = "bazel_skylib",
version = "1.7.1",
)
bazel_dep(
name = "rules_shell",
version = "0.3.0",
)

rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
use_repo(rust, "rust_toolchains")
register_toolchains("@rust_toolchains//:all")
EOF

if [[ -f "${BUILD_WORKSPACE_DIRECTORY}/.bazelversion" ]]; then
cp "${BUILD_WORKSPACE_DIRECTORY}/.bazelversion" "${NEW_WORKSPACE}/.bazelversion"
fi

# Drop the 'noclippy' tags
if [ "$(uname)" == "Darwin" ]; then
SEDOPTS=(-i '' -e)
Expand Down
7 changes: 7 additions & 0 deletions test/rustfmt/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
load(":rustfmt_integration_test_suite.bzl", "rustfmt_integration_test_suite")

exports_files([
Expand All @@ -19,3 +20,9 @@ pub fn greeting() {
rustfmt_integration_test_suite(
name = "rustfmt_integration_test_suite",
)

sh_binary(
name = "rustfmt_failure_tester",
testonly = True,
srcs = ["rustfmt_failure_tester.sh"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,34 @@ function test_all_and_apply() {

mkdir -p "${new_workspace}/test/rustfmt" && \
cp -r test/rustfmt/* "${new_workspace}/test/rustfmt/" && \
cat << EOF > "${new_workspace}/WORKSPACE.bazel"
workspace(name = "rules_rust_test_rustfmt")
local_repository(
name = "rules_rust",
cat << EOF > "${new_workspace}/MODULE.bazel"
module(name = "rules_rust_test_rustfmt")
bazel_dep(name = "rules_rust", version = "0.0.0")
local_path_override(
module_name = "rules_rust",
path = "${BUILD_WORKSPACE_DIRECTORY}",
)
load("@rules_rust//rust:repositories.bzl", "rust_repositories")
rust_repositories()

bazel_dep(
name = "bazel_skylib",
version = "1.7.1",
)
bazel_dep(
name = "rules_shell",
version = "0.3.0",
)

rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
use_repo(rust, "rust_toolchains")
register_toolchains("@rust_toolchains//:all")
EOF
# See github.com/bazelbuild/rules_rust/issues/2317.
echo "build --noincompatible_sandbox_hermetic_tmp" > "${new_workspace}/.bazelrc"

if [[ -f "${BUILD_WORKSPACE_DIRECTORY}/.bazelversion" ]]; then
cp "${BUILD_WORKSPACE_DIRECTORY}/.bazelversion" "${new_workspace}/.bazelversion"
fi

# Drop the 'norustfmt' tags
if [ "$(uname)" == "Darwin" ]; then
SEDOPTS=(-i '' -e)
Expand Down
7 changes: 0 additions & 7 deletions test/rustfmt/rustfmt_integration_test_suite.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ load(
"rust_static_library",
"rustfmt_test",
)
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")

_VARIANTS = {
"rust_binary": rust_binary,
Expand Down Expand Up @@ -115,9 +114,3 @@ def rustfmt_integration_test_suite(name, **kwargs):
tests = tests,
**kwargs
)

sh_binary(
name = "{}.test_runner".format(name),
srcs = ["rustfmt_failure_test.sh"],
testonly = True,
)
Loading