Skip to content

Commit

Permalink
Replace calls to getRawLinkArgv with calls to arguments
Browse files Browse the repository at this point in the history
The implementation of both methods is the same. Because the second one is already public, this reduces the number of public methods of LinkCommandLine.

The change is a no-op.

PiperOrigin-RevId: 595771439
Change-Id: Ia5a494746c1f15be7a16149ee28ae349c57c955d
  • Loading branch information
comius authored and copybara-github committed Jan 4, 2024
1 parent cb98d32 commit c92ecbf
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,25 +247,14 @@ private static boolean isLikelyParamFile(String arg) {
&& !arg.startsWith("@executable_path");
}

/**
* Returns a raw link command for the given link invocation, including both command and arguments
* (argv). The version that uses the expander is preferred, but that one can't be used during
* analysis.
*
* @return raw link command line.
*/
public List<String> getRawLinkArgv() throws CommandLineExpansionException {
return getRawLinkArgv(null);
}

/**
* Returns a raw link command for the given link invocation, including both command and arguments
* (argv).
*
* @param expander ArtifactExpander for expanding TreeArtifacts.
* @return raw link command line.
*/
public List<String> getRawLinkArgv(@Nullable ArtifactExpander expander)
private List<String> getRawLinkArgv(@Nullable ArtifactExpander expander)
throws CommandLineExpansionException {
return getRawLinkArgv(
expander, forcedToolPath, featureConfiguration, actionName, linkTargetType, variables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ public void testActionGraph() throws Exception {
assertThat(ActionsTestUtil.getFirstArtifactEndingWith(linkAction.getInputs(), "linkstamp.o"))
.isNotNull();

List<String> commandLine = linkAction.getLinkCommandLineForTesting().getRawLinkArgv();
String prefix = getTargetConfiguration().getOutputDirectory(RepositoryName.MAIN)
.getExecPathString();
List<String> commandLine = linkAction.getLinkCommandLineForTesting().arguments();
String prefix =
getTargetConfiguration().getOutputDirectory(RepositoryName.MAIN).getExecPathString();
assertThat(commandLine)
.containsAtLeast(
prefix + "/bin/pkg/bin.lto.merged.o",
Expand Down Expand Up @@ -421,9 +421,9 @@ public void testNoLinkstatic() throws Exception {
CppLinkAction linkAction = getLinkAction();
String rootExecPath = getRootExecPath();

List<String> commandLine = linkAction.getLinkCommandLineForTesting().getRawLinkArgv();
String prefix = getTargetConfiguration().getOutputDirectory(RepositoryName.MAIN)
.getExecPathString();
List<String> commandLine = linkAction.getLinkCommandLineForTesting().arguments();
String prefix =
getTargetConfiguration().getOutputDirectory(RepositoryName.MAIN).getExecPathString();

assertThat(commandLine).contains("-Wl,@" + prefix + "/bin/pkg/bin-lto-final.params");

Expand Down Expand Up @@ -1821,7 +1821,7 @@ public void testPropellerOptimizeAbsoluteOptions() throws Exception {
assertThat(ActionsTestUtil.baseArtifactNames(linkAction.getInputs()))
.contains("ld_profile.txt");

List<String> commandLine = linkAction.getLinkCommandLineForTesting().getRawLinkArgv();
List<String> commandLine = linkAction.getLinkCommandLineForTesting().arguments();
assertThat(commandLine.toString())
.containsMatch("-Wl,--symbol-ordering-file=.*/ld_profile.txt");

Expand Down Expand Up @@ -1968,7 +1968,7 @@ public void testPropellerHostBuilds() throws Exception {
(CppLinkAction) getPredecessorByInputName(genruleAction, "pkg/gen_lib");
assertThat(ActionsTestUtil.baseArtifactNames(hostLinkAction.getInputs()))
.doesNotContain("ld_profile.txt");
assertThat(hostLinkAction.getLinkCommandLineForTesting().getRawLinkArgv().toString())
assertThat(hostLinkAction.getLinkCommandLineForTesting().arguments().toString())
.doesNotContainMatch("-Wl,--symbol-ordering-file=.*/ld_profile.txt");

// The hostLinkAction inputs has a different root from the backendAction.
Expand All @@ -1988,7 +1988,7 @@ public void testPropellerHostBuilds() throws Exception {
assertThat(hostIndexAction).isNotNull();
assertThat(ActionsTestUtil.baseArtifactNames(hostIndexAction.getInputs()))
.doesNotContain("ld_profile.txt");
assertThat(hostIndexAction.getLinkCommandLineForTesting().getRawLinkArgv().toString())
assertThat(hostIndexAction.getLinkCommandLineForTesting().arguments().toString())
.doesNotContainMatch("-Wl,--symbol-ordering-file=.*/ld_profile.txt");

CppCompileAction hostBitcodeAction =
Expand Down Expand Up @@ -2026,7 +2026,7 @@ private void testPropellerOptimizeOption(boolean label) throws Exception {
CppLinkAction linkAction = (CppLinkAction) getGeneratingAction(binArtifact);
assertThat(linkAction.getOutputs()).containsExactly(binArtifact);

List<String> commandLine = linkAction.getLinkCommandLineForTesting().getRawLinkArgv();
List<String> commandLine = linkAction.getLinkCommandLineForTesting().arguments();
assertThat(commandLine.toString())
.containsMatch("-Wl,--symbol-ordering-file=.*/ld_profile.txt");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ public void testActionGraph() throws Exception {
assertThat(ActionsTestUtil.getFirstArtifactEndingWith(linkAction.getInputs(), "linkstamp.o"))
.isNotNull();

List<String> commandLine = linkAction.getLinkCommandLineForTesting().getRawLinkArgv();
String prefix = getTargetConfiguration().getOutputDirectory(RepositoryName.MAIN)
.getExecPathString();
List<String> commandLine = linkAction.getLinkCommandLineForTesting().arguments();
String prefix =
getTargetConfiguration().getOutputDirectory(RepositoryName.MAIN).getExecPathString();
assertThat(commandLine)
.containsAtLeast(
prefix + "/bin/pkg/bin.lto.merged.o",
Expand Down Expand Up @@ -303,9 +303,9 @@ public void testNoLinkstatic() throws Exception {
CppLinkAction linkAction = getLinkAction();
String rootExecPath = getRootExecPath();

List<String> commandLine = linkAction.getLinkCommandLineForTesting().getRawLinkArgv();
String prefix = getTargetConfiguration().getOutputDirectory(RepositoryName.MAIN)
.getExecPathString();
List<String> commandLine = linkAction.getLinkCommandLineForTesting().arguments();
String prefix =
getTargetConfiguration().getOutputDirectory(RepositoryName.MAIN).getExecPathString();

assertThat(commandLine).contains("-Wl,@" + prefix + "/bin/pkg/bin-lto-final.params");

Expand Down Expand Up @@ -1741,7 +1741,7 @@ public void testPropellerOptimizeAbsoluteOptions() throws Exception {
assertThat(ActionsTestUtil.baseArtifactNames(linkAction.getInputs()))
.contains("ld_profile.txt");

List<String> commandLine = linkAction.getLinkCommandLineForTesting().getRawLinkArgv();
List<String> commandLine = linkAction.getLinkCommandLineForTesting().arguments();
assertThat(commandLine.toString())
.containsMatch("-Wl,--symbol-ordering-file=.*/ld_profile.txt");

Expand Down Expand Up @@ -1926,7 +1926,7 @@ public void testPropellerHostBuilds() throws Exception {
(CppLinkAction) getPredecessorByInputName(genruleAction, "pkg/gen_lib");
assertThat(ActionsTestUtil.baseArtifactNames(hostLinkAction.getInputs()))
.doesNotContain("ld_profile.txt");
assertThat(hostLinkAction.getLinkCommandLineForTesting().getRawLinkArgv().toString())
assertThat(hostLinkAction.getLinkCommandLineForTesting().arguments().toString())
.doesNotContainMatch("-Wl,--symbol-ordering-file=.*/ld_profile.txt");

// The hostLinkAction inputs has a different root from the backendAction.
Expand All @@ -1946,7 +1946,7 @@ public void testPropellerHostBuilds() throws Exception {
assertThat(hostIndexAction).isNotNull();
assertThat(ActionsTestUtil.baseArtifactNames(hostIndexAction.getInputs()))
.doesNotContain("ld_profile.txt");
assertThat(hostIndexAction.getLinkCommandLineForTesting().getRawLinkArgv().toString())
assertThat(hostIndexAction.getLinkCommandLineForTesting().arguments().toString())
.doesNotContainMatch("-Wl,--symbol-ordering-file=.*/ld_profile.txt");

CppCompileAction hostBitcodeAction =
Expand Down Expand Up @@ -1984,7 +1984,7 @@ private void testPropellerOptimizeOption(boolean label) throws Exception {
CppLinkAction linkAction = (CppLinkAction) getGeneratingAction(binArtifact);
assertThat(linkAction.getOutputs()).containsExactly(binArtifact);

List<String> commandLine = linkAction.getLinkCommandLineForTesting().getRawLinkArgv();
List<String> commandLine = linkAction.getLinkCommandLineForTesting().arguments();
assertThat(commandLine.toString())
.containsMatch("-Wl,--symbol-ordering-file=.*/ld_profile.txt");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.mock;

import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
Expand All @@ -32,7 +31,6 @@
import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact;
import com.google.devtools.build.lib.actions.ArtifactRoot;
import com.google.devtools.build.lib.actions.ArtifactRoot.RootType;
import com.google.devtools.build.lib.actions.InputMetadataProvider;
import com.google.devtools.build.lib.actions.PathMapper;
import com.google.devtools.build.lib.actions.ResourceSet;
import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
Expand Down Expand Up @@ -780,8 +778,6 @@ private static NestedSet<Artifact> createInputs(RuleContext ruleContext, int cou

private ResourceSet estimateResourceConsumptionLocal(
RuleContext ruleContext, OS os, int inputsCount) throws Exception {
InputMetadataProvider inputMetadataProvider = mock(InputMetadataProvider.class);

NestedSet<Artifact> inputs = createInputs(ruleContext, inputsCount);
try {
LinkResourceSetBuilder estimator = new LinkResourceSetBuilder();
Expand Down Expand Up @@ -1064,13 +1060,13 @@ public void testLinksTreeArtifactLibraries() throws Exception {

// Should only reference the tree artifact.
verifyArguments(
linkAction.getLinkCommandLineForTesting().getRawLinkArgv(),
linkAction.getLinkCommandLineForTesting().arguments(),
treeArtifactsPaths,
treeFileArtifactsPaths);

// Should only reference tree file artifacts.
verifyArguments(
linkAction.getLinkCommandLineForTesting().getRawLinkArgv(expander),
linkAction.getLinkCommandLineForTesting().arguments(expander, null),
treeFileArtifactsPaths,
treeArtifactsPaths);
}
Expand Down Expand Up @@ -1151,7 +1147,7 @@ public void testPieOptionDisabledForSharedLibraries() throws Exception {
.setLibraryIdentifier("foo")
.build();

List<String> argv = linkAction.getLinkCommandLineForTesting().getRawLinkArgv();
List<String> argv = linkAction.getLinkCommandLineForTesting().arguments();
assertThat(argv).doesNotContain("-pie");
assertThat(argv).contains("-other");
}
Expand All @@ -1173,7 +1169,7 @@ public void testPieOptionKeptForExecutables() throws Exception {
.addLinkopts(ImmutableList.of("-pie", "-other", "-pie"))
.build();

List<String> argv = linkAction.getLinkCommandLineForTesting().getRawLinkArgv();
List<String> argv = linkAction.getLinkCommandLineForTesting().arguments();
assertThat(argv).contains("-pie");
assertThat(argv).contains("-other");
}
Expand Down Expand Up @@ -1203,7 +1199,7 @@ public void testLinkoptsComeAfterLinkerInputs() throws Exception {
.addLinkopts(ImmutableList.of("FakeLinkopt1", "FakeLinkopt2"))
.build();

List<String> argv = linkAction.getLinkCommandLineForTesting().getRawLinkArgv();
List<String> argv = linkAction.getLinkCommandLineForTesting().arguments();
int lastLinkerInputIndex =
Ints.max(
argv.indexOf("FakeLinkerInput1"), argv.indexOf("FakeLinkerInput2"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void testLinkCommandIsExecCommandWhenNoLinkstamps() throws Exception {
.setActionName(LinkTargetType.EXECUTABLE.getActionName())
.setLinkTargetType(LinkTargetType.EXECUTABLE)
.build();
List<String> rawLinkArgv = linkConfig.getRawLinkArgv();
List<String> rawLinkArgv = linkConfig.arguments();
assertThat(linkConfig.arguments()).isEqualTo(rawLinkArgv);
}

Expand All @@ -157,7 +157,7 @@ public void testSymbolCountsDisabled() throws Exception {
.forceToolPath("foo/bar/gcc")
.setLinkTargetType(LinkTargetType.NODEPS_DYNAMIC_LIBRARY)
.build();
List<String> argv = linkConfig.getRawLinkArgv();
List<String> argv = linkConfig.arguments();
for (String arg : argv) {
assertThat(arg).doesNotContain("print-symbol-counts");
}
Expand All @@ -179,7 +179,7 @@ public void testLibrariesToLink() throws Exception {
.setActionName(LinkTargetType.NODEPS_DYNAMIC_LIBRARY.getActionName())
.setLinkTargetType(LinkTargetType.NODEPS_DYNAMIC_LIBRARY)
.build();
String commandLine = Joiner.on(" ").join(linkConfig.getRawLinkArgv());
String commandLine = Joiner.on(" ").join(linkConfig.arguments());
assertThat(commandLine).matches(".*foo -Wl,-whole-archive bar -Wl,-no-whole-archive.*");
}

Expand All @@ -196,7 +196,7 @@ public void testLibrarySearchDirectories() throws Exception {
.setActionName(LinkTargetType.NODEPS_DYNAMIC_LIBRARY.getActionName())
.setLinkTargetType(LinkTargetType.NODEPS_DYNAMIC_LIBRARY)
.build();
assertThat(linkConfig.getRawLinkArgv()).containsAtLeast("-Lfoo", "-Lbar").inOrder();
assertThat(linkConfig.arguments()).containsAtLeast("-Lfoo", "-Lbar").inOrder();
}

@Test
Expand All @@ -211,7 +211,7 @@ public void testLinkerParamFileForStaticLibrary() throws Exception {
.setActionName(LinkTargetType.STATIC_LIBRARY.getActionName())
.setLinkTargetType(LinkTargetType.STATIC_LIBRARY)
.build();
assertThat(linkConfig.getRawLinkArgv()).contains("@foo/bar.param");
assertThat(linkConfig.arguments()).contains("@foo/bar.param");
}

@Test
Expand All @@ -226,7 +226,7 @@ public void testLinkerParamFileForDynamicLibrary() throws Exception {
.setActionName(LinkTargetType.NODEPS_DYNAMIC_LIBRARY.getActionName())
.setLinkTargetType(LinkTargetType.NODEPS_DYNAMIC_LIBRARY)
.build();
assertThat(linkConfig.getRawLinkArgv()).contains("@foo/bar.param");
assertThat(linkConfig.arguments()).contains("@foo/bar.param");
}

private List<String> basicArgv(LinkTargetType targetType) throws Exception {
Expand Down Expand Up @@ -328,7 +328,7 @@ public void testStaticLinkCommand() throws Exception {
.setActionName(LinkTargetType.STATIC_LIBRARY.getActionName())
.setLinkTargetType(LinkTargetType.STATIC_LIBRARY)
.build();
List<String> result = linkConfig.getRawLinkArgv();
List<String> result = linkConfig.arguments();
assertThat(result).isEqualTo(Arrays.asList("foo/bar/ar", "rcsD", "a/FakeOutput"));
}

Expand Down Expand Up @@ -420,7 +420,7 @@ public void expand(Artifact artifact, Collection<? super Artifact> output) {
// Should only reference the tree artifact.
verifyArguments(
linkConfig.arguments(null, PathMapper.NOOP), treeArtifactsPaths, treeFileArtifactsPaths);
verifyArguments(linkConfig.getRawLinkArgv(null), treeArtifactsPaths, treeFileArtifactsPaths);
verifyArguments(linkConfig.arguments(), treeArtifactsPaths, treeFileArtifactsPaths);
verifyArguments(
linkConfig.paramCmdLine().arguments(null, PathMapper.NOOP),
treeArtifactsPaths,
Expand All @@ -432,7 +432,7 @@ public void expand(Artifact artifact, Collection<? super Artifact> output) {
treeFileArtifactsPaths,
treeArtifactsPaths);
verifyArguments(
linkConfig.getRawLinkArgv(expander), treeFileArtifactsPaths, treeArtifactsPaths);
linkConfig.arguments(expander, null), treeFileArtifactsPaths, treeArtifactsPaths);
verifyArguments(
linkConfig.paramCmdLine().arguments(expander, PathMapper.NOOP),
treeFileArtifactsPaths,
Expand Down

0 comments on commit c92ecbf

Please sign in to comment.