-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently guarded by --experimental_action_args. With this flag aspects can access precise command lines used by C++ actions by calling their .args() method. See 2b6a435 for more details. RELNOTES: None. PiperOrigin-RevId: 282540483
- Loading branch information
1 parent
8f075d2
commit e7ce105
Showing
8 changed files
with
290 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/main/java/com/google/devtools/build/lib/rules/cpp/FeatureConfigurationCommandLine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright 2019 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.devtools.build.lib.rules.cpp; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.devtools.build.lib.actions.Artifact.ArtifactExpander; | ||
import com.google.devtools.build.lib.actions.CommandLine; | ||
import com.google.devtools.build.lib.actions.CommandLineExpansionException; | ||
import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.ExpansionException; | ||
import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration; | ||
|
||
/** | ||
* A representation of command line for C++ actions ({@link CppCompileAction}, {@link | ||
* CppLinkAction}, {@link LtoBackendAction}...). | ||
* | ||
* <p>This class is an adapter from {@link FeatureConfiguration} and {@link CcToolchainVariables} to | ||
* {@link CommandLine}. Using this we're able to pass C++ command lines to {@link | ||
* com.google.devtools.build.lib.analysis.actions.SpawnAction} or to give access to C++ command | ||
* lines to Starlark aspects. | ||
* | ||
* <p>See {@link CompileCommandLine#getArguments} for inline subclass of CommandLine that does all | ||
* of this plus some more specifics for CppCompileAction. | ||
*/ | ||
public class FeatureConfigurationCommandLine extends CommandLine { | ||
|
||
private final FeatureConfiguration featureConfiguration; | ||
private final CcToolchainVariables buildVariables; | ||
private final String actionName; | ||
private final boolean usePic; | ||
|
||
/** | ||
* Create a {@link CommandLine} instance from given {@link FeatureConfiguration} and {@link | ||
* CcToolchainVariables}. | ||
*/ | ||
public static FeatureConfigurationCommandLine from( | ||
FeatureConfiguration featureConfiguration, | ||
CcToolchainVariables ccToolchainVariables, | ||
String actionName) { | ||
return new FeatureConfigurationCommandLine( | ||
featureConfiguration, ccToolchainVariables, actionName, /* usePic= */ false); | ||
} | ||
|
||
/** | ||
* Do not use for new code. | ||
* | ||
* <p>TODO(hlopko): Refactor to remove the usePic field. | ||
* | ||
* @deprecated Only there for legacy/technical debt reasons for ThinLTO. | ||
*/ | ||
@Deprecated | ||
public static FeatureConfigurationCommandLine forLtoBackendAction( | ||
FeatureConfiguration featureConfiguration, | ||
CcToolchainVariables ccToolchainVariables, | ||
boolean usePic) { | ||
return new FeatureConfigurationCommandLine( | ||
featureConfiguration, ccToolchainVariables, CppActionNames.LTO_BACKEND, usePic); | ||
} | ||
|
||
private FeatureConfigurationCommandLine( | ||
FeatureConfiguration featureConfiguration, | ||
CcToolchainVariables ccToolchainVariables, | ||
String actionName, | ||
boolean usePic) { | ||
this.featureConfiguration = featureConfiguration; | ||
this.buildVariables = ccToolchainVariables; | ||
this.actionName = actionName; | ||
this.usePic = usePic; | ||
} | ||
@Override | ||
public Iterable<String> arguments() throws CommandLineExpansionException { | ||
return arguments(/* artifactExpander= */ null); | ||
} | ||
|
||
@Override | ||
public Iterable<String> arguments(ArtifactExpander artifactExpander) | ||
throws CommandLineExpansionException { | ||
ImmutableList.Builder<String> args = ImmutableList.builder(); | ||
try { | ||
args.addAll( | ||
featureConfiguration.getCommandLine(actionName, buildVariables, artifactExpander)); | ||
} catch (ExpansionException e) { | ||
throw new CommandLineExpansionException(e.getMessage()); | ||
} | ||
// If this is a PIC compile (set based on the CppConfiguration), the PIC | ||
// option should be added after the rest of the command line so that it | ||
// cannot be overridden. This is consistent with the ordering in the | ||
// CppCompileAction's compiler options. | ||
if (usePic) { | ||
args.add("-fPIC"); | ||
} | ||
return args.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 0 additions & 60 deletions
60
src/main/java/com/google/devtools/build/lib/rules/cpp/LtoBackendCommandLine.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.