Deny rust warnings by default.

* "-D warnings" means "deny all warnings" and make them errors.
* Modules with warnings should fix all warnings or use
        deny_warnings: false

Bug: 141699953
Test: mm in projects with Rust modules
Change-Id: I6310dee8e34b7780937e8fc1834016a04a943a2f
This commit is contained in:
Chih-Hung Hsieh
2019-09-26 18:59:27 -07:00
parent 2784fda152
commit efdd7aca76
2 changed files with 12 additions and 1 deletions

View File

@@ -25,7 +25,8 @@ import (
func NewBaseCompiler(dir, dir64 string) *baseCompiler { func NewBaseCompiler(dir, dir64 string) *baseCompiler {
return &baseCompiler{ return &baseCompiler{
Properties: BaseCompilerProperties{ Properties: BaseCompilerProperties{
Edition: &config.DefaultEdition, Edition: &config.DefaultEdition,
Deny_warnings: config.DefaultDenyWarnings,
}, },
dir: dir, dir: dir,
dir64: dir64, dir64: dir64,
@@ -33,6 +34,9 @@ func NewBaseCompiler(dir, dir64 string) *baseCompiler {
} }
type BaseCompilerProperties struct { type BaseCompilerProperties struct {
// whether to pass "-D warnings" to rustc. Defaults to true.
Deny_warnings *bool
// flags to pass to rustc // flags to pass to rustc
Flags []string `android:"path,arch_variant"` Flags []string `android:"path,arch_variant"`
@@ -109,6 +113,9 @@ func (compiler *baseCompiler) featuresToFlags(features []string) []string {
func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flags { func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flags {
if Bool(compiler.Properties.Deny_warnings) {
flags.RustFlags = append(flags.RustFlags, "-D warnings")
}
flags.RustFlags = append(flags.RustFlags, compiler.Properties.Flags...) flags.RustFlags = append(flags.RustFlags, compiler.Properties.Flags...)
flags.RustFlags = append(flags.RustFlags, compiler.featuresToFlags(compiler.Properties.Features)...) flags.RustFlags = append(flags.RustFlags, compiler.featuresToFlags(compiler.Properties.Features)...)
flags.RustFlags = append(flags.RustFlags, "--edition="+*compiler.Properties.Edition) flags.RustFlags = append(flags.RustFlags, "--edition="+*compiler.Properties.Edition)

View File

@@ -17,6 +17,8 @@ package config
import ( import (
"strings" "strings"
"github.com/google/blueprint/proptools"
"android/soong/android" "android/soong/android"
_ "android/soong/cc/config" _ "android/soong/cc/config"
) )
@@ -33,6 +35,8 @@ var (
"libtest", "libtest",
} }
DefaultDenyWarnings = proptools.BoolPtr(true)
deviceGlobalRustFlags = []string{} deviceGlobalRustFlags = []string{}
deviceGlobalLinkFlags = []string{ deviceGlobalLinkFlags = []string{