From 1b4934a215b382a504ede752032899212d32384d Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Thu, 14 Jan 2021 15:45:25 -0800 Subject: [PATCH] WITH_TIDY=1 implies -warnings-as-errors=-* * This allows local projects to enable clang-tidy and catch errors in a default build, but allows all warnings in a global build with WITH_TIDY=1. Test: make with WITH_TIDY=1 Change-Id: I92a10af24b23ee9f04eebb0513e8f611dd7dcf59 --- cc/tidy.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/cc/tidy.go b/cc/tidy.go index 17471e674..972ad7bc7 100644 --- a/cc/tidy.go +++ b/cc/tidy.go @@ -15,6 +15,7 @@ package cc import ( + "regexp" "strings" "github.com/google/blueprint/proptools" @@ -130,7 +131,31 @@ func (tidy *tidyFeature) flags(ctx ModuleContext, flags Flags) Flags { tidyChecks = tidyChecks + ",-bugprone-branch-clone" flags.TidyFlags = append(flags.TidyFlags, tidyChecks) - if len(tidy.Properties.Tidy_checks_as_errors) > 0 { + 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 + } + } + if !inserted { + flags.TidyFlags = append(flags.TidyFlags, "-warnings-as-errors=-*") + } + } else if len(tidy.Properties.Tidy_checks_as_errors) > 0 { tidyChecksAsErrors := "-warnings-as-errors=" + strings.Join(esc(tidy.Properties.Tidy_checks_as_errors), ",") flags.TidyFlags = append(flags.TidyFlags, tidyChecksAsErrors) }