From 507aeaab74df6ba48f6762c99f541196191bcee7 Mon Sep 17 00:00:00 2001 From: jcater Date: Fri, 16 Apr 2021 06:13:52 -0700 Subject: [PATCH] Re-implement cc_host_toolchain_alias to handle toolchain resolution. PiperOrigin-RevId: 368833358 --- .../rules/cpp/CcHostToolchainAliasRule.java | 71 +++++++++++++++---- .../rules/cpp/CcHostToolchainAliasTest.java | 26 +++++-- 2 files changed, 79 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcHostToolchainAliasRule.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcHostToolchainAliasRule.java index bc737b7ac08b73..2ffc367a811eb6 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcHostToolchainAliasRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcHostToolchainAliasRule.java @@ -14,25 +14,72 @@ package com.google.devtools.build.lib.rules.cpp; +import static com.google.devtools.build.lib.packages.Attribute.attr; +import static com.google.devtools.build.lib.packages.BuildType.LABEL; + +import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException; +import com.google.devtools.build.lib.analysis.BaseRuleClasses; +import com.google.devtools.build.lib.analysis.ConfiguredTarget; +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.RuleDefinition; import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; +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.analysis.TransitiveInfoCollection; import com.google.devtools.build.lib.analysis.config.HostTransition; -import com.google.devtools.build.lib.cmdline.Label; -import com.google.devtools.build.lib.packages.Attribute; -import com.google.devtools.build.lib.rules.LateBoundAlias.CommonAliasRule; +import com.google.devtools.build.lib.analysis.platform.ToolchainInfo; +import com.google.devtools.build.lib.packages.RuleClass; /** Implementation of the {@code cc_toolchain_alias} rule. */ -public class CcHostToolchainAliasRule extends CommonAliasRule { +public class CcHostToolchainAliasRule implements RuleDefinition { - public CcHostToolchainAliasRule() { - super( - "cc_host_toolchain_alias", - CppRuleClasses::ccHostToolchainAttribute, - CppConfiguration.class); + @Override + public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) { + return builder + .requiresConfigurationFragments(CppConfiguration.class) + .removeAttribute("licenses") + .removeAttribute("distribs") + .add( + attr("$cc_toolchain_alias", LABEL) + .cfg(HostTransition.createFactory()) + .value(env.getToolsLabel("//tools/cpp:current_cc_toolchain"))) + .build(); } @Override - protected Attribute.Builder