compiler_wrapper: refactor goma => "remote compile"

This is intended to be no functional change. In most places, we use
"goma" as a way of saying "remote compilation;" this CL clarifies which
is which.

BUG=b:190741226
TEST=go test

Change-Id: Ia03c1a05486c907cd6f7bc33b59a56c98db5d527
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2956695
Reviewed-by: Ryan Beltran <ryanbeltran@chromium.org>
Tested-by: George Burgess <gbiv@chromium.org>
diff --git a/compiler_wrapper/compiler_wrapper.go b/compiler_wrapper/compiler_wrapper.go
index 9d7b76e..ebc1c42 100644
--- a/compiler_wrapper/compiler_wrapper.go
+++ b/compiler_wrapper/compiler_wrapper.go
@@ -81,7 +81,7 @@
 	// Disable CCache for rusage logs
 	// Note: Disabling Goma causes timeout related INFRA_FAILUREs in builders
 	allowCCache := !rusageEnabled
-	gomaUsed := false
+	remoteBuildUsed := false
 
 	workAroundKernelBugWithRetries := false
 	if cfg.isAndroidWrapper {
@@ -91,7 +91,8 @@
 			mainBuilder.addPreUserArgs(mainBuilder.cfg.clangFlags...)
 			mainBuilder.addPreUserArgs(mainBuilder.cfg.commonFlags...)
 			mainBuilder.addPostUserArgs(mainBuilder.cfg.clangPostFlags...)
-			if gomaUsed, err = processGomaCccFlags(mainBuilder); err != nil {
+			// Android doesn't support rewrapper; don't try to use it.
+			if remoteBuildUsed, err = processGomaCccFlags(mainBuilder); err != nil {
 				return 0, err
 			}
 			compilerCmd = mainBuilder.build()
@@ -109,16 +110,16 @@
 			}
 			if tidyMode != tidyModeNone {
 				allowCCache = false
-				clangCmdWithoutGomaAndCCache := mainBuilder.build()
+				clangCmdWithoutRemoteBuildAndCCache := mainBuilder.build()
 				var err error
 				switch tidyMode {
 				case tidyModeTricium:
 					if cfg.triciumNitsDir == "" {
 						return 0, newErrorwithSourceLocf("tricium linting was requested, but no nits directory is configured")
 					}
-					err = runClangTidyForTricium(env, clangCmdWithoutGomaAndCCache, cSrcFile, cfg.triciumNitsDir, tidyFlags, cfg.crashArtifactsDir)
+					err = runClangTidyForTricium(env, clangCmdWithoutRemoteBuildAndCCache, cSrcFile, cfg.triciumNitsDir, tidyFlags, cfg.crashArtifactsDir)
 				case tidyModeAll:
-					err = runClangTidy(env, clangCmdWithoutGomaAndCCache, cSrcFile, tidyFlags)
+					err = runClangTidy(env, clangCmdWithoutRemoteBuildAndCCache, cSrcFile, tidyFlags)
 				default:
 					panic(fmt.Sprintf("Unknown tidy mode: %v", tidyMode))
 				}
@@ -127,7 +128,7 @@
 					return 0, err
 				}
 			}
-			if gomaUsed, err = processGomaCCacheFlags(allowCCache, mainBuilder); err != nil {
+			if remoteBuildUsed, err = processRemoteBuildAndCCacheFlags(allowCCache, mainBuilder); err != nil {
 				return 0, err
 			}
 			compilerCmd = mainBuilder.build()
@@ -144,7 +145,7 @@
 				}
 				return checkClangSyntax(env, clangCmd, gccCmd)
 			}
-			gomaUsed, compilerCmd, err = calcGccCommand(rusageEnabled, mainBuilder)
+			remoteBuildUsed, compilerCmd, err = calcGccCommand(rusageEnabled, mainBuilder)
 			if err != nil {
 				return 0, err
 			}
@@ -245,7 +246,7 @@
 		case err != nil:
 			return exitCode, err
 		default:
-			if !gomaUsed {
+			if !remoteBuildUsed {
 				if err := commitRusage(exitCode); err != nil {
 					return exitCode, fmt.Errorf("commiting rusage: %v", err)
 				}
@@ -273,11 +274,11 @@
 	if err != nil {
 		return false, nil, err
 	}
-	gomaUsed, err := processGomaCCacheFlags(allowCCache, builder)
+	remoteBuildUsed, err := processRemoteBuildAndCCacheFlags(allowCCache, builder)
 	if err != nil {
-		return gomaUsed, nil, err
+		return remoteBuildUsed, nil, err
 	}
-	return gomaUsed, builder.build(), nil
+	return remoteBuildUsed, builder.build(), nil
 }
 
 func calcGccCommand(enableRusage bool, builder *commandBuilder) (bool, *command, error) {
@@ -288,14 +289,14 @@
 	calcCommonPreUserArgs(builder)
 	processGccFlags(builder)
 
-	gomaUsed := false
+	remoteBuildUsed := false
 	if !builder.cfg.isHostWrapper {
 		var err error
-		if gomaUsed, err = processGomaCCacheFlags(!enableRusage, builder); err != nil {
-			return gomaUsed, nil, err
+		if remoteBuildUsed, err = processRemoteBuildAndCCacheFlags(!enableRusage, builder); err != nil {
+			return remoteBuildUsed, nil, err
 		}
 	}
-	return gomaUsed, builder.build(), nil
+	return remoteBuildUsed, builder.build(), nil
 }
 
 func calcCommonPreUserArgs(builder *commandBuilder) {
@@ -309,19 +310,18 @@
 	processSanitizerFlags(builder)
 }
 
-func processGomaCCacheFlags(allowCCache bool, builder *commandBuilder) (gomaccUsed bool, err error) {
-
-	gomaccUsed = false
+func processRemoteBuildAndCCacheFlags(allowCCache bool, builder *commandBuilder) (remoteBuildUsed bool, err error) {
+	remoteBuildUsed = false
 	if !builder.cfg.isHostWrapper {
-		gomaccUsed, err = processGomaCccFlags(builder)
+		remoteBuildUsed, err = processRemoteBuildFlags(builder)
 		if err != nil {
-			return gomaccUsed, err
+			return remoteBuildUsed, err
 		}
 	}
-	if !gomaccUsed && allowCCache {
+	if !remoteBuildUsed && allowCCache {
 		processCCacheFlag(builder)
 	}
-	return gomaccUsed, nil
+	return remoteBuildUsed, nil
 }
 
 func getAbsWrapperPath(env env, wrapperCmd *command) (string, error) {
diff --git a/compiler_wrapper/gomacc_flag_test.go b/compiler_wrapper/remote_build_flag_test.go
similarity index 100%
rename from compiler_wrapper/gomacc_flag_test.go
rename to compiler_wrapper/remote_build_flag_test.go
diff --git a/compiler_wrapper/gomacc_flag.go b/compiler_wrapper/remote_build_flags.go
similarity index 80%
rename from compiler_wrapper/gomacc_flag.go
rename to compiler_wrapper/remote_build_flags.go
index 56522d4..fa70cbc 100644
--- a/compiler_wrapper/gomacc_flag.go
+++ b/compiler_wrapper/remote_build_flags.go
@@ -111,3 +111,26 @@
 	}
 	return false, nil
 }
+
+func processRewrapperCcFlags(builder *commandBuilder) (rewrapperUsed bool, err error) {
+	// FIXME(gbiv): Add parsing and such for this.
+	return false, nil
+}
+
+func processRemoteBuildFlags(builder *commandBuilder) (remoteBuildUsed bool, err error) {
+	rewrapperUsed, err := processRewrapperCcFlags(builder)
+	if err != nil {
+		return rewrapperUsed, err
+	}
+
+	gomaUsed, err := processGomaCccFlags(builder)
+	remoteBuildUsed = gomaUsed || rewrapperUsed
+	if err != nil {
+		return remoteBuildUsed, err
+	}
+
+	if gomaUsed && rewrapperUsed {
+		return true, newUserErrorf("rewrapper and gomacc are mutually exclusive")
+	}
+	return remoteBuildUsed, nil
+}