export clang-tidy variables to soong_injection
Change-Id: If6470c35f5ee8f4867177d641640cdc2806de574
This commit is contained in:
@@ -69,6 +69,7 @@ func (ev ExportedVariables) asBazel(config Config,
|
|||||||
ret = append(ret, ev.exportedStringListDictVars.asBazel(config, stringVars, stringListVars, cfgDepVars)...)
|
ret = append(ret, ev.exportedStringListDictVars.asBazel(config, stringVars, stringListVars, cfgDepVars)...)
|
||||||
// Note: ExportedVariableReferenceDictVars collections can only contain references to other variables and must be printed last
|
// Note: ExportedVariableReferenceDictVars collections can only contain references to other variables and must be printed last
|
||||||
ret = append(ret, ev.exportedVariableReferenceDictVars.asBazel(config, stringVars, stringListVars, cfgDepVars)...)
|
ret = append(ret, ev.exportedVariableReferenceDictVars.asBazel(config, stringVars, stringListVars, cfgDepVars)...)
|
||||||
|
ret = append(ret, ev.exportedConfigDependingVars.asBazel(config, stringVars, stringListVars, cfgDepVars)...)
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,6 +142,33 @@ func (m ExportedConfigDependingVariables) set(k string, v interface{}) {
|
|||||||
m[k] = v
|
m[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m ExportedConfigDependingVariables) asBazel(config Config,
|
||||||
|
stringVars ExportedStringVariables, stringListVars ExportedStringListVariables, cfgDepVars ExportedConfigDependingVariables) []bazelConstant {
|
||||||
|
ret := make([]bazelConstant, 0, len(m))
|
||||||
|
for variable, unevaluatedVar := range m {
|
||||||
|
evalFunc := reflect.ValueOf(unevaluatedVar)
|
||||||
|
validateVariableMethod(variable, evalFunc)
|
||||||
|
evaluatedResult := evalFunc.Call([]reflect.Value{reflect.ValueOf(config)})
|
||||||
|
evaluatedValue := evaluatedResult[0].Interface().(string)
|
||||||
|
expandedVars, err := expandVar(config, evaluatedValue, stringVars, stringListVars, cfgDepVars)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("error expanding config variable %s: %s", variable, err))
|
||||||
|
}
|
||||||
|
if len(expandedVars) > 1 {
|
||||||
|
ret = append(ret, bazelConstant{
|
||||||
|
variableName: variable,
|
||||||
|
internalDefinition: starlark_fmt.PrintStringList(expandedVars, 0),
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
ret = append(ret, bazelConstant{
|
||||||
|
variableName: variable,
|
||||||
|
internalDefinition: fmt.Sprintf(`"%s"`, validateCharacters(expandedVars[0])),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure that string s has no invalid characters to be generated into the bzl file.
|
// Ensure that string s has no invalid characters to be generated into the bzl file.
|
||||||
func validateCharacters(s string) string {
|
func validateCharacters(s string) string {
|
||||||
for _, c := range []string{`\n`, `"`, `\`} {
|
for _, c := range []string{`\n`, `"`, `\`} {
|
||||||
|
@@ -61,8 +61,8 @@ func init() {
|
|||||||
// The global default tidy checks should include clang-tidy
|
// The global default tidy checks should include clang-tidy
|
||||||
// default checks and tested groups, but exclude known noisy checks.
|
// default checks and tested groups, but exclude known noisy checks.
|
||||||
// See https://clang.llvm.org/extra/clang-tidy/checks/list.html
|
// See https://clang.llvm.org/extra/clang-tidy/checks/list.html
|
||||||
pctx.VariableFunc("TidyDefaultGlobalChecks", func(ctx android.PackageVarContext) string {
|
exportedVars.ExportVariableConfigMethod("TidyDefaultGlobalChecks", func(config android.Config) string {
|
||||||
if override := ctx.Config().Getenv("DEFAULT_GLOBAL_TIDY_CHECKS"); override != "" {
|
if override := config.Getenv("DEFAULT_GLOBAL_TIDY_CHECKS"); override != "" {
|
||||||
return override
|
return override
|
||||||
}
|
}
|
||||||
checks := strings.Join([]string{
|
checks := strings.Join([]string{
|
||||||
@@ -110,7 +110,7 @@ func init() {
|
|||||||
// limit clang-tidy runtime. We allow clang-tidy default clang-analyzer-* checks,
|
// limit clang-tidy runtime. We allow clang-tidy default clang-analyzer-* checks,
|
||||||
// and add it explicitly when CLANG_ANALYZER_CHECKS is set.
|
// and add it explicitly when CLANG_ANALYZER_CHECKS is set.
|
||||||
// The insecureAPI.DeprecatedOrUnsafeBufferHandling warning does not apply to Android.
|
// The insecureAPI.DeprecatedOrUnsafeBufferHandling warning does not apply to Android.
|
||||||
if ctx.Config().IsEnvTrue("CLANG_ANALYZER_CHECKS") {
|
if config.IsEnvTrue("CLANG_ANALYZER_CHECKS") {
|
||||||
checks += ",clang-analyzer-*,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling"
|
checks += ",clang-analyzer-*,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling"
|
||||||
} else {
|
} else {
|
||||||
checks += ",-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling"
|
checks += ",-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling"
|
||||||
@@ -123,8 +123,8 @@ func init() {
|
|||||||
// There are too many clang-tidy warnings in external and vendor projects, so we only
|
// There are too many clang-tidy warnings in external and vendor projects, so we only
|
||||||
// enable some google checks for these projects. Users can add more checks locally with the
|
// enable some google checks for these projects. Users can add more checks locally with the
|
||||||
// "tidy_checks" list in .bp files, or the "Checks" list in .clang-tidy config files.
|
// "tidy_checks" list in .bp files, or the "Checks" list in .clang-tidy config files.
|
||||||
pctx.VariableFunc("TidyExternalVendorChecks", func(ctx android.PackageVarContext) string {
|
exportedVars.ExportVariableConfigMethod("TidyExternalVendorChecks", func(config android.Config) string {
|
||||||
if override := ctx.Config().Getenv("DEFAULT_EXTERNAL_VENDOR_TIDY_CHECKS"); override != "" {
|
if override := config.Getenv("DEFAULT_EXTERNAL_VENDOR_TIDY_CHECKS"); override != "" {
|
||||||
return override
|
return override
|
||||||
}
|
}
|
||||||
return strings.Join([]string{
|
return strings.Join([]string{
|
||||||
@@ -137,24 +137,24 @@ func init() {
|
|||||||
}, ",")
|
}, ",")
|
||||||
})
|
})
|
||||||
|
|
||||||
pctx.VariableFunc("TidyGlobalNoChecks", func(ctx android.PackageVarContext) string {
|
exportedVars.ExportVariableFuncVariable("TidyGlobalNoChecks", func() string {
|
||||||
return strings.Join(globalNoCheckList, ",")
|
return strings.Join(globalNoCheckList, ",")
|
||||||
})
|
})
|
||||||
|
|
||||||
pctx.VariableFunc("TidyGlobalNoErrorChecks", func(ctx android.PackageVarContext) string {
|
exportedVars.ExportVariableFuncVariable("TidyGlobalNoErrorChecks", func() string {
|
||||||
return strings.Join(globalNoErrorCheckList, ",")
|
return strings.Join(globalNoErrorCheckList, ",")
|
||||||
})
|
})
|
||||||
|
|
||||||
// To reduce duplicate warnings from the same header files,
|
// To reduce duplicate warnings from the same header files,
|
||||||
// header-filter will contain only the module directory and
|
// header-filter will contain only the module directory and
|
||||||
// those specified by DEFAULT_TIDY_HEADER_DIRS.
|
// those specified by DEFAULT_TIDY_HEADER_DIRS.
|
||||||
pctx.VariableFunc("TidyDefaultHeaderDirs", func(ctx android.PackageVarContext) string {
|
exportedVars.ExportVariableConfigMethod("TidyDefaultHeaderDirs", func(config android.Config) string {
|
||||||
return ctx.Config().Getenv("DEFAULT_TIDY_HEADER_DIRS")
|
return config.Getenv("DEFAULT_TIDY_HEADER_DIRS")
|
||||||
})
|
})
|
||||||
|
|
||||||
// Use WTIH_TIDY_FLAGS to pass extra global default clang-tidy flags.
|
// Use WTIH_TIDY_FLAGS to pass extra global default clang-tidy flags.
|
||||||
pctx.VariableFunc("TidyWithTidyFlags", func(ctx android.PackageVarContext) string {
|
exportedVars.ExportVariableConfigMethod("TidyWithTidyFlags", func(config android.Config) string {
|
||||||
return ctx.Config().Getenv("WITH_TIDY_FLAGS")
|
return config.Getenv("WITH_TIDY_FLAGS")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user