[shush] Clean up TODOs
Change-Id: I69b265ebfc3b32ce6ff2375d0f0ecade989267f6
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/693262
Commit-Queue: Joseph Ryan <josephry@google.com>
Reviewed-by: Tyler Mandry <tmandry@google.com>
diff --git a/tools/BUILD.gn b/tools/BUILD.gn
index 2eedb62..444d41e 100644
--- a/tools/BUILD.gn
+++ b/tools/BUILD.gn
@@ -182,7 +182,7 @@
"//tools/qemu:tests($host_toolchain)",
"//tools/rfc:tests",
"//tools/sdk-tools:tests($host_toolchain)",
- "//tools/shush:shush_test($host_toolchain)",
+ "//tools/shush:tests($host_toolchain)",
"//tools/staticanalysis:tests",
"//tools/symbol-index:tests",
"//tools/symbolizer:tests",
diff --git a/tools/shush/BUILD.gn b/tools/shush/BUILD.gn
index 37f1cb8..cdfa1fe 100644
--- a/tools/shush/BUILD.gn
+++ b/tools/shush/BUILD.gn
@@ -5,38 +5,42 @@
import("//build/rust/rustc_binary.gni")
if (is_host) {
- config("env") {
- rustenv = [ "RUST_SYSROOT=$out_rustc_prefix" ]
- }
+ _deps = [
+ "//third_party/rust_crates:anyhow",
+ "//third_party/rust_crates:argh",
+ "//third_party/rust_crates:lazy_static",
+ "//third_party/rust_crates:proc-macro2",
+ "//third_party/rust_crates:regex",
+ "//third_party/rust_crates:rustfix",
+ "//third_party/rust_crates:serde",
+ "//third_party/rust_crates:serde_json",
+ "//third_party/rust_crates:syn",
+ ]
+
+ _sources = [
+ "src/allow.rs",
+ "src/fix.rs",
+ "src/lint.rs",
+ "src/main.rs",
+ "src/owners.rs",
+ "src/span.rs",
+ ]
rustc_binary("shush") {
edition = "2021"
- with_unit_tests = true
- deps = [
- "//third_party/rust_crates:anyhow",
- "//third_party/rust_crates:argh",
- "//third_party/rust_crates:lazy_static",
- "//third_party/rust_crates:proc-macro2",
- "//third_party/rust_crates:regex",
- "//third_party/rust_crates:rustfix",
- "//third_party/rust_crates:serde",
- "//third_party/rust_crates:serde_json",
- "//third_party/rust_crates:syn",
- ]
- sources = [
- "src/allow.rs",
- "src/fix.rs",
- "src/lint.rs",
- "src/main.rs",
- "src/owners.rs",
- "src/span.rs",
- ]
+ deps = _deps
+ sources = _sources
+ rustenv = [ "RUST_SYSROOT=$out_rustc_prefix" ]
+ }
- # Specify clippy-driver path from our prebuilts for tests
+ rustc_test("shush_test") {
+ edition = "2021"
+ deps = _deps
+ sources = _sources
+ source_root = "src/main.rs"
+
test_deps = [ "//build/rust:prebuilt_toolchain_host_test_data" ]
-
- # TODO(josephry): update this to just use rustenv after http://fxrev.dev/667908 lands
- configs += [ ":env" ]
+ rustenv = [ "RUST_SYSROOT=$out_rustc_prefix" ]
}
copy("install") {
@@ -44,4 +48,9 @@
deps = [ ":shush" ]
outputs = [ "$root_build_dir/host-tools/{{source_file_part}}" ]
}
+
+ group("tests") {
+ testonly = true
+ deps = [ ":shush_test" ]
+ }
}
diff --git a/tools/shush/src/lint.rs b/tools/shush/src/lint.rs
index 0e54da4..b8746e9 100644
--- a/tools/shush/src/lint.rs
+++ b/tools/shush/src/lint.rs
@@ -19,24 +19,29 @@
pub span: Span,
}
-#[cfg(target_arch = "x86_64")]
-const HOST_ARCH: &str = "x64";
-#[cfg(target_arch = "aarch64")]
-const HOST_ARCH: &str = "arm64";
-#[cfg(target_os = "linux")]
-const HOST_OS: &str = "linux";
-#[cfg(target_os = "macos")]
-const HOST_OS: &str = "mac";
+#[allow(unused)]
+fn get_sysroot() -> String {
+ #[cfg(target_arch = "x86_64")]
+ const HOST_ARCH: &str = "x64";
+ #[cfg(target_arch = "aarch64")]
+ const HOST_ARCH: &str = "arm64";
+ #[cfg(target_os = "linux")]
+ const HOST_OS: &str = "linux";
+ #[cfg(target_os = "macos")]
+ const HOST_OS: &str = "mac";
+
+ #[cfg(test)]
+ let sysroot = env!("RUST_SYSROOT").to_owned();
+ #[cfg(not(test))]
+ let sysroot = format!("prebuilt/third_party/rust/{}-{}", HOST_OS, HOST_ARCH);
+
+ sysroot
+}
/// Returns a mapping of the lint categories (all, style, etc.) to the individual
/// names of the lints they contain by parsing the output of `clippy-driver -Whelp`.
pub fn get_categories() -> HashMap<String, HashSet<String>> {
- let sysroot = if cfg!(test) {
- // TODO(josephry): update this to just use env! after http://fxrev.dev/667908 lands
- option_env!("RUST_SYSROOT").unwrap().to_owned()
- } else {
- format!("prebuilt/third_party/rust/{}-{}", HOST_OS, HOST_ARCH)
- };
+ let sysroot = get_sysroot();
let output = Command::new(format!("{}/bin/clippy-driver", sysroot))
.arg("--sysroot")
.arg(&sysroot)
@@ -103,13 +108,11 @@
.filter_map(|d| d.code.as_ref().map(|c| filter_lints.contains(&c.code).then(|| d.clone())))
.flatten()
.for_each(|lint| {
- // The primary span is always last in the list
- // TODO(josephry): Once rustfix 0.6.1 releases, use Diagnostic::is_primary
- let span = lint.spans.last().expect("no spans found");
+ let span = lint.spans.iter().find(|s| s.is_primary).expect("no primary span found");
let file = &span.file_name;
// ignore stuff in the build directory
if file.starts_with("out/") {
- eprintln!("Ignoring file inside build dir: {}", span.file_name);
+ eprintln!("Ignoring file inside build dir: {}", file);
} else {
files
.entry(file.to_string())