Don't register linkstamp compile actions when we're doing thinlto indexing step

RELNOTES: None.
PiperOrigin-RevId: 186456188
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java
index 2519f30..0fce270 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java
@@ -1004,29 +1004,32 @@
 
     LinkCommandLine linkCommandLine = linkCommandLineBuilder.build();
 
-    for (Entry<Linkstamp, Artifact> linkstampEntry : linkstampMap.entrySet()) {
-      analysisEnvironment.registerAction(
-          CppLinkstampCompileHelper.createLinkstampCompileAction(
-              ruleContext,
-              linkstampEntry.getKey().getArtifact(),
-              linkstampEntry.getValue(),
-              linkstampEntry.getKey().getDeclaredIncludeSrcs(),
-              ImmutableSet.copyOf(nonCodeInputs),
-              buildInfoHeaderArtifacts,
-              additionalLinkstampDefines,
-              toolchain,
-              configuration.isCodeCoverageEnabled(),
-              cppConfiguration,
-              CppHelper.getFdoBuildStamp(ruleContext, fdoSupport.getFdoSupport()),
-              featureConfiguration,
-              cppConfiguration.forcePic()
-                  || (linkType == LinkTargetType.DYNAMIC_LIBRARY && toolchain.toolchainNeedsPic()),
-              Matcher.quoteReplacement(
-                  isNativeDeps && cppConfiguration.shareNativeDeps()
-                      ? output.getExecPathString()
-                      : Label.print(getOwner().getLabel())),
-              Matcher.quoteReplacement(output.getExecPathString()),
-              cppSemantics));
+    if (!isLtoIndexing) {
+      for (Entry<Linkstamp, Artifact> linkstampEntry : linkstampMap.entrySet()) {
+        analysisEnvironment.registerAction(
+            CppLinkstampCompileHelper.createLinkstampCompileAction(
+                ruleContext,
+                linkstampEntry.getKey().getArtifact(),
+                linkstampEntry.getValue(),
+                linkstampEntry.getKey().getDeclaredIncludeSrcs(),
+                ImmutableSet.copyOf(nonCodeInputs),
+                buildInfoHeaderArtifacts,
+                additionalLinkstampDefines,
+                toolchain,
+                configuration.isCodeCoverageEnabled(),
+                cppConfiguration,
+                CppHelper.getFdoBuildStamp(ruleContext, fdoSupport.getFdoSupport()),
+                featureConfiguration,
+                cppConfiguration.forcePic()
+                    || (linkType == LinkTargetType.DYNAMIC_LIBRARY
+                        && toolchain.toolchainNeedsPic()),
+                Matcher.quoteReplacement(
+                    isNativeDeps && cppConfiguration.shareNativeDeps()
+                        ? output.getExecPathString()
+                        : Label.print(getOwner().getLabel())),
+                Matcher.quoteReplacement(output.getExecPathString()),
+                cppSemantics));
+      }
     }
 
     // Compute the set of inputs - we only need stable order here.