Skip to content

Commit a81264e

Browse files
hlopkophilwo
authored andcommitted
Use tool from action_config for link-executable and link-dynamic-lib actions
This cl finishes the last bit of c++ linking actions migration to crosstool's action_configs. From now on, the action_config { tool_path: ... } will be used, instead of top level tool { path: ... }. RELNOTES: Bazel now uses tools from action_configs in Crosstool by default (as oposed to using top level tools). PiperOrigin-RevId: 159677525
1 parent c9b6f4a commit a81264e

4 files changed

Lines changed: 77 additions & 107 deletions

File tree

src/main/java/com/google/devtools/build/lib/rules/cpp/CppActionConfigs.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public static String getCppActionConfigs(
118118
" config_name: 'c++-link-executable'",
119119
" action_name: 'c++-link-executable'",
120120
" tool {",
121-
" tool_path: 'DUMMY_TOOL'",
121+
" tool_path: '" + gccToolPath + "'",
122122
" }",
123123
" implies: 'symbol_counts'",
124124
" implies: 'strip_debug_symbols'",
@@ -136,7 +136,7 @@ public static String getCppActionConfigs(
136136
" config_name: 'c++-link-dynamic-library'",
137137
" action_name: 'c++-link-dynamic-library'",
138138
" tool {",
139-
" tool_path: 'DUMMY_TOOL'",
139+
" tool_path: '" + gccToolPath + "'",
140140
" }",
141141
" implies: 'build_interface_libraries'",
142142
" implies: 'dynamic_library_linker_tool'",

src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -755,9 +755,15 @@ public CppLinkAction build() throws InterruptedException {
755755
.setToolchain(toolchain)
756756
.setFdoSupport(fdoSupport.getFdoSupport())
757757
.setBuildVariables(buildVariables)
758-
.setToolPath(getToolPath())
759758
.setFeatureConfiguration(featureConfiguration);
760759

760+
// TODO(b/62693279): Cleanup once internal crosstools specify ifso building correctly.
761+
if (linkType.equals(LinkTargetType.DYNAMIC_LIBRARY)
762+
&& !featureConfiguration.hasConfiguredLinkerPathInActionConfig()) {
763+
linkCommandLineBuilder.forceToolPath(
764+
toolchain.getLinkDynamicLibraryTool().getExecPathString());
765+
}
766+
761767
if (!isLTOIndexing) {
762768
linkCommandLineBuilder
763769
.setOutput(output)
@@ -889,26 +895,6 @@ public CppLinkAction build() throws InterruptedException {
889895
executionRequirements.build());
890896
}
891897

892-
/**
893-
* Returns the tool path from feature configuration, if the tool in the configuration is sane, or
894-
* builtin tool, if configuration has a dummy value.
895-
*/
896-
private String getToolPath() {
897-
if (!featureConfiguration.actionIsConfigured(linkType.getActionName())) {
898-
return null;
899-
}
900-
String toolPath =
901-
featureConfiguration
902-
.getToolForAction(linkType.getActionName())
903-
.getToolPath(cppConfiguration.getCrosstoolTopPathFragment())
904-
.getPathString();
905-
if (linkType.equals(LinkTargetType.DYNAMIC_LIBRARY)
906-
&& !featureConfiguration.hasConfiguredLinkerPathInActionConfig()) {
907-
toolPath = toolchain.getLinkDynamicLibraryTool().getExecPathString();
908-
}
909-
return toolPath;
910-
}
911-
912898
/** The default heuristic on whether we need to use whole-archive for the link. */
913899
private static boolean needWholeArchive(
914900
LinkStaticness staticness,

src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java

Lines changed: 28 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
@Immutable
5454
public final class LinkCommandLine extends CommandLine {
5555
private final String actionName;
56-
private final String toolPath;
56+
private final String forcedToolPath;
5757
private final boolean codeCoverageEnabled;
5858
private final CppConfiguration cppConfiguration;
5959
private final ActionOwner owner;
@@ -80,7 +80,7 @@ public final class LinkCommandLine extends CommandLine {
8080

8181
private LinkCommandLine(
8282
String actionName,
83-
String toolPath,
83+
String forcedToolPath,
8484
BuildConfiguration configuration,
8585
ActionOwner owner,
8686
Artifact output,
@@ -103,7 +103,7 @@ private LinkCommandLine(
103103
CcToolchainProvider ccProvider) {
104104

105105
this.actionName = actionName;
106-
this.toolPath = toolPath;
106+
this.forcedToolPath = forcedToolPath;
107107
this.codeCoverageEnabled = configuration.isCodeCoverageEnabled();
108108
this.cppConfiguration = configuration.getFragment(CppConfiguration.class);
109109
this.variables = variables;
@@ -320,6 +320,9 @@ public static void extractArgumentsForDynamicLinkParamFile(
320320
}
321321

322322
private ImmutableList<String> getToolchainFlags() {
323+
if (Staticness.STATIC.equals(linkTargetType.staticness())) {
324+
return ImmutableList.of();
325+
}
323326
boolean fullyStatic = (linkStaticness == LinkStaticness.FULLY_STATIC);
324327
boolean mostlyStatic = (linkStaticness == LinkStaticness.MOSTLY_STATIC);
325328
boolean sharedLinkopts =
@@ -379,52 +382,23 @@ private ImmutableList<String> getToolchainFlags() {
379382
*/
380383
public List<String> getRawLinkArgv() {
381384
List<String> argv = new ArrayList<>();
382-
383-
// TODO(b/30109612): Extract this switch into individual crosstools once action configs are no
384-
// longer hardcoded in CppActionConfigs.
385-
switch (linkTargetType) {
386-
case EXECUTABLE:
387-
argv.add(cppConfiguration.getCppExecutable().getPathString());
388-
argv.addAll(
389-
featureConfiguration.getCommandLine(
390-
actionName,
391-
new Variables.Builder()
392-
.addAll(variables)
393-
.addStringSequenceVariable(
394-
CppLinkActionBuilder.LEGACY_LINK_FLAGS_VARIABLE, getToolchainFlags())
395-
.build()));
396-
break;
397-
398-
case STATIC_LIBRARY:
399-
case PIC_STATIC_LIBRARY:
400-
case ALWAYS_LINK_STATIC_LIBRARY:
401-
case ALWAYS_LINK_PIC_STATIC_LIBRARY:
402-
argv.add(toolPath);
403-
argv.addAll(featureConfiguration.getCommandLine(actionName, variables));
404-
break;
405-
406-
// Since the objc case/dynamic libs is not hardcoded in CppConfiguration, we can use the
407-
// actual tool.
408-
// TODO(b/30109612): make this pattern the case for all link variants.
409-
case DYNAMIC_LIBRARY:
410-
case OBJC_ARCHIVE:
411-
case OBJC_FULLY_LINKED_ARCHIVE:
412-
case OBJC_EXECUTABLE:
413-
case OBJCPP_EXECUTABLE:
414-
argv.add(toolPath);
415-
argv.addAll(
416-
featureConfiguration.getCommandLine(
417-
actionName,
418-
new Variables.Builder()
419-
.addAll(variables)
420-
.addStringSequenceVariable(
421-
CppLinkActionBuilder.LEGACY_LINK_FLAGS_VARIABLE, getToolchainFlags())
422-
.build()));
423-
break;
424-
425-
default:
426-
throw new IllegalArgumentException();
427-
}
385+
if (forcedToolPath != null) {
386+
argv.add(forcedToolPath);
387+
} else {
388+
argv.add(
389+
featureConfiguration
390+
.getToolForAction(linkTargetType.getActionName())
391+
.getToolPath(cppConfiguration.getCrosstoolTopPathFragment())
392+
.getPathString());
393+
}
394+
argv.addAll(
395+
featureConfiguration.getCommandLine(
396+
actionName,
397+
new Variables.Builder()
398+
.addAll(variables)
399+
.addStringSequenceVariable(
400+
CppLinkActionBuilder.LEGACY_LINK_FLAGS_VARIABLE, getToolchainFlags())
401+
.build()));
428402
return argv;
429403
}
430404

@@ -635,7 +609,7 @@ public static final class Builder {
635609
private final ActionOwner owner;
636610
private final RuleContext ruleContext;
637611

638-
@Nullable private String toolPath;
612+
private String forcedToolPath;
639613
@Nullable private Artifact output;
640614
private ImmutableList<Artifact> buildInfoHeaderArtifacts = ImmutableList.of();
641615
private Iterable<? extends LinkerInput> linkerInputs = ImmutableList.of();
@@ -714,7 +688,7 @@ public LinkCommandLine build() {
714688

715689
return new LinkCommandLine(
716690
actionName,
717-
toolPath,
691+
forcedToolPath,
718692
configuration,
719693
owner,
720694
output,
@@ -751,9 +725,9 @@ public Builder setFdoSupport(FdoSupport fdoSupport) {
751725
return this;
752726
}
753727

754-
/** Sets the tool path, with tool being the first thing on the command line */
755-
public Builder setToolPath(String toolPath) {
756-
this.toolPath = toolPath;
728+
/** Use given tool path instead of the one from feature configuration */
729+
public Builder forceToolPath(String forcedToolPath) {
730+
this.forcedToolPath = forcedToolPath;
757731
return this;
758732
}
759733

0 commit comments

Comments
 (0)