Skip to content

Commit

Permalink
Remove CppConfiguration#getFeatures in favor of
Browse files Browse the repository at this point in the history
CcToolchainProvider#getFeatures.

PiperOrigin-RevId: 173702792
  • Loading branch information
calpeyser authored and katre committed Oct 30, 2017
1 parent 02a5b0f commit 5d42ae1
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public boolean supportsHeaderParsing() {
*/
@Nullable
public CcToolchainFeatures getFeatures() {
return cppConfiguration == null ? null : cppConfiguration.getFeatures();
return toolchainInfo.getFeatures();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class CppCompileActionTemplate implements ActionTemplate<CppCompile
private final CppCompileActionBuilder cppCompileActionBuilder;
private final Artifact sourceTreeArtifact;
private final Artifact outputTreeArtifact;
private final CppConfiguration cppConfiguration;
private final CcToolchainProvider toolchain;
private final Iterable<ArtifactCategory> categories;
private final ActionOwner actionOwner;
private final NestedSet<Artifact> mandatoryInputs;
Expand All @@ -49,25 +49,25 @@ public final class CppCompileActionTemplate implements ActionTemplate<CppCompile
* Creates an CppCompileActionTemplate.
* @param sourceTreeArtifact the TreeArtifact that contains source files to compile.
* @param outputTreeArtifact the TreeArtifact that contains compilation outputs.
* @param cppCompileActionBuilder An almost completely configured {@link CppCompileActionBuilder}
* @param cppCompileActionBuilder An almost completely configured {@link CppCompileActionBuilder}
* without the input and output files set. It is used as a template to instantiate expanded
* {CppCompileAction}s.
* @param cppConfiguration configuration for cpp.
* @param categories A list of {@link ArtifactCategory} used to calculate output file name from
* a source file name.
* @param toolchain the CcToolchainProvider representing the c++ toolchain for this action
* @param categories A list of {@link ArtifactCategory} used to calculate output file name from a
* source file name.
* @param actionOwner the owner of this {@link ActionTemplate}.
*/
CppCompileActionTemplate(
Artifact sourceTreeArtifact,
Artifact outputTreeArtifact,
CppCompileActionBuilder cppCompileActionBuilder,
CppConfiguration cppConfiguration,
CcToolchainProvider toolchain,
Iterable<ArtifactCategory> categories,
ActionOwner actionOwner) {
this.cppCompileActionBuilder = cppCompileActionBuilder;
this.sourceTreeArtifact = sourceTreeArtifact;
this.outputTreeArtifact = outputTreeArtifact;
this.cppConfiguration = cppConfiguration;
this.toolchain = toolchain;
this.categories = categories;
this.actionOwner = actionOwner;
this.mandatoryInputs = cppCompileActionBuilder.buildMandatoryInputs();
Expand Down Expand Up @@ -124,7 +124,7 @@ private String outputTreeFileArtifactName(TreeFileArtifact inputTreeFileArtifact
String outputName = FileSystemUtils.removeExtension(
inputTreeFileArtifact.getParentRelativePath().getPathString());
for (ArtifactCategory category : categories) {
outputName = cppConfiguration.getFeatures().getArtifactNameForCategory(category, outputName);
outputName = toolchain.getFeatures().getArtifactNameForCategory(category, outputName);
}
return outputName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,14 +611,6 @@ public Label getCcToolchainRuleLabel() {
return ccToolchainLabel;
}

/**
* Returns the configured features of the toolchain. Rules should not call this directly, but
* instead use {@code CcToolchainProvider.getFeatures}.
*/
public CcToolchainFeatures getFeatures() {
return cppToolchainInfo.getFeatures();
}

/**
* Returns the configured current compilation mode. Rules should not call this directly, but
* instead use {@code CcToolchainProvider.getCompilationMode}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1165,13 +1165,14 @@ private Artifact createCompileActionTemplate(AnalysisEnvironment env,
coptsFilter,
features);
// Make sure this builder doesn't reference ruleContext outside of analysis phase.
CppCompileActionTemplate actionTemplate = new CppCompileActionTemplate(
sourceArtifact,
outputFiles,
builder,
cppConfiguration,
outputCategories,
ruleContext.getActionOwner());
CppCompileActionTemplate actionTemplate =
new CppCompileActionTemplate(
sourceArtifact,
outputFiles,
builder,
ccToolchain,
outputCategories,
ruleContext.getActionOwner());
env.registerAction(actionTemplate);

return outputFiles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.google.devtools.build.lib.rules.proto.ProtoSourcesProvider;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;

/**
Expand Down Expand Up @@ -105,7 +106,10 @@ public final ConfiguredTarget create(RuleContext ruleContext)
ruleContext.getPrerequisitesByConfiguration("deps", Mode.SPLIT, ObjcProtoProvider.class);

Map<String, NestedSet<Artifact>> outputGroupCollector = new TreeMap<>();
for (BuildConfiguration childConfig : childConfigurationsAndToolchains.keySet()) {
for (Entry<BuildConfiguration, CcToolchainProvider> childConfigAndToolchain :
childConfigurationsAndToolchains.entrySet()) {
BuildConfiguration childConfig = childConfigAndToolchain.getKey();
CcToolchainProvider childToolchain = childConfigAndToolchain.getValue();
Iterable<ObjcProtoProvider> objcProtoProviders = objcProtoProvidersMap.get(childConfig);
ProtobufSupport protoSupport =
new ProtobufSupport(
Expand Down Expand Up @@ -141,6 +145,7 @@ public final ConfiguredTarget create(RuleContext ruleContext)
new CompilationSupport.Builder()
.setRuleContext(ruleContext)
.setConfig(childConfig)
.setToolchainProvider(childToolchain)
.setOutputGroupCollector(outputGroupCollector)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,9 @@ protected CompilationSupport(
this.usePch = usePch;
// TODO(b/62143697): Remove this check once all rules are using the crosstool support.
if (ruleContext
.attributes()
.has(CcToolchain.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME, BuildType.LABEL)) {
.attributes()
.has(CcToolchain.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME, BuildType.LABEL)
|| ruleContext.attributes().has(":j2objc_cc_toolchain", BuildType.LABEL)) {
if (toolchain == null) {
toolchain = CppHelper.getToolchainUsingDefaultCcToolchainAttribute(ruleContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.VariablesExtension;
import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider;
import com.google.devtools.build.lib.rules.cpp.CppCompileAction;
import com.google.devtools.build.lib.rules.cpp.CppConfiguration;
import com.google.devtools.build.lib.rules.cpp.CppHelper;
import com.google.devtools.build.lib.rules.cpp.CppLinkAction;
import com.google.devtools.build.lib.rules.cpp.CppLinkActionBuilder;
Expand Down Expand Up @@ -551,8 +550,7 @@ private FeatureConfiguration getFeatureConfiguration(

activatedCrosstoolSelectables.addAll(ruleContext.getFeatures());
try {
return configuration
.getFragment(CppConfiguration.class)
return toolchain
.getFeatures()
.getFeatureConfiguration(
FeatureSpecification.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ private ConfiguredAspect buildAspect(
CompilationSupport compilationSupport =
new CompilationSupport.Builder()
.setRuleContext(ruleContext)
.setToolchainProvider(ccToolchain)
.setIntermediateArtifacts(ObjcRuleClasses.j2objcIntermediateArtifacts(ruleContext))
.doNotUsePch()
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public void registerActions(
new CompilationSupport.Builder()
.setRuleContext(ruleContext)
.setConfig(dependencySpecificConfiguration.config())
.setToolchainProvider(dependencySpecificConfiguration.toolchain())
.setOutputGroupCollector(outputMapCollector)
.build();

Expand Down

0 comments on commit 5d42ae1

Please sign in to comment.