Disallow -warnings-as-errors in tidy_flags

* Also remove the undocumented complicated
  experiment to overwrite local warnings-as-errors.

Bug: 229801437
Test: WITH_TIDY=1 make; make tidy-soong_subset
Change-Id: I2fb32146b4685ab9f5198724c15c303f799b7a14
This commit is contained in:
Chih-Hung Hsieh
2022-04-28 15:56:08 -07:00
parent 2320e27eb1
commit 2d481842b1
2 changed files with 77 additions and 24 deletions

View File

@@ -188,31 +188,14 @@ func (tidy *tidyFeature) flags(ctx ModuleContext, flags Flags) Flags {
tidyChecks = tidyChecks + ",-cert-err33-c"
flags.TidyFlags = append(flags.TidyFlags, tidyChecks)
if ctx.Config().IsEnvTrue("WITH_TIDY") {
// WITH_TIDY=1 enables clang-tidy globally. There could be many unexpected
// warnings from new checks and many local tidy_checks_as_errors and
// -warnings-as-errors can break a global build.
// So allow all clang-tidy warnings.
inserted := false
for i, s := range flags.TidyFlags {
if strings.Contains(s, "-warnings-as-errors=") {
// clang-tidy accepts only one -warnings-as-errors
// replace the old one
re := regexp.MustCompile(`'?-?-warnings-as-errors=[^ ]* *`)
newFlag := re.ReplaceAllString(s, "")
if newFlag == "" {
flags.TidyFlags[i] = "-warnings-as-errors=-*"
} else {
flags.TidyFlags[i] = newFlag + " -warnings-as-errors=-*"
}
inserted = true
break
}
// Embedding -warnings-as-errors in tidy_flags is error-prone.
// It should be replaced with the tidy_checks_as_errors list.
for _, s := range flags.TidyFlags {
if strings.Contains(s, "-warnings-as-errors=") {
ctx.PropertyErrorf("tidy_flags", "should not contain -warnings-as-errors, use tidy_checks_as_errors instead")
}
if !inserted {
flags.TidyFlags = append(flags.TidyFlags, "-warnings-as-errors=-*")
}
} else if len(tidy.Properties.Tidy_checks_as_errors) > 0 {
}
if len(tidy.Properties.Tidy_checks_as_errors) > 0 {
tidyChecksAsErrors := "-warnings-as-errors=" + strings.Join(esc(ctx, "tidy_checks_as_errors", tidy.Properties.Tidy_checks_as_errors), ",")
flags.TidyFlags = append(flags.TidyFlags, tidyChecksAsErrors)
}