Remove buildInfoHeaderArtifacts from LinkCommandLine

They had no place there, because "build info" is only used in CppCompileAction (any  header artifacts can't appear on link command line or are used during linking).

The value was used in a couple of tests and previously removed CppLinkInfo structure.

PiperOrigin-RevId: 594396045
Change-Id: I6d6688302e3b6323df045858612aa68a4347cf10
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java
index 60b3849..d90635c 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java
@@ -375,11 +375,6 @@
     }
   }
 
-  /** Returns the (ordered, immutable) list of header files that contain build info. */
-  public ImmutableList<Artifact> getBuildInfoHeaderArtifacts() {
-    return linkCommandLine.getBuildInfoHeaderArtifacts();
-  }
-
   @Override
   protected void computeKey(
       ActionKeyContext actionKeyContext,
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 e2987a1..08188fa 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
@@ -915,10 +915,6 @@
           toolchain.getLinkDynamicLibraryTool().getExecPathString());
     }
 
-    if (!isLtoIndexing) {
-      linkCommandLineBuilder.setBuildInfoHeaderArtifacts(buildInfoHeaderArtifacts);
-    }
-
     linkCommandLineBuilder.setBuildVariables(buildVariables);
     LinkCommandLine linkCommandLine = linkCommandLineBuilder.build();
 
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java
index bfba8a4..f81a350 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java
@@ -49,7 +49,6 @@
   private final CcToolchainVariables variables;
   // The feature config can be null for tests.
   @Nullable private final FeatureConfiguration featureConfiguration;
-  private final ImmutableList<Artifact> buildInfoHeaderArtifacts;
   private final NestedSet<Artifact> linkerInputArtifacts;
   private final LinkTargetType linkTargetType;
   private final Link.LinkingMode linkingMode;
@@ -62,7 +61,6 @@
   private LinkCommandLine(
       String actionName,
       String forcedToolPath,
-      ImmutableList<Artifact> buildInfoHeaderArtifacts,
       NestedSet<Artifact> linkerInputArtifacts,
       LinkTargetType linkTargetType,
       Link.LinkingMode linkingMode,
@@ -77,7 +75,6 @@
     this.forcedToolPath = forcedToolPath;
     this.variables = variables;
     this.featureConfiguration = featureConfiguration;
-    this.buildInfoHeaderArtifacts = Preconditions.checkNotNull(buildInfoHeaderArtifacts);
     this.linkerInputArtifacts = Preconditions.checkNotNull(linkerInputArtifacts);
     this.linkTargetType = Preconditions.checkNotNull(linkTargetType);
     this.linkingMode = Preconditions.checkNotNull(linkingMode);
@@ -92,11 +89,6 @@
     return paramFile;
   }
 
-  /** See {@link CppLinkAction#getBuildInfoHeaderArtifacts()} */
-  public ImmutableList<Artifact> getBuildInfoHeaderArtifacts() {
-    return buildInfoHeaderArtifacts;
-  }
-
   /** Returns the (ordered, immutable) list of paths to the linker's input files. */
   public NestedSet<Artifact> getLinkerInputArtifacts() {
     return linkerInputArtifacts;
@@ -386,7 +378,6 @@
   public static final class Builder {
 
     private String forcedToolPath;
-    private ImmutableList<Artifact> buildInfoHeaderArtifacts = ImmutableList.of();
     private NestedSet<Artifact> linkerInputArtifacts =
         NestedSetBuilder.emptySet(Order.STABLE_ORDER);
     @Nullable private LinkTargetType linkTargetType;
@@ -400,12 +391,6 @@
     private String actionName;
 
     public LinkCommandLine build() {
-      if (linkTargetType.linkerOrArchiver() == LinkerOrArchiver.ARCHIVER) {
-        Preconditions.checkArgument(
-            buildInfoHeaderArtifacts.isEmpty(),
-            "build info headers may only be present on dynamic library or executable links");
-      }
-
       if (variables == null) {
         variables = CcToolchainVariables.EMPTY;
       }
@@ -413,7 +398,6 @@
       return new LinkCommandLine(
           actionName,
           forcedToolPath,
-          buildInfoHeaderArtifacts,
           linkerInputArtifacts,
           linkTargetType,
           linkingMode,
@@ -475,17 +459,6 @@
     }
 
     /**
-     * The build info header artifacts are generated header files that are used for link stamping.
-     * The {@link #build} method throws an exception if the build info header artifacts are
-     * non-empty for a static link (see {@link LinkTargetType#linkerOrArchiver()}}).
-     */
-    @CanIgnoreReturnValue
-    public Builder setBuildInfoHeaderArtifacts(ImmutableList<Artifact> buildInfoHeaderArtifacts) {
-      this.buildInfoHeaderArtifacts = buildInfoHeaderArtifacts;
-      return this;
-    }
-
-    /**
      * Whether the resulting library is intended to be used as a native library from another
      * programming language. This influences the rpath. The {@link #build} method throws an
      * exception if this is true for a static link (see {@link LinkTargetType#linkerOrArchiver()}}).
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLineTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLineTest.java
index a62c0ce..67ccd52 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLineTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLineTest.java
@@ -15,7 +15,6 @@
 package com.google.devtools.build.lib.rules.cpp;
 
 import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.assertThrows;
 
 import com.google.common.base.Joiner;
 import com.google.common.collect.ImmutableList;
@@ -137,22 +136,6 @@
     return minimalConfiguration(getMockBuildVariables());
   }
 
-  private void assertError(String expectedSubstring, LinkCommandLine.Builder builder) {
-    RuntimeException e = assertThrows(RuntimeException.class, () -> builder.build());
-    assertThat(e).hasMessageThat().contains(expectedSubstring);
-  }
-
-  @Test
-  public void testStaticLinkWithBuildInfoHeadersIsError() throws Exception {
-    assertError(
-        "build info headers may only be present",
-        minimalConfiguration()
-            .setLinkTargetType(LinkTargetType.STATIC_LIBRARY)
-            .setLinkingMode(LinkingMode.STATIC)
-            .setBuildInfoHeaderArtifacts(
-                ImmutableList.of(scratchArtifact("FakeBuildInfoHeaderArtifact1"))));
-  }
-
   /**
    * Tests that when linking without linkstamps, the exec command is the same as the link command.
    */