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
This commit is contained in:
Chih-Hung Hsieh 2017-11-14 14:09:14 -08:00
parent 6693613f11
commit 64a38dcb18
4 changed files with 118 additions and 0 deletions

View File

@ -206,6 +206,21 @@ func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
return deps 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, // Create a Flags struct that collects the compile flags from global values,
// per-target values, module type values, and per-module Blueprints properties // per-target values, module type values, and per-module Blueprints properties
func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags { func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
@ -464,6 +479,21 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
flags = rsFlags(ctx, flags, &compiler.Properties) 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 return flags
} }

View File

@ -118,6 +118,51 @@ var (
ClangDefaultBase = "prebuilts/clang/host" ClangDefaultBase = "prebuilts/clang/host"
ClangDefaultVersion = "clang-4393122" ClangDefaultVersion = "clang-4393122"
ClangDefaultShortVersion = "5.0.1" 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") var pctx = android.NewPackageContext("android/soong/cc/config")

View File

@ -18,15 +18,51 @@ import (
"fmt" "fmt"
"sort" "sort"
"strings" "strings"
"sync"
"android/soong/android" "android/soong/android"
"android/soong/cc/config" "android/soong/cc/config"
) )
const (
modulesAddedWall = "ModulesAddedWall"
modulesAddedWerror = "ModulesAddedWerror"
modulesUsingWnoError = "ModulesUsingWnoError"
)
func init() { func init() {
android.RegisterMakeVarsProvider(pctx, makeVarsProvider) 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) { func makeVarsProvider(ctx android.MakeVarsContext) {
ctx.Strict("LLVM_RELEASE_VERSION", "${config.ClangShortVersion}") ctx.Strict("LLVM_RELEASE_VERSION", "${config.ClangShortVersion}")
ctx.Strict("LLVM_PREBUILTS_VERSION", "${config.ClangVersion}") ctx.Strict("LLVM_PREBUILTS_VERSION", "${config.ClangVersion}")
@ -64,6 +100,11 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
ctx.Strict("LLNDK_LIBRARIES", strings.Join(llndkLibraries, " ")) ctx.Strict("LLNDK_LIBRARIES", strings.Join(llndkLibraries, " "))
ctx.Strict("VNDK_PRIVATE_LIBRARIES", strings.Join(vndkPrivateLibraries, " ")) 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_CFLAGS", strings.Join(asanCflags, " "))
ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS", strings.Join(asanLdflags, " ")) ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS", strings.Join(asanLdflags, " "))
ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES", strings.Join(asanLibs, " ")) ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES", strings.Join(asanLibs, " "))

View File

@ -251,6 +251,8 @@ func addStubLibraryCompilerFlags(flags Flags) Flags {
"-Wno-incompatible-library-redeclaration", "-Wno-incompatible-library-redeclaration",
"-Wno-builtin-requires-header", "-Wno-builtin-requires-header",
"-Wno-invalid-noreturn", "-Wno-invalid-noreturn",
"-Wall",
"-Werror",
// These libraries aren't actually used. Don't worry about unwinding // These libraries aren't actually used. Don't worry about unwinding
// (avoids the need to link an unwinder into a fake library). // (avoids the need to link an unwinder into a fake library).
"-fno-unwind-tables", "-fno-unwind-tables",