Skip to content

Commit

Permalink
Update native rules to use a common definition for the CC toolchain t…
Browse files Browse the repository at this point in the history
…ype requirement.

Part of #14727.

PiperOrigin-RevId: 449453965
  • Loading branch information
katre authored and copybara-github committed May 18, 2022
1 parent 1fdf1e1 commit a54a1a7
Show file tree
Hide file tree
Showing 17 changed files with 11 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/actions:artifacts",
"//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster",
"//src/main/java/com/google/devtools/build/lib/analysis:config/execution_transition_factory",
"//src/main/java/com/google/devtools/build/lib/analysis:config/toolchain_type_requirement",
"//src/main/java/com/google/devtools/build/lib/analysis:platform_configuration",
"//src/main/java/com/google/devtools/build/lib/analysis:rule_definition_environment",
"//src/main/java/com/google/devtools/build/lib/analysis/platform",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.config.ExecutionTransitionFactory;
import com.google.devtools.build.lib.analysis.config.ToolchainTypeRequirement;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.packages.Attribute;
import com.google.devtools.build.lib.packages.AttributeMap;
Expand Down Expand Up @@ -105,12 +104,7 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env)
.value(CppRuleClasses.ccToolchainTypeAttribute(env)))
.setPreferredDependencyPredicate(Predicates.<String>or(CPP_SOURCE, C_SOURCE, CPP_HEADER))
.requiresConfigurationFragments(PlatformConfiguration.class)
// TODO(https://github.com/bazelbuild/bazel/issues/14727): Evaluate whether this can be
// optional.
.addToolchainTypes(
ToolchainTypeRequirement.builder(CppRuleClasses.ccToolchainTypeAttribute(env))
.mandatory(true)
.build())
.addToolchainTypes(CppRuleClasses.ccToolchainTypeRequirement(env))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster",
"//src/main/java/com/google/devtools/build/lib/analysis:build_info",
"//src/main/java/com/google/devtools/build/lib/analysis:config/execution_transition_factory",
"//src/main/java/com/google/devtools/build/lib/analysis:config/toolchain_type_requirement",
"//src/main/java/com/google/devtools/build/lib/analysis:rule_definition_environment",
"//src/main/java/com/google/devtools/build/lib/bazel/rules/cpp",
"//src/main/java/com/google/devtools/build/lib/packages",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.config.ToolchainTypeRequirement;
import com.google.devtools.build.lib.bazel.rules.java.BazelJavaRuleClasses.BaseJavaBinaryRule;
import com.google.devtools.build.lib.packages.Attribute;
import com.google.devtools.build.lib.packages.AttributeMap;
Expand Down Expand Up @@ -102,12 +101,7 @@ public Object getDefault(AttributeMap rule) {
return rule.get("create_executable", BOOLEAN);
}
}))
// TODO(https://github.com/bazelbuild/bazel/issues/14727): Evaluate whether this can be
// optional.
.addToolchainTypes(
ToolchainTypeRequirement.builder(CppRuleClasses.ccToolchainTypeAttribute(env))
.mandatory(true)
.build())
.addToolchainTypes(CppRuleClasses.ccToolchainTypeRequirement(env))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.config.ConfigAwareRuleClassBuilder;
import com.google.devtools.build.lib.analysis.config.ExecutionTransitionFactory;
import com.google.devtools.build.lib.analysis.config.ToolchainTypeRequirement;
import com.google.devtools.build.lib.bazel.rules.java.BazelJavaRuleClasses.JavaRule;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.StarlarkProviderIdentifier;
import com.google.devtools.build.lib.rules.cpp.CppConfiguration;
import com.google.devtools.build.lib.rules.cpp.CppRuleClasses;
import com.google.devtools.build.lib.rules.java.JavaConfiguration;
import com.google.devtools.build.lib.rules.java.JavaInfo;
import com.google.devtools.build.lib.rules.java.JavaPluginInfo;
Expand Down Expand Up @@ -159,12 +157,6 @@ differs only in places that the JLS forbids compilers to inline (and that must h
.mandatoryProviders(JavaPluginInfo.PROVIDER.id())
.allowedFileTypes())
.advertiseStarlarkProvider(StarlarkProviderIdentifier.forKey(JavaInfo.PROVIDER.getKey()))
// TODO(https://github.com/bazelbuild/bazel/issues/14727): Evaluate whether this can be
// optional.
.addToolchainTypes(
ToolchainTypeRequirement.builder(CppRuleClasses.ccToolchainTypeAttribute(env))
.mandatory(true)
.build())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.config.ExecutionTransitionFactory;
import com.google.devtools.build.lib.analysis.config.ToolchainTypeRequirement;
import com.google.devtools.build.lib.bazel.rules.java.BazelJavaRuleClasses.BaseJavaBinaryRule;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
Expand Down Expand Up @@ -103,12 +102,7 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env)
</p>
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(attr("test_class", STRING))
// TODO(https://github.com/bazelbuild/bazel/issues/14727): Evaluate whether this can be
// optional.
.addToolchainTypes(
ToolchainTypeRequirement.builder(CppRuleClasses.ccToolchainTypeAttribute(env))
.mandatory(true)
.build())
.addToolchainTypes(CppRuleClasses.ccToolchainTypeRequirement(env))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.config.ToolchainTypeRequirement;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
import com.google.devtools.build.lib.util.FileTypeSet;
Expand Down Expand Up @@ -99,12 +98,7 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env)
<!-- #END_BLAZE_RULE.ATTRIBUTE -->*/
.add(attr("alwayslink", BOOLEAN))
.add(attr("data", LABEL_LIST).allowedFileTypes(FileTypeSet.ANY_FILE).dontCheckConstraints())
// TODO(https://github.com/bazelbuild/bazel/issues/14727): Evaluate whether this can be
// optional.
.addToolchainTypes(
ToolchainTypeRequirement.builder(CppRuleClasses.ccToolchainTypeAttribute(env))
.mandatory(true)
.build())
.addToolchainTypes(CppRuleClasses.ccToolchainTypeRequirement(env))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
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.config.ToolchainTypeRequirement;
import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
import com.google.devtools.build.lib.packages.RuleClass;
import javax.annotation.Nullable;
Expand All @@ -52,12 +51,7 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env)
attr(CcToolchain.CC_TOOLCHAIN_TYPE_ATTRIBUTE_NAME, NODEP_LABEL)
.value(CppRuleClasses.ccToolchainTypeAttribute(env)))
.requiresConfigurationFragments(PlatformConfiguration.class)
// TODO(https://github.com/bazelbuild/bazel/issues/14727): Evaluate whether this can be
// optional.
.addToolchainTypes(
ToolchainTypeRequirement.builder(CppRuleClasses.ccToolchainTypeAttribute(env))
.mandatory(true)
.build())
.addToolchainTypes(CppRuleClasses.ccToolchainTypeRequirement(env))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/lib/actions:artifacts",
"//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster",
"//src/main/java/com/google/devtools/build/lib/analysis:config/toolchain_type_requirement",
"//src/main/java/com/google/devtools/build/lib/analysis:configured_target",
"//src/main/java/com/google/devtools/build/lib/analysis:rule_definition_environment",
"//src/main/java/com/google/devtools/build/lib/analysis:transitive_info_collection",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.TransitiveInfoProviderMap;
import com.google.devtools.build.lib.analysis.TransitiveInfoProviderMapBuilder;
import com.google.devtools.build.lib.analysis.config.ToolchainTypeRequirement;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
Expand Down Expand Up @@ -121,12 +120,7 @@ public AspectDefinition getDefinition(AspectParameters aspectParameters) {
.propagateAlongAttribute("deps")
.requiresConfigurationFragments(CppConfiguration.class, ProtoConfiguration.class)
.requireStarlarkProviders(ProtoInfo.PROVIDER.id())
.addToolchainTypes(
ToolchainTypeRequirement.builder(ccToolchainType)
// TODO(https://github.com/bazelbuild/bazel/issues/14727): Evaluate whether this
// can be optional.
.mandatory(true)
.build())
.addToolchainTypes(CppRuleClasses.ccToolchainTypeRequirement(ccToolchainType))
.add(
attr(PROTO_TOOLCHAIN_ATTR, LABEL)
.mandatoryProviders(ProtoLangToolchainProvider.PROVIDER_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.config.ToolchainTypeRequirement;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
import com.google.devtools.build.lib.rules.config.ConfigFeatureFlagProvider;
import com.google.devtools.build.lib.rules.cpp.CppConfiguration;
import com.google.devtools.build.lib.rules.cpp.CppRuleClasses;

/**
* Abstract rule definition for apple_static_library.
Expand Down Expand Up @@ -81,12 +79,6 @@ <p>A list of targets which should not be included (nor their transitive dependen
.allowedFileTypes()
.nonconfigurable("defines an aspect of configuration")
.mandatoryProviders(ImmutableList.of(ConfigFeatureFlagProvider.id())))
// TODO(https://github.com/bazelbuild/bazel/issues/14727): Evaluate whether this can be
// optional.
.addToolchainTypes(
ToolchainTypeRequirement.builder(CppRuleClasses.ccToolchainTypeAttribute(env))
.mandatory(true)
.build())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/analysis:config/execution_transition_factory",
"//src/main/java/com/google/devtools/build/lib/analysis:config/fragment",
"//src/main/java/com/google/devtools/build/lib/analysis:config/fragment_options",
"//src/main/java/com/google/devtools/build/lib/analysis:config/toolchain_type_requirement",
"//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/patch_transition",
"//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/split_transition",
"//src/main/java/com/google/devtools/build/lib/analysis:config/transitions/starlark_exposed_rule_transition_factory",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.analysis.config.ConfigAwareAspectBuilder;
import com.google.devtools.build.lib.analysis.config.ExecutionTransitionFactory;
import com.google.devtools.build.lib.analysis.config.ToolchainTypeRequirement;
import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.cmdline.RepositoryName;
Expand Down Expand Up @@ -149,12 +148,7 @@ public AspectDefinition getDefinition(AspectParameters aspectParameters) {
J2ObjcConfiguration.class,
ObjcConfiguration.class,
ProtoConfiguration.class)
.addToolchainTypes(
ToolchainTypeRequirement.builder(ccToolchainType)
// TODO(https://github.com/bazelbuild/bazel/issues/14727): Evaluate whether this can
// be optional.
.mandatory(true)
.build())
.addToolchainTypes(CppRuleClasses.ccToolchainTypeRequirement(ccToolchainType))
.add(
attr("$grep_includes", LABEL)
.cfg(ExecutionTransitionFactory.create())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.config.ToolchainTypeRequirement;
import com.google.devtools.build.lib.packages.Attribute.ValidityPredicate;
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.packages.RuleClass;
Expand Down Expand Up @@ -115,12 +114,7 @@ public String checkValid(Rule from, Rule to) {
return null;
}
}))
// TODO(https://github.com/bazelbuild/bazel/issues/14727): Evaluate whether this can be
// optional.
.addToolchainTypes(
ToolchainTypeRequirement.builder(CppRuleClasses.ccToolchainTypeAttribute(env))
.mandatory(true)
.build())
.addToolchainTypes(CppRuleClasses.ccToolchainTypeRequirement(env))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.config.ToolchainTypeRequirement;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
Expand All @@ -43,12 +42,7 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment envi
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(
attr("archives", LABEL_LIST).mandatory().nonEmpty().allowedFileTypes(FileType.of(".a")))
// TODO(https://github.com/bazelbuild/bazel/issues/14727): Evaluate whether this can be
// optional.
.addToolchainTypes(
ToolchainTypeRequirement.builder(CppRuleClasses.ccToolchainTypeAttribute(environment))
.mandatory(true)
.build())
.addToolchainTypes(CppRuleClasses.ccToolchainTypeRequirement(environment))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.config.ToolchainTypeRequirement;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
Expand All @@ -34,12 +33,7 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env)
return builder
.requiresConfigurationFragments(
AppleConfiguration.class, CppConfiguration.class, ObjcConfiguration.class)
// TODO(https://github.com/bazelbuild/bazel/issues/14727): Evaluate whether this can be
// optional.
.addToolchainTypes(
ToolchainTypeRequirement.builder(CppRuleClasses.ccToolchainTypeAttribute(env))
.mandatory(true)
.build())
.addToolchainTypes(CppRuleClasses.ccToolchainTypeRequirement(env))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
import com.google.devtools.build.lib.analysis.config.ExecutionTransitionFactory;
import com.google.devtools.build.lib.analysis.config.ToolchainTypeRequirement;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.packages.ImplicitOutputsFunction.SafeImplicitOutputsFunction;
import com.google.devtools.build.lib.packages.RuleClass;
Expand Down Expand Up @@ -312,12 +311,7 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env)
.add(
attr(CcToolchain.CC_TOOLCHAIN_TYPE_ATTRIBUTE_NAME, NODEP_LABEL)
.value(CppRuleClasses.ccToolchainTypeAttribute(env)))
// TODO(https://github.com/bazelbuild/bazel/issues/14727): Evaluate whether this can be
// optional.
.addToolchainTypes(
ToolchainTypeRequirement.builder(CppRuleClasses.ccToolchainTypeAttribute(env))
.mandatory(true)
.build())
.addToolchainTypes(CppRuleClasses.ccToolchainTypeRequirement(env))
.build();
}

Expand Down

0 comments on commit a54a1a7

Please sign in to comment.