Use WITH_TIDY_FLAGS env variable.

This variable is a space separated string of clang-tidy flags to be passed
to clang-tidy before any other system required extra flags.
Note that when this flag or local tidy_flags is defined,
the default -header-filter flag is suppressed.

Test: make with WITH_TIDY=1 WITH_TIDY_FLAGS="-extra-arg=-DABCD1=1 -extra-arg=-DABCD2=2"
Bug: 32668284
Change-Id: If7bd31c65404ef7fe6c3499d51f0f209a704efd9
This commit is contained in:
Chih-Hung Hsieh 2018-09-21 15:12:44 -07:00
parent 60bd4bf079
commit 9e5d8a60e2
3 changed files with 12 additions and 1 deletions

View file

@ -80,6 +80,11 @@ func init() {
"system/",
}, "|")
})
// Use WTIH_TIDY_FLAGS to pass extra global default clang-tidy flags.
pctx.VariableFunc("TidyWithTidyFlags", func(ctx android.PackageVarContext) string {
return ctx.Config().Getenv("WITH_TIDY_FLAGS")
})
}
type PathBasedTidyCheck struct {

View file

@ -143,6 +143,7 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
ctx.Strict("DEFAULT_GLOBAL_TIDY_CHECKS", "${config.TidyDefaultGlobalChecks}")
ctx.Strict("DEFAULT_LOCAL_TIDY_CHECKS", joinLocalTidyChecks(config.DefaultLocalTidyChecks))
ctx.Strict("DEFAULT_TIDY_HEADER_DIRS", "${config.TidyDefaultHeaderDirs}")
ctx.Strict("WITH_TIDY_FLAGS", "${config.TidyWithTidyFlags}")
ctx.Strict("AIDL_CPP", "${aidlCmd}")

View file

@ -69,9 +69,14 @@ func (tidy *tidyFeature) flags(ctx ModuleContext, flags Flags) Flags {
flags.Tidy = true
// Add global WITH_TIDY_FLAGS and local tidy_flags.
withTidyFlags := ctx.Config().Getenv("WITH_TIDY_FLAGS")
if len(withTidyFlags) > 0 {
flags.TidyFlags = append(flags.TidyFlags, withTidyFlags)
}
esc := proptools.NinjaAndShellEscape
flags.TidyFlags = append(flags.TidyFlags, esc(tidy.Properties.Tidy_flags)...)
// If TidyFlags is empty, add default header filter.
if len(flags.TidyFlags) == 0 {
headerFilter := "-header-filter=\"(" + ctx.ModuleDir() + "|${config.TidyDefaultHeaderDirs})\""
flags.TidyFlags = append(flags.TidyFlags, headerFilter)