Add default -Wall -Werror or -Wall.
* When -Wno-error and -Werror are not used:
add -Wall to the front of cflags
if the project is in the WarningAllowedProjects,
otherwise add -Wall -Werror.
* Add -Wall -Werror to ndk_library build targets.
* Collect names of modules with -Wno-error or without -Werror,
and pass them to makefile variables:
SOONG_MODULES_USING_WNO_ERROR
SOONG_MODULES_ADDED_WERROR
SOONG_MODULES_ADDED_WALL
* Generate ANDROID_WARNING_ALLOWED_PROJECTS for old makefiles.
Bug: 66996870
Test: normal build
Change-Id: I31385e12b80ca946c7395a5a184ef259b029aac6
diff --git a/cc/compiler.go b/cc/compiler.go
index ca68a00..fc2eeec 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -206,6 +206,21 @@
return deps
}
+// Return true if the module is in the WarningAllowedProjects.
+func warningsAreAllowed(subdir string) bool {
+ subdir += "/"
+ for _, prefix := range config.WarningAllowedProjects {
+ if strings.HasPrefix(subdir, prefix) {
+ return true
+ }
+ }
+ return false
+}
+
+func addToModuleList(ctx ModuleContext, list string, module string) {
+ getWallWerrorMap(ctx.AConfig(), list).Store(module, true)
+}
+
// Create a Flags struct that collects the compile flags from global values,
// per-target values, module type values, and per-module Blueprints properties
func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
@@ -464,6 +479,21 @@
flags = rsFlags(ctx, flags, &compiler.Properties)
}
+ if len(compiler.Properties.Srcs) > 0 {
+ module := ctx.ModuleDir() + "/Android.bp:" + ctx.ModuleName()
+ if inList("-Wno-error", flags.CFlags) || inList("-Wno-error", flags.CppFlags) {
+ addToModuleList(ctx, modulesUsingWnoError, module)
+ } else if !inList("-Werror", flags.CFlags) && !inList("-Werror", flags.CppFlags) {
+ if warningsAreAllowed(ctx.ModuleDir()) {
+ addToModuleList(ctx, modulesAddedWall, module)
+ flags.CFlags = append([]string{"-Wall"}, flags.CFlags...)
+ } else {
+ addToModuleList(ctx, modulesAddedWerror, module)
+ flags.CFlags = append([]string{"-Wall", "-Werror"}, flags.CFlags...)
+ }
+ }
+ }
+
return flags
}
diff --git a/cc/config/global.go b/cc/config/global.go
index 44ad30b..4322436 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -118,6 +118,51 @@
ClangDefaultBase = "prebuilts/clang/host"
ClangDefaultVersion = "clang-4393122"
ClangDefaultShortVersion = "5.0.1"
+
+ WarningAllowedProjects = []string{
+ "external/boringssl/",
+ "external/libese/third_party/NXPNFC_P61_JCOP_Kit/",
+ "external/mdnsresponder/",
+ "external/protobuf/",
+ "external/skia/",
+ "device/",
+ "frameworks/av/media/libeffects/factory/",
+ "frameworks/av/media/libstagefright/codecs/",
+ "frameworks/base/tools/streaming_proto/",
+ "frameworks/ml/nn/",
+ "frameworks/native/libs/vr/libbufferhub/",
+ "frameworks/native/libs/vr/libbufferhubqueue/",
+ "frameworks/native/libs/vr/libdvr/tests/",
+ "frameworks/native/services/surfaceflinger/tests/",
+ "frameworks/native/services/vr/",
+ "hardware/interfaces/audio/effect/",
+ "hardware/interfaces/biometrics/fingerprint/",
+ "vendor/",
+ }
+
+ // Some Android.mk files still have warnings.
+ WarningAllowedOldProjects = []string{
+ "cts/hostsidetests/security/securityPatch/",
+ "cts/tests/tests/permission/jni/",
+ "development/tutorials/ReverseDebug/",
+ "external/freetype/",
+ "frameworks/av/drm/mediacas/plugins/",
+ "frameworks/av/media/libaaudio/examples/",
+ "frameworks/av/services/mediaextractor/",
+ "frameworks/base/core/tests/webkit/apk_with_native_libs/jni/",
+ "frameworks/base/tests/backup/",
+ "frameworks/native/cmds/cmd/",
+ "frameworks/webview/chromium/",
+ "hardware/interfaces/audio/2.0/",
+ "hardware/libhardware/modules/",
+ "hardware/libhardware/tests/",
+ "hardware/qcom/",
+ "sdk/emulator/mksdcard/",
+ "system/vold/tests/",
+ "test/vts-testcase/kernel/api/qtaguid/",
+ "test/vts-testcase/security/poc/target/",
+ "tools/adt/idea/android/ultimate/get_modification_time/jni/",
+ }
)
var pctx = android.NewPackageContext("android/soong/cc/config")
diff --git a/cc/makevars.go b/cc/makevars.go
index 7befb11..f7f8b60 100644
--- a/cc/makevars.go
+++ b/cc/makevars.go
@@ -18,15 +18,51 @@
"fmt"
"sort"
"strings"
+ "sync"
"android/soong/android"
"android/soong/cc/config"
)
+const (
+ modulesAddedWall = "ModulesAddedWall"
+ modulesAddedWerror = "ModulesAddedWerror"
+ modulesUsingWnoError = "ModulesUsingWnoError"
+)
+
func init() {
android.RegisterMakeVarsProvider(pctx, makeVarsProvider)
}
+func getWallWerrorMap(config android.Config, name string) *sync.Map {
+ return config.Once(name, func() interface{} {
+ return &sync.Map{}
+ }).(*sync.Map)
+}
+
+func makeStringOfKeys(ctx android.MakeVarsContext, setName string) string {
+ set := getWallWerrorMap(ctx.Config(), setName)
+ keys := []string{}
+ set.Range(func(key interface{}, value interface{}) bool {
+ keys = append(keys, key.(string))
+ return true
+ })
+ sort.Strings(keys)
+ return strings.Join(keys, " ")
+}
+
+func makeStringOfWarningAllowedProjects() string {
+ allProjects := append([]string{}, config.WarningAllowedProjects...)
+ allProjects = append(allProjects, config.WarningAllowedOldProjects...)
+ sort.Strings(allProjects)
+ // Makefile rules use pattern "path/%" to match module paths.
+ if len(allProjects) > 0 {
+ return strings.Join(allProjects, "% ") + "%"
+ } else {
+ return ""
+ }
+}
+
func makeVarsProvider(ctx android.MakeVarsContext) {
ctx.Strict("LLVM_RELEASE_VERSION", "${config.ClangShortVersion}")
ctx.Strict("LLVM_PREBUILTS_VERSION", "${config.ClangVersion}")
@@ -64,6 +100,11 @@
ctx.Strict("LLNDK_LIBRARIES", strings.Join(llndkLibraries, " "))
ctx.Strict("VNDK_PRIVATE_LIBRARIES", strings.Join(vndkPrivateLibraries, " "))
+ ctx.Strict("ANDROID_WARNING_ALLOWED_PROJECTS", makeStringOfWarningAllowedProjects())
+ ctx.Strict("SOONG_MODULES_ADDED_WALL", makeStringOfKeys(ctx, modulesAddedWall))
+ ctx.Strict("SOONG_MODULES_ADDED_WERROR", makeStringOfKeys(ctx, modulesAddedWerror))
+ ctx.Strict("SOONG_MODULES_USING_WNO_ERROR", makeStringOfKeys(ctx, modulesUsingWnoError))
+
ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS", strings.Join(asanCflags, " "))
ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS", strings.Join(asanLdflags, " "))
ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES", strings.Join(asanLibs, " "))
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index c517523..96a90fb 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -251,6 +251,8 @@
"-Wno-incompatible-library-redeclaration",
"-Wno-builtin-requires-header",
"-Wno-invalid-noreturn",
+ "-Wall",
+ "-Werror",
// These libraries aren't actually used. Don't worry about unwinding
// (avoids the need to link an unwinder into a fake library).
"-fno-unwind-tables",