Skip to content

Commit

Permalink
Add CcToolchainAttributesProvider
Browse files Browse the repository at this point in the history
This provider encapsulates everything that is cc_toolchain-rule specific and
contributes to the construction of CcToolchainProvider. In the followup cl,
cc_toolchain will be modified to provide CcToolchainAttributesProvider, and
cc_toolchain_suite will get the provider and construct the CcToolchainProvider
from it.

#6072.

RELNOTES: None.
PiperOrigin-RevId: 214762144
  • Loading branch information
hlopko authored and Copybara-Service committed Sep 27, 2018
1 parent 9e183ca commit 59a624e
Show file tree
Hide file tree
Showing 3 changed files with 490 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,14 @@
import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.LicensesProvider;
import com.google.devtools.build.lib.analysis.LicensesProvider.TargetLicense;
import com.google.devtools.build.lib.analysis.LicensesProviderImpl;
import com.google.devtools.build.lib.analysis.MiddlemanProvider;
import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder;
import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.Runfiles;
import com.google.devtools.build.lib.analysis.RunfilesProvider;
import com.google.devtools.build.lib.analysis.TemplateVariableInfo;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.packages.License;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.HashMap;

Expand All @@ -48,10 +42,13 @@ public class CcToolchain implements RuleConfiguredTargetFactory {
@Override
public ConfiguredTarget create(RuleContext ruleContext)
throws InterruptedException, RuleErrorException, ActionConflictException {
CcToolchainProvider ccToolchainProvider =
CcToolchainProviderHelper.getCcToolchainProvider(
CcToolchainAttributesProvider attributes =
new CcToolchainAttributesProvider(
ruleContext, isAppleToolchain(), getAdditionalBuildVariables(ruleContext));

CcToolchainProvider ccToolchainProvider =
CcToolchainProviderHelper.getCcToolchainProvider(ruleContext, attributes);

if (ccToolchainProvider == null) {
return null;
}
Expand All @@ -71,22 +68,8 @@ public ConfiguredTarget create(RuleContext ruleContext)
.addProvider(RunfilesProvider.simple(Runfiles.EMPTY))
.addProvider(new MiddlemanProvider(ccToolchainProvider.getCrosstoolMiddleman()));

// If output_license is specified on the cc_toolchain rule, override the transitive licenses
// with that one. This is necessary because cc_toolchain is used in the target configuration,
// but it is sort-of-kind-of a tool, but various parts of it are linked into the output...
// ...so we trust the judgment of the author of the cc_toolchain rule to figure out what
// licenses should be propagated to C++ targets.
// TODO(elenairina): Remove this and use Attribute.Builder.useOutputLicenses() on the
// :cc_toolchain attribute instead.
final License outputLicense =
ruleContext.getRule().getToolOutputLicense(ruleContext.attributes());
if (outputLicense != null && !outputLicense.equals(License.NO_LICENSE)) {
final NestedSet<TargetLicense> license = NestedSetBuilder.create(Order.STABLE_ORDER,
new TargetLicense(ruleContext.getLabel(), outputLicense));
LicensesProvider licensesProvider =
new LicensesProviderImpl(
license, new TargetLicense(ruleContext.getLabel(), outputLicense));
builder.add(LicensesProvider.class, licensesProvider);
if (attributes.getLicensesProvider() != null) {
builder.add(LicensesProvider.class, attributes.getLicensesProvider());
}

return builder.build();
Expand Down Expand Up @@ -118,8 +101,8 @@ private static TemplateVariableInfo createMakeVariableProvider(

/**
* Add local build variables from subclasses into {@link CcToolchainVariables} returned from
* {@link CcToolchainProviderHelper#getBuildVariables(RuleContext, PathFragment,
* CcToolchainVariables)}.
* {@link CcToolchainProviderHelper#getBuildVariables(RuleContext, CcToolchainAttributesProvider,
* PathFragment, CcToolchainVariables)}.
*
* <p>This method is meant to be overridden by subclasses of CcToolchain.
*/
Expand Down
Loading

0 comments on commit 59a624e

Please sign in to comment.