You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.5 KiB

/*
* Copyright (c) Hisilicon Technologies Co., Ltd.. 2020-2020. All rights reserved.
* Description: Strictly control the compilation options not including options beginning with -Wno
* Author: os_build
* Create: 2020-03-05
*/
package config
import (
"strings"
"android/soong/android"
)
func init() {
// remove all "-Wno-XXX" and "-Werror=XXX" options
strictGlobalCflags, _ := RemovePrefixFromList("-Wno-", commonGlobalCflags)
strictGlobalCflags, _ = RemovePrefixFromList("-Werror=", strictGlobalCflags)
// remove "-Wformat" "-Winit-self"
// "-Wformat" replaced by "-Wformat=2"
// "-Wall" including "-Winit-self"
_, strictGlobalCflags = RemoveFromList("-Wformat", strictGlobalCflags)
_, strictGlobalCflags = RemoveFromList("-Winit-self", strictGlobalCflags)
// Warning compilation options
strictGlobalCflags = append(strictGlobalCflags, "-Wextra")
strictGlobalCflags = append(strictGlobalCflags, "-Wdate-time")
strictGlobalCflags = append(strictGlobalCflags, "-Wfloat-equal")
strictGlobalCflags = append(strictGlobalCflags, "-Wshadow")
strictGlobalCflags = append(strictGlobalCflags, "-Wformat=2")
// Code generation options
strictGlobalCflags = append(strictGlobalCflags, "-fno-common")
strictGlobalCppflags, _:= RemovePrefixFromList("-Wno-", commonGlobalCppflags)
strictGlobalCppflags, _= RemovePrefixFromList("-Werror=", strictGlobalCppflags)
strictGlobalCppflags = append(strictGlobalCppflags, "-Weffc++")
strictnoOverrideGlobalCflags, _:= RemovePrefixFromList("-Wno-", noOverrideGlobalCflags)
strictnoOverrideGlobalCflags, _= RemovePrefixFromList("-Werror=", strictnoOverrideGlobalCflags)
strictdeviceGlobalCflags,_ := RemovePrefixFromList("-Wno-", deviceGlobalCflags)
strictdeviceGlobalCflags,_ = RemovePrefixFromList("-Werror=", strictdeviceGlobalCflags)
stricthostGlobalCflags,_ := RemovePrefixFromList("-Wno-", hostGlobalCflags)
stricthostGlobalCflags,_ = RemovePrefixFromList("-Werror=", stricthostGlobalCflags)
pctx.StaticVariable("StrictClangGlobalCflags",
strings.Join(append(ClangFilterUnknownCflags(strictGlobalCflags), "${ClangStrictCflags}"), " "))
pctx.StaticVariable("StrictClangGlobalCppflags",
strings.Join(append(ClangFilterUnknownCflags(strictGlobalCppflags), "${ClangStrictCppflags}"), " "))
pctx.StaticVariable("StrictNoOverrideClangGlobalCflags",
strings.Join(append(ClangFilterUnknownCflags(strictnoOverrideGlobalCflags), "${ClangStrictNoOverrideCflags}"), " "))
pctx.VariableFunc("DeviceStrictClangGlobalCflags", func(ctx android.PackageVarContext) string {
if ctx.Config().Fuchsia() {
return strings.Join(ClangFilterUnknownCflags(strictdeviceGlobalCflags), " ")
} else {
return strings.Join(append(ClangFilterUnknownCflags(strictdeviceGlobalCflags), "${ClangExtraTargetCflags}"), " ")
}
})
pctx.StaticVariable("HostStrictClangGlobalCflags",
strings.Join(ClangFilterUnknownCflags(stricthostGlobalCflags), " "))
}
func RemovePrefixFromList(Prefix string, list []string) (remainder []string, filtered []string) {
for _, l := range list {
if strings.HasPrefix(l, Prefix) {
filtered = append(filtered, l)
} else {
remainder = append(remainder, l)
}
}
return
}
func IndexList(s string, list []string) int {
for i, l := range list {
if l == s {
return i
}
}
return -1
}
func RemoveFromList(s string, list []string) (bool, []string) {
i := IndexList(s, list)
if i == -1 {
return false, list
}
result := make([]string, 0, len(list)-1)
result = append(result, list[:i]...)
for _, l := range list[i+1:] {
if l != s {
result = append(result, l)
}
}
return true, result
}