5353@ Immutable
5454public 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