diff options
author | Pirama Arumuga Nainar <pirama@google.com> | 2020-06-01 15:09:18 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-06-11 02:02:40 +0000 |
commit | ad5bd3e097f1d6ef592bdbc5ee041ad896b6b9aa (patch) | |
tree | a9ee8642e087719d18dde9a9babce165a6c1169d /compiler_wrapper/disable_werror_flag_test.go | |
parent | deff1db299a82e7f1dd480ccf5844d4afa485916 (diff) | |
download | toolchain-utils-ad5bd3e097f1d6ef592bdbc5ee041ad896b6b9aa.tar.gz |
[compiler-wrapper] Handle double build for clang-tidy
For clang-tidy, the equivalent of -Werror is --warnings-as-errors (or
-warnings-as-errors). The error message will also have
"warnings-as-errors". So,
1. Trigger double-build if "warnings-as-errors" is in *stdout*.
Clang-tidy will also fail if clang issues a Werror diagnostic. In this
case, we'd get "clang-diagnostic" in stdout. Do a re-build in both
these cases.
2. Remove flags containing "-warnings-as-errors" in the rerun. Unlike
-Werror/Wno-error, clang-tidy doesn't have a -no-warnings-as-errors to
override a prior -warnings-as-errors. Existing double-build processing
will disable -Werror flags to Clang.
Originally reviewed at
https://android-review.googlesource.com/c/platform/external/toolchain-utils/+/1322200.
BUG=None
TEST=go test
Change-Id: I18de245972da81e0ac3600f9098b71cec82e9e96
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2239370
Commit-Queue: Pirama Arumuga Nainar <pirama@google.com>
Tested-by: Pirama Arumuga Nainar <pirama@google.com>
Reviewed-by: George Burgess <gbiv@chromium.org>
Diffstat (limited to 'compiler_wrapper/disable_werror_flag_test.go')
-rw-r--r-- | compiler_wrapper/disable_werror_flag_test.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/compiler_wrapper/disable_werror_flag_test.go b/compiler_wrapper/disable_werror_flag_test.go index 53b0fb52..28e48371 100644 --- a/compiler_wrapper/disable_werror_flag_test.go +++ b/compiler_wrapper/disable_werror_flag_test.go @@ -449,3 +449,72 @@ func TestChromeOSGetNewWarningsDirOff(t *testing.T) { } }) } + +func TestClangTidyNoDoubleBuild(t *testing.T) { + withTestContext(t, func(ctx *testContext) { + ctx.cfg.isAndroidWrapper = true + ctx.cfg.useLlvmNext = true + ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(clangTidyAndroid, "--", mainCc))) + if ctx.cmdCount != 1 { + t.Errorf("expected 1 call. Got: %d", ctx.cmdCount) + } + }) +} + +func withAndroidClangTidyTestContext(t *testing.T, work func(ctx *testContext)) { + withTestContext(t, func(ctx *testContext) { + ctx.cfg.isAndroidWrapper = true + ctx.cfg.useLlvmNext = true + ctx.env = []string{"OUT_DIR=/tmp"} + + ctx.cmdMock = func(cmd *command, stdin io.Reader, stdout io.Writer, stderr io.Writer) error { + hasArg := func(s string) bool { + for _, e := range cmd.Args { + if strings.Contains(e, s) { + return true + } + } + return false + } + switch ctx.cmdCount { + case 1: + if hasArg("-Werror") { + fmt.Fprint(stdout, "clang-diagnostic-") + return newExitCodeError(1) + } + if hasArg("-warnings-as-errors") { + fmt.Fprint(stdout, "warnings-as-errors") + return newExitCodeError(1) + } + return nil + case 2: + if hasArg("warnings-as-errors") { + return fmt.Errorf("Unexpected arg warnings-as-errors found. All args: %s", cmd.Args) + } + return nil + default: + t.Fatalf("unexpected command: %#v", cmd) + return nil + } + } + work(ctx) + }) +} + +func TestClangTidyDoubleBuildClangTidyError(t *testing.T) { + withAndroidClangTidyTestContext(t, func(ctx *testContext) { + ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(clangTidyAndroid, "-warnings-as-errors=*", "--", mainCc))) + if ctx.cmdCount != 2 { + t.Errorf("expected 2 calls. Got: %d", ctx.cmdCount) + } + }) +} + +func TestClangTidyDoubleBuildClangError(t *testing.T) { + withAndroidClangTidyTestContext(t, func(ctx *testContext) { + ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(clangTidyAndroid, "-Werrors=*", "--", mainCc))) + if ctx.cmdCount != 2 { + t.Errorf("expected 2 calls. Got: %d", ctx.cmdCount) + } + }) +} |