Remove linkerInputArtifacts from LinkCommandLine

They value of linkerInputArtifacts was only used in tests.

Replace uses in tests with CppLinkCommand.getInputs(). The second method also returns path to linker and some scripts used during linker, so exact comparisons need to be replaced with containsAtLeast. It's more reliable on one hand (because actions can't lie about their inputs), and less reliable (because there could be some additional files on the path that are weren't there before). However, general intent of the tests is verifying that the files are present.

PiperOrigin-RevId: 594431021
Change-Id: I84cdda8d4bc50715ea3e412760bf8c713abd0353
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 d90635c..c6ab676 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
@@ -324,7 +324,7 @@
     ResourceSetOrBuilder localResources = new LinkResourceSetBuilder();
 
     try {
-      int inputsCount = linkCommandLine.getLinkerInputArtifacts().memoizedFlattenAndGetSize();
+      int inputsCount = getInputs().memoizedFlattenAndGetSize();
       ResourceSet resourceSet = localResources.buildResourceSet(OS.getCurrent(), inputsCount);
       Spawn spawn = createSpawn(actionExecutionContext, resourceSet);
       ImmutableList<SpawnResult> spawnResults =
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 08188fa..04734b3 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
@@ -893,11 +893,6 @@
     LinkCommandLine.Builder linkCommandLineBuilder =
         new LinkCommandLine.Builder()
             .setActionName(getActionName())
-            .setLinkerInputArtifacts(
-                NestedSetBuilder.<Artifact>stableOrder()
-                    .addTransitive(expandedLinkerArtifacts)
-                    .addTransitive(linkstampObjectArtifacts)
-                    .build())
             .setLinkTargetType(linkType)
             .setLinkingMode(linkingMode)
             .setToolchainLibrariesSolibDir(
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 f81a350..cd2b114 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
@@ -22,10 +22,6 @@
 import com.google.devtools.build.lib.actions.CommandLine;
 import com.google.devtools.build.lib.actions.CommandLineExpansionException;
 import com.google.devtools.build.lib.actions.PathMapper;
-import com.google.devtools.build.lib.collect.CollectionUtils;
-import com.google.devtools.build.lib.collect.nestedset.NestedSet;
-import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
-import com.google.devtools.build.lib.collect.nestedset.Order;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
 import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.ExpansionException;
 import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration;
@@ -49,7 +45,6 @@
   private final CcToolchainVariables variables;
   // The feature config can be null for tests.
   @Nullable private final FeatureConfiguration featureConfiguration;
-  private final NestedSet<Artifact> linkerInputArtifacts;
   private final LinkTargetType linkTargetType;
   private final Link.LinkingMode linkingMode;
   @Nullable private final PathFragment toolchainLibrariesSolibDir;
@@ -61,7 +56,6 @@
   private LinkCommandLine(
       String actionName,
       String forcedToolPath,
-      NestedSet<Artifact> linkerInputArtifacts,
       LinkTargetType linkTargetType,
       Link.LinkingMode linkingMode,
       @Nullable PathFragment toolchainLibrariesSolibDir,
@@ -75,7 +69,6 @@
     this.forcedToolPath = forcedToolPath;
     this.variables = variables;
     this.featureConfiguration = featureConfiguration;
-    this.linkerInputArtifacts = Preconditions.checkNotNull(linkerInputArtifacts);
     this.linkTargetType = Preconditions.checkNotNull(linkTargetType);
     this.linkingMode = Preconditions.checkNotNull(linkingMode);
     this.toolchainLibrariesSolibDir = toolchainLibrariesSolibDir;
@@ -89,11 +82,6 @@
     return paramFile;
   }
 
-  /** Returns the (ordered, immutable) list of paths to the linker's input files. */
-  public NestedSet<Artifact> getLinkerInputArtifacts() {
-    return linkerInputArtifacts;
-  }
-
   @Nullable
   @VisibleForTesting
   public FeatureConfiguration getFeatureConfiguration() {
@@ -378,8 +366,6 @@
   public static final class Builder {
 
     private String forcedToolPath;
-    private NestedSet<Artifact> linkerInputArtifacts =
-        NestedSetBuilder.emptySet(Order.STABLE_ORDER);
     @Nullable private LinkTargetType linkTargetType;
     private Link.LinkingMode linkingMode = Link.LinkingMode.STATIC;
     @Nullable private PathFragment toolchainLibrariesSolibDir;
@@ -398,7 +384,6 @@
       return new LinkCommandLine(
           actionName,
           forcedToolPath,
-          linkerInputArtifacts,
           linkTargetType,
           linkingMode,
           toolchainLibrariesSolibDir,
@@ -437,17 +422,6 @@
     }
 
     /**
-     * Sets a list of linker input artifacts. These get turned into linker options depending on the
-     * staticness and the target type. This call makes an immutable copy of the inputs, if the
-     * provided Iterable isn't already immutable (see {@link CollectionUtils#makeImmutable}).
-     */
-    @CanIgnoreReturnValue
-    public Builder setLinkerInputArtifacts(NestedSet<Artifact> linkerInputArtifacts) {
-      this.linkerInputArtifacts = linkerInputArtifacts;
-      return this;
-    }
-
-    /**
      * Sets how static the link is supposed to be. For static target types (see {@link
      * LinkTargetType#linkerOrArchiver()}}), the {@link #build} method throws an exception if this
      * is not {@link LinkingMode#STATIC}. The default setting is {@link LinkingMode#STATIC}.
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java
index cc9983c..5f3f44a 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java
@@ -189,7 +189,7 @@
   private Iterable<Artifact> getLinkerInputs(ConfiguredTarget target) {
     Artifact executable = getExecutable(target);
     CppLinkAction linkAction = (CppLinkAction) getGeneratingAction(executable);
-    return linkAction.getLinkCommandLineForTesting().getLinkerInputArtifacts().toList();
+    return linkAction.getInputs().toList();
   }
 
   @Test