Explicitly define Rust default lints

Add documentation on how lints are defined and used in Android. Merge
the deny_warnings attribute with a new attribute (no_lint) which can be
used to disable the default linting parameters.
Explicitly allow all lints for external/ and prebuilts/, which remove
any warning when building sysroot for the devices.

Test: cd external/rust/crates; mma
Test: add dummy internal Rust module; mma
Change-Id: I62be1c41aeda4068fb9e288038727c1de5ffe547
This commit is contained in:
Thiébaud Weksteen
2020-06-30 21:43:35 +02:00
parent cfc2df847c
commit 8e46efac71
6 changed files with 156 additions and 92 deletions

View File

@@ -28,10 +28,6 @@ func getEdition(compiler *baseCompiler) string {
return proptools.StringDefault(compiler.Properties.Edition, config.DefaultEdition)
}
func getDenyWarnings(compiler *baseCompiler) bool {
return BoolDefault(compiler.Properties.Deny_warnings, config.DefaultDenyWarnings)
}
func (compiler *baseCompiler) setNoStdlibs() {
compiler.Properties.No_stdlibs = proptools.BoolPtr(true)
}
@@ -56,8 +52,8 @@ type BaseCompilerProperties struct {
// path to the source file that is the main entry point of the program (e.g. main.rs or lib.rs)
Srcs []string `android:"path,arch_variant"`
// whether to pass "-D warnings" to rustc. Defaults to true.
Deny_warnings *bool
// whether to suppress the standard lint flags - default to false
No_lint *bool
// flags to pass to rustc
Flags []string `android:"path,arch_variant"`
@@ -145,8 +141,8 @@ func (compiler *baseCompiler) featuresToFlags(features []string) []string {
func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flags {
if getDenyWarnings(compiler) {
flags.RustFlags = append(flags.RustFlags, "-D warnings")
if !Bool(compiler.Properties.No_lint) {
flags.RustFlags = append(flags.RustFlags, config.RustcLintsForDir(ctx.ModuleDir()))
}
flags.RustFlags = append(flags.RustFlags, compiler.Properties.Flags...)
flags.RustFlags = append(flags.RustFlags, compiler.featuresToFlags(compiler.Properties.Features)...)