compiler_wrapper: disable force-disable-werror with GCC

Enabling this functionality with GCC is pointless -- we don't roll it,
so we don't want to catch new -Werrors with it. We're having some
GCC-specific functionality coming in soon; disabling this simplifies
things some.

BUG=chromium:1166017
TEST=CQ

Change-Id: I3f73a8124ea85a2f14fd5c909a9bbed2b46f28f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2648431
Reviewed-by: Manoj Gupta <[email protected]>
Tested-by: George Burgess <[email protected]>
diff --git a/compiler_wrapper/compiler_wrapper.go b/compiler_wrapper/compiler_wrapper.go
index f47b09c..21a308b 100644
--- a/compiler_wrapper/compiler_wrapper.go
+++ b/compiler_wrapper/compiler_wrapper.go
@@ -149,7 +149,7 @@
 		compilerCmd = removeRusageFromCommand(compilerCmd)
 	}
 
-	if shouldForceDisableWerror(env, cfg) {
+	if shouldForceDisableWerror(env, cfg, mainBuilder.target.compilerType) {
 		if bisectStage != "" {
 			return 0, newUserErrorf("BISECT_STAGE is meaningless with FORCE_DISABLE_WERROR")
 		}
diff --git a/compiler_wrapper/compiler_wrapper_test.go b/compiler_wrapper/compiler_wrapper_test.go
index 680312f..dc2a9dd 100644
--- a/compiler_wrapper/compiler_wrapper_test.go
+++ b/compiler_wrapper/compiler_wrapper_test.go
@@ -115,7 +115,7 @@
 				return nil
 			}
 		}
-		ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, mainCc)))
+		ctx.must(callCompiler(ctx, ctx.cfg, ctx.newCommand(clangX86_64, mainCc)))
 		if _, err := os.Stat(logFileName); os.IsNotExist(err) {
 			t.Errorf("no logfile created at TOOLCHAIN_RUSAGE_OUTPUT path %q", logFileName)
 		} else if err != nil {
@@ -146,7 +146,7 @@
 			"BISECT_STAGE=xyz",
 			"FORCE_DISABLE_WERROR=1",
 		}
-		stderr := ctx.mustFail(callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, mainCc)))
+		stderr := ctx.mustFail(callCompiler(ctx, ctx.cfg, ctx.newCommand(clangX86_64, mainCc)))
 		if err := verifyNonInternalError(stderr, "BISECT_STAGE is meaningless with FORCE_DISABLE_WERROR"); err != nil {
 			t.Error(err)
 		}
diff --git a/compiler_wrapper/disable_werror_flag.go b/compiler_wrapper/disable_werror_flag.go
index 3974dcb..9bbf2e2 100644
--- a/compiler_wrapper/disable_werror_flag.go
+++ b/compiler_wrapper/disable_werror_flag.go
@@ -19,10 +19,15 @@
 
 const numWErrorEstimate = 30
 
-func shouldForceDisableWerror(env env, cfg *config) bool {
+func shouldForceDisableWerror(env env, cfg *config, ty compilerType) bool {
 	if cfg.isAndroidWrapper {
 		return cfg.useLlvmNext
 	}
+
+	// We only want this functionality for clang.
+	if ty != clangType {
+		return false
+	}
 	value, _ := env.getenv("FORCE_DISABLE_WERROR")
 	return value != ""
 }
diff --git a/compiler_wrapper/disable_werror_flag_test.go b/compiler_wrapper/disable_werror_flag_test.go
index 0c43dbe..d005426 100644
--- a/compiler_wrapper/disable_werror_flag_test.go
+++ b/compiler_wrapper/disable_werror_flag_test.go
@@ -412,13 +412,21 @@
 
 		// Disable werror ON
 		ctx.cfg.useLlvmNext = true
-		if !shouldForceDisableWerror(ctx, ctx.cfg) {
+		if !shouldForceDisableWerror(ctx, ctx.cfg, gccType) {
+			t.Errorf("disable Werror not enabled for Android with useLlvmNext")
+		}
+
+		if !shouldForceDisableWerror(ctx, ctx.cfg, clangType) {
 			t.Errorf("disable Werror not enabled for Android with useLlvmNext")
 		}
 
 		// Disable werror OFF
 		ctx.cfg.useLlvmNext = false
-		if shouldForceDisableWerror(ctx, ctx.cfg) {
+		if shouldForceDisableWerror(ctx, ctx.cfg, gccType) {
+			t.Errorf("disable-Werror enabled for Android without useLlvmNext")
+		}
+
+		if shouldForceDisableWerror(ctx, ctx.cfg, clangType) {
 			t.Errorf("disable-Werror enabled for Android without useLlvmNext")
 		}
 	})
@@ -426,9 +434,25 @@
 
 func TestChromeOSNoForceDisableWerror(t *testing.T) {
 	withTestContext(t, func(ctx *testContext) {
-		if shouldForceDisableWerror(ctx, ctx.cfg) {
+		if shouldForceDisableWerror(ctx, ctx.cfg, gccType) {
 			t.Errorf("disable Werror enabled for ChromeOS without FORCE_DISABLE_WERROR set")
 		}
+
+		if shouldForceDisableWerror(ctx, ctx.cfg, clangType) {
+			t.Errorf("disable Werror enabled for ChromeOS without FORCE_DISABLE_WERROR set")
+		}
+	})
+}
+
+func TestChromeOSForceDisableWerrorOnlyAppliesToClang(t *testing.T) {
+	withForceDisableWErrorTestContext(t, func(ctx *testContext) {
+		if !shouldForceDisableWerror(ctx, ctx.cfg, clangType) {
+			t.Errorf("Disable -Werror should be enabled for clang.")
+		}
+
+		if shouldForceDisableWerror(ctx, ctx.cfg, gccType) {
+			t.Errorf("Disable -Werror should be disabled for gcc.")
+		}
 	})
 }