Skip to content

Commit

Permalink
Remove the cc_common.cc_toolchain_attr and java_common.java_runtime_a…
Browse files Browse the repository at this point in the history
…ttr in favor of the cc_toolchain_alias() and the java_runtime_alias() rules introduced in 4409199.

These two serve the same purpose; the attributes were originally introduced in 28c9617 and 4634ff9 respectively in order to avoid introducing the magic rule classes. However, the magic rule classes needed to be introduced anyway so that existing rules can declare which Make variables they use and there is no point in having two mechanisms to do the same thing.

RELNOTES[INC]: cc_common.cc_toolchain_attr and java_common.java_runtime_attr are not supported anymore and were replaced with the cc_toolchain_alias() and java_runtime_alias() rules.

PiperOrigin-RevId: 161799608
  • Loading branch information
lberki authored and laszlocsomor committed Jul 14, 2017
1 parent 597fb75 commit bc6769b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ public void init(Builder builder) {
builder.addRuleDefinition(new AndroidDeviceRule());

builder.addSkylarkAccessibleTopLevels("android_common", new AndroidSkylarkCommon());
builder.addSkylarkAccessibleTopLevels("java_common", new JavaSkylarkCommon(
BazelJavaSemantics.INSTANCE, builder.getToolsRepository()));
builder.addSkylarkAccessibleTopLevels("java_common",
new JavaSkylarkCommon(BazelJavaSemantics.INSTANCE));
builder.addSkylarkAccessibleTopLevels("java_proto_common", JavaProtoSkylarkCommon.class);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.MiddlemanProvider;
import com.google.devtools.build.lib.analysis.RuleContext;
Expand All @@ -25,10 +24,7 @@
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.packages.Attribute;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.ClassObjectConstructor;
import com.google.devtools.build.lib.rules.SkylarkAttr;
import com.google.devtools.build.lib.rules.SkylarkRuleContext;
import com.google.devtools.build.lib.rules.java.proto.StrictDepsUtils;
import com.google.devtools.build.lib.skylarkinterface.Param;
Expand All @@ -44,11 +40,9 @@
@SkylarkModule(name = "java_common", doc = "Utilities for Java compilation support in Skylark.")
public class JavaSkylarkCommon {
private final JavaSemantics javaSemantics;
private final String toolsRepository;

public JavaSkylarkCommon(JavaSemantics javaSemantics, String toolsrepository) {
public JavaSkylarkCommon(JavaSemantics javaSemantics) {
this.javaSemantics = javaSemantics;
this.toolsRepository = toolsrepository;
}

@SkylarkCallable(
Expand Down Expand Up @@ -468,20 +462,4 @@ private static StrictDepsMode getStrictDepsMode(String strictDepsMode) {
public static ClassObjectConstructor getJavaRuntimeProvider() {
return JavaRuntimeProvider.SKYLARK_CONSTRUCTOR;
}

@SkylarkCallable(
name = "java_runtime_attr",
doc = "A value that, when passed as a value in the attribute dictionary of a rule "
+ "definition, will yield a dependency that describes the current Java runtime in use.",
documented = false,
structField = true
)
public SkylarkAttr.Descriptor getJvmAttribute() {
ConfiguredRuleClassProvider.Builder env = new ConfiguredRuleClassProvider.Builder();
env.setToolsRepository(toolsRepository);
return new SkylarkAttr.Descriptor(
"java_runtime_attr",
new Attribute.Builder<>("", BuildType.LABEL)
.value(JavaSemantics.jvmAttribute(env)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void testJavaRuntimeProvider() throws Exception {
"load(':rule.bzl', 'jrule')",
"java_runtime(name='jvm', srcs=[], java_home='/foo/bar/')",
"java_runtime_suite(name='suite', default=':jvm')",
"java_runtime_alias(name='alias')",
"jrule(name='r')");

scratch.file(
Expand All @@ -58,7 +59,7 @@ public void testJavaRuntimeProvider() throws Exception {
" return struct(",
" java_executable = provider.java_executable_exec_path,",
")",
"jrule = rule(_impl, attrs = { '_java_runtime': java_common.java_runtime_attr})");
"jrule = rule(_impl, attrs = { '_java_runtime': attr.label(default=Label('//a:alias'))})");

useConfiguration("--javabase=//a:suite");
ConfiguredTarget ct = getConfiguredTarget("//a:r");
Expand Down

0 comments on commit bc6769b

Please sign in to comment.