Skip to content

Commit

Permalink
Make JavaRuntimeInfo extend ToolchainInfo, and delete JavaRuntimeTool…
Browse files Browse the repository at this point in the history
…chainInfo

PiperOrigin-RevId: 231880172
  • Loading branch information
cushon authored and Copybara-Service committed Feb 1, 2019
1 parent 698c91d commit 4a55d41
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib:skylarkinterface",
"//src/main/java/com/google/devtools/build/lib:util",
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/lib/analysis/platform",
"//src/main/java/com/google/devtools/build/lib/collect/nestedset",
"//src/main/java/com/google/devtools/build/lib/concurrent",
"//src/main/java/com/google/devtools/build/lib/rules/cpp",
Expand Down Expand Up @@ -106,7 +107,6 @@ java_library(
"JavaRuleOutputJarsProvider.java",
"JavaRunfilesProvider.java",
"JavaRuntimeInfo.java",
"JavaRuntimeToolchainInfo.java",
"JavaSemantics.java",
"JavaSkylarkApiProvider.java",
"JavaSkylarkCommon.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.config.HostTransition;
import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
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;
Expand All @@ -29,6 +30,6 @@ public JavaHostRuntimeAliasRule() {
@Override
protected Attribute.Builder<Label> makeAttribute(RuleDefinitionEnvironment environment) {
Attribute.Builder<Label> builder = super.makeAttribute(environment);
return builder.cfg(HostTransition.INSTANCE).mandatoryProviders(JavaRuntimeInfo.PROVIDER.id());
return builder.cfg(HostTransition.INSTANCE).mandatoryProviders(ToolchainInfo.PROVIDER.id());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env)
.add(
attr(":jvm", LABEL)
.value(JavaSemantics.jvmAttribute(env))
.mandatoryProviders(JavaRuntimeInfo.PROVIDER.id())
.mandatoryProviders(ToolchainInfo.PROVIDER.id())
.useOutputLicenses())
.add(
attr(":host_jdk", LABEL)
.cfg(HostTransition.INSTANCE)
.value(JavaSemantics.hostJdkAttribute(env))
.mandatoryProviders(JavaRuntimeInfo.PROVIDER.id()))
.mandatoryProviders(ToolchainInfo.PROVIDER.id()))
.add(
attr(JAVA_RUNTIME_TOOLCHAIN_TYPE_ATTRIBUTE_NAME, NODEP_LABEL)
.value(JavaRuleClasses.javaRuntimeTypeAttribute(env)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ public ConfiguredTarget create(RuleContext ruleContext)
.addProvider(RunfilesProvider.class, RunfilesProvider.simple(runfiles))
.setFilesToBuild(filesToBuild)
.addNativeDeclaredProvider(javaRuntime)
.addNativeDeclaredProvider(new JavaRuntimeToolchainInfo(javaRuntime))
.addNativeDeclaredProvider(templateVariableInfo)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.google.devtools.build.lib.rules.java;

import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
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;
Expand All @@ -28,6 +29,6 @@ public JavaRuntimeAliasRule() {
@Override
protected Attribute.Builder<Label> makeAttribute(RuleDefinitionEnvironment environment) {
Attribute.Builder<Label> builder = super.makeAttribute(environment);
return builder.mandatoryProviders(JavaRuntimeInfo.PROVIDER.id());
return builder.mandatoryProviders(ToolchainInfo.PROVIDER.id());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static com.google.devtools.build.lib.packages.BuildType.NODEP_LABEL;
import static com.google.devtools.build.lib.rules.java.JavaRuleClasses.JAVA_RUNTIME_TOOLCHAIN_TYPE_ATTRIBUTE_NAME;

import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.PlatformOptions;
import com.google.devtools.build.lib.analysis.RuleContext;
Expand All @@ -27,9 +28,8 @@
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.NativeInfo;
import com.google.devtools.build.lib.packages.NativeProvider;
import com.google.devtools.build.lib.packages.RuleErrorConsumer;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization;
Expand All @@ -40,11 +40,7 @@
/** Information about the Java runtime used by the <code>java_*</code> rules. */
@Immutable
@AutoCodec
public class JavaRuntimeInfo extends NativeInfo implements JavaRuntimeInfoApi {
public static final String SKYLARK_NAME = "JavaRuntimeInfo";

public static final NativeProvider<JavaRuntimeInfo> PROVIDER =
new NativeProvider<JavaRuntimeInfo>(JavaRuntimeInfo.class, SKYLARK_NAME) {};
public class JavaRuntimeInfo extends ToolchainInfo implements JavaRuntimeInfoApi {

public static JavaRuntimeInfo create(
NestedSet<Artifact> javaBaseInputs,
Expand Down Expand Up @@ -95,8 +91,8 @@ private static JavaRuntimeInfo from(
if (toolchainType != null && useToolchainResolutionForJavaRules) {
ToolchainInfo toolchainInfo =
ruleContext.getToolchainContext().forToolchainType(toolchainType);
if (toolchainInfo instanceof JavaRuntimeToolchainInfo) {
return ((JavaRuntimeToolchainInfo) toolchainInfo).javaRuntime();
if (toolchainInfo instanceof JavaRuntimeInfo) {
return (JavaRuntimeInfo) toolchainInfo;
}
}

Expand All @@ -116,7 +112,7 @@ private static JavaRuntimeInfo from(
@Nullable
protected static JavaRuntimeInfo from(
TransitiveInfoCollection collection, RuleErrorConsumer errorConsumer) {
return collection.get(JavaRuntimeInfo.PROVIDER);
return (JavaRuntimeInfo) collection.get(ToolchainInfo.PROVIDER);
}

private final NestedSet<Artifact> javaBaseInputs;
Expand All @@ -135,7 +131,7 @@ protected static JavaRuntimeInfo from(
PathFragment javaBinaryExecPath,
PathFragment javaHomeRunfilesPath,
PathFragment javaBinaryRunfilesPath) {
super(PROVIDER);
super(ImmutableMap.of(), Location.BUILTIN);
this.javaBaseInputs = javaBaseInputs;
this.javaBaseInputsMiddleman = javaBaseInputsMiddleman;
this.javaHome = javaHome;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.PlatformOptions;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
import com.google.devtools.build.lib.analysis.skylark.SkylarkActionFactory;
import com.google.devtools.build.lib.analysis.skylark.SkylarkRuleContext;
import com.google.devtools.build.lib.cmdline.Label;
Expand Down Expand Up @@ -230,12 +231,12 @@ public JavaInfo makeNonStrict(JavaInfo javaInfo) {

@Override
public Provider getJavaToolchainProvider() {
return JavaToolchainProvider.PROVIDER;
return ToolchainInfo.PROVIDER;
}

@Override
public Provider getJavaRuntimeProvider() {
return JavaRuntimeInfo.PROVIDER;
return ToolchainInfo.PROVIDER;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
import com.google.devtools.build.lib.analysis.config.HostTransition;
import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget;
import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
Expand All @@ -45,7 +46,6 @@
import com.google.devtools.build.lib.rules.java.JavaConfiguration;
import com.google.devtools.build.lib.rules.java.JavaRuleClasses;
import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider;
import com.google.devtools.build.lib.rules.java.JavaRuntimeInfo;
import com.google.devtools.build.lib.rules.java.JavaSemantics;
import com.google.devtools.build.lib.rules.java.JavaSkylarkApiProvider;
import com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider;
Expand Down Expand Up @@ -132,7 +132,7 @@ public AspectDefinition getDefinition(AspectParameters aspectParameters) {
attr(":host_jdk", LABEL)
.cfg(HostTransition.INSTANCE)
.value(hostJdkAttribute)
.mandatoryProviders(JavaRuntimeInfo.PROVIDER.id()))
.mandatoryProviders(ToolchainInfo.PROVIDER.id()))
.add(
attr(JavaRuleClasses.JAVA_TOOLCHAIN_ATTRIBUTE_NAME, LABEL)
.useOutputLicenses()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@

package com.google.devtools.build.lib.skylarkbuildapi.java;

import com.google.devtools.build.lib.skylarkbuildapi.StructApi;
import com.google.devtools.build.lib.skylarkbuildapi.platform.ToolchainInfoApi;
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.vfs.PathFragment;

/**
* Information about the Java runtime being used.
*/
/** Information about the Java runtime being used. */
@SkylarkModule(name = "JavaRuntimeInfo", doc = "Information about the Java runtime being used.")
public interface JavaRuntimeInfoApi extends StructApi {
public interface JavaRuntimeInfoApi extends ToolchainInfoApi {

@SkylarkCallable(
name = "java_home",
Expand Down

0 comments on commit 4a55d41

Please sign in to comment.