Skip to content

Commit

Permalink
Delete native CcToolchainAlias rule since it is already Starlarkified.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 527571232
Change-Id: Ic6383beb645507c6c9efe89dcc81c5c0952ecdea
  • Loading branch information
buildbreaker2021 authored and copybara-github committed Apr 27, 2023
1 parent 7d61938 commit db70e2f
Showing 1 changed file with 5 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,88 +14,29 @@

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 static com.google.devtools.build.lib.packages.BuildType.NODEP_LABEL;

import com.google.common.collect.ImmutableMap;
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.PlatformConfiguration;
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.platform.ToolchainInfo;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.Type;
import javax.annotation.Nullable;

/** Implementation of the {@code cc_toolchain_alias} rule. */
/**
* Dummy rule definition for cc_toolchain_alias rule. To make sure that the rule can be overridden
* from Starlark builtins.
*/
public class CcToolchainAliasRule implements RuleDefinition {
@Override
public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
return builder
.requiresConfigurationFragments(CppConfiguration.class)
.removeAttribute("licenses")
.removeAttribute("distribs")
.add(
attr(CcToolchain.CC_TOOLCHAIN_DEFAULT_ATTRIBUTE_NAME, LABEL)
.mandatoryProviders(CcToolchainProvider.PROVIDER.id())
.value(CppRuleClasses.ccToolchainAttribute(env)))
.add(
attr(CcToolchain.CC_TOOLCHAIN_TYPE_ATTRIBUTE_NAME, NODEP_LABEL)
.value(CppRuleClasses.ccToolchainTypeAttribute(env)))
.add(attr("mandatory", Type.BOOLEAN).value(true))
.requiresConfigurationFragments(PlatformConfiguration.class)
.addToolchainTypes(CppRuleClasses.ccToolchainTypeRequirement(env))
.build();
}

@Override
public Metadata getMetadata() {
return Metadata.builder()
.name("cc_toolchain_alias")
.factoryClass(BaseRuleClasses.EmptyRuleConfiguredTargetFactory.class)
.ancestors(BaseRuleClasses.NativeBuildRule.class)
.factoryClass(CcToolchainAlias.class)
.build();
}

/** Implementation of cc_toolchain_alias. */
public static class CcToolchainAlias implements RuleConfiguredTargetFactory {
@Override
@Nullable
public ConfiguredTarget create(RuleContext ruleContext)
throws InterruptedException, RuleErrorException, ActionConflictException {

CcToolchainProvider ccToolchainProvider =
CppHelper.getToolchainUsingDefaultCcToolchainAttribute(ruleContext);

TemplateVariableInfo templateVariableInfo =
CcToolchain.createMakeVariableProvider(
ccToolchainProvider, ruleContext.getRule().getLocation());

ToolchainInfo toolchain =
new ToolchainInfo(
ImmutableMap.<String, Object>builder()
.put("cc", ccToolchainProvider)
// Add a clear signal that this is a CcToolchainProvider, since just "cc" is
// generic enough to possibly be re-used.
.put("cc_provider_in_toolchain", true)
.build());

return new RuleConfiguredTargetBuilder(ruleContext)
.addProvider(RunfilesProvider.simple(Runfiles.EMPTY))
.addNativeDeclaredProvider(ccToolchainProvider)
.addNativeDeclaredProvider(toolchain)
.addNativeDeclaredProvider(templateVariableInfo)
.setFilesToBuild(ccToolchainProvider.getAllFilesIncludingLibc())
.build();
}
}
}

0 comments on commit db70e2f

Please sign in to comment.