-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
420c884
commit df47457
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
load("@io_bazel_rules_rust//test/rustfmt:rustfmt_generator.bzl", "rustfmt_generator") | ||
|
||
rustfmt_generator( | ||
name = "formatted", | ||
src = ":unformatted.rs", | ||
) | ||
|
||
sh_test( | ||
name = "rustfmt_test", | ||
size = "small", | ||
data = [ | ||
":formatted.rs", | ||
":unformatted.rs", | ||
], | ||
srcs = [":rustfmt_test.sh"], | ||
deps = ["@bazel_tools//tools/bash/runfiles"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
load("@io_bazel_rules_rust//rust:private/utils.bzl", "find_toolchain") | ||
|
||
def _rustfmt_generator_impl(ctx): | ||
toolchain = find_toolchain(ctx) | ||
rustfmt_bin = toolchain.rustfmt | ||
output = ctx.outputs.out | ||
|
||
ctx.actions.run_shell( | ||
inputs = depset([rustfmt_bin, ctx.file.src]), | ||
outputs = [output], | ||
command = "{} --emit stdout --quiet {} > {}".format(rustfmt_bin.path, ctx.file.src.path, output.path), | ||
tools = [rustfmt_bin], | ||
) | ||
|
||
|
||
rustfmt_generator = rule( | ||
_rustfmt_generator_impl, | ||
doc = "Given an unformatted Rust source file, output the file after being run through rustfmt.", | ||
attrs = { | ||
"src": attr.label( | ||
doc = "The file to be formatted.", | ||
allow_single_file = True, | ||
) | ||
}, | ||
outputs = {"out": "%{name}.rs"}, | ||
toolchains = [ | ||
"@io_bazel_rules_rust//rust:toolchain", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
set -euxo pipefail | ||
|
||
formatted="$(rlocation io_bazel_rules_rust/test/rustfmt/formatted.rs)" | ||
unformatted="$(rlocation io_bazel_rules_rust/test/rustfmt/unformatted.rs)" | ||
|
||
# Ensure that the file was formatted | ||
! diff "$unformatted" "$formatted" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fn example(){println!("test");} |