blob: da24880f3311afdbb3f81a39453a37b8641fc482 [file] [log] [blame]
# Copyright 2021 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/rust/config.gni")
# Defines a clippy target corresponding to a given `rustc_{library/binary/test}` target.
# This will emit json lints to the target's gen directory in a `target_name.clippy` file.
template("clippy") {
_output = "$target_gen_dir/$target_name"
# These generated files collect the rlibs of this targets direct and transitive dependencies
generated_file("$target_name.depsfile") {
forward_variables_from(invoker, [ "testonly" ])
deps = invoker.deps
outputs = [ "$_output.deps" ]
data_keys = [ "rlib" ]
walk_keys = [ "rust_barrier" ]
}
generated_file("$target_name.transdepsfile") {
forward_variables_from(invoker, [ "testonly" ])
deps = invoker.deps
outputs = [ "$_output.transdeps" ]
data_keys = [ "searchdir" ]
}
action(target_name) {
# Some clippy targets leak the output dir, but these aren't run remotely, nor are they depended
# on by anything which does. So just opt out all clippy targets.
no_output_dir_leaks = false
forward_variables_from(invoker,
[
"testonly",
"configs",
])
sources = invoker.sources
deps = invoker.deps
deps += [
":${invoker.target_name}.depsfile",
":${invoker.target_name}.transdepsfile",
]
if (defined(invoker.non_rust_deps)) {
deps += invoker.non_rust_deps
}
inputs = [
"$_output.deps",
"$_output.transdeps",
]
script = "//build/rust/clippy_wrapper.sh"
output = _output
outputs = [ output ]
_jq = "//prebuilt/third_party/jq/${host_platform}/bin/jq"
args = [
"--output",
rebase_path(_output, root_build_dir),
"--jq",
rebase_path(_jq, root_build_dir),
]
if (clippy_cause_failure) {
args += [ "--fail" ]
}
args += [
"--",
"env",
]
if (defined(invoker.rustenv)) {
args += invoker.rustenv
}
args += [
"$rebased_rustc_prefix/bin/clippy-driver",
rebase_path(invoker.crate_root, root_build_dir),
"--sysroot=$rebased_rustc_prefix",
"--crate-type=${invoker.clippy_crate_type}",
"{{rustflags}}",
"-Wwarnings", # undo -Dwarnings
]
if (clippy_force_warn) {
args += [ "--force-warn=clippy::all" ]
} else {
_level = "A"
if (clippy_warn) {
_level = "W"
}
args += [
"-${_level}clippy::all",
"-Dclippy::correctness",
"-Dclippy::missing_safety_doc",
]
}
args += invoker.rustflags
if (invoker.clippy_crate_type == "proc-macro") {
args += [ "--extern=proc_macro" ]
}
}
}