Skip to content

Commit

Permalink
Cleanup unused java rules code
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 702674779
Change-Id: I837984c08fac0e1090161bb4652e29eab45928c9
  • Loading branch information
hvadehra authored and copybara-github committed Dec 4, 2024
1 parent 75ca6db commit eae9d4d
Show file tree
Hide file tree
Showing 21 changed files with 25 additions and 3,644 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package com.google.devtools.build.lib.rules.java;

import static com.google.devtools.build.lib.skyframe.BzlLoadValue.keyForBuild;
import static com.google.devtools.build.lib.skyframe.BzlLoadValue.keyForBuiltins;

import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.cmdline.Label;
Expand All @@ -38,9 +37,6 @@
public class BootClassPathInfo extends StarlarkInfoWrapper {

/** Provider singleton constant. */
public static final StarlarkProviderWrapper<BootClassPathInfo> LEGACY_BUILTINS_PROVIDER =
new BuiltinsProvider();

public static final StarlarkProviderWrapper<BootClassPathInfo> PROVIDER = new Provider();
public static final StarlarkProviderWrapper<BootClassPathInfo> RULES_JAVA_PROVIDER =
new RulesJavaProvider();
Expand Down Expand Up @@ -87,8 +83,6 @@ public static BootClassPathInfo wrap(Info info) throws RuleErrorException {
com.google.devtools.build.lib.packages.Provider.Key key = info.getProvider().getKey();
if (key.equals(PROVIDER.getKey())) {
return PROVIDER.wrap(info);
} else if (key.equals(LEGACY_BUILTINS_PROVIDER.getKey())) {
return LEGACY_BUILTINS_PROVIDER.wrap(info);
} else if (key.equals(RULES_JAVA_PROVIDER.getKey())) {
return RULES_JAVA_PROVIDER.wrap(info);
} else if (key.equals(WORKSPACE_PROVIDER.getKey())) {
Expand Down Expand Up @@ -129,14 +123,6 @@ && systemInputs().isEmpty()
&& systemPath().isEmpty();
}

private static class BuiltinsProvider extends Provider {
private BuiltinsProvider() {
super(
keyForBuiltins(
Label.parseCanonicalUnchecked("@_builtins//:common/java/boot_class_path_info.bzl")));
}
}

private static class RulesJavaProvider extends Provider {
private RulesJavaProvider() {
super(keyForBuild(Label.parseCanonicalUnchecked("//java/private:boot_class_path_info.bzl")));
Expand Down
103 changes: 5 additions & 98 deletions src/main/java/com/google/devtools/build/lib/rules/java/JavaInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package com.google.devtools.build.lib.rules.java;

import static com.google.devtools.build.lib.skyframe.BzlLoadValue.keyForBuild;
import static com.google.devtools.build.lib.skyframe.BzlLoadValue.keyForBuiltins;
import static com.google.devtools.build.lib.unsafe.UnsafeProvider.unsafe;

import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -69,13 +68,10 @@
@Immutable
public sealed class JavaInfo extends NativeInfo
implements JavaInfoApi<Artifact, JavaOutput, JavaPluginData>
permits JavaInfo.BuiltinsJavaInfo, JavaInfo.RulesJavaJavaInfo, JavaInfo.WorkspaceJavaInfo {
permits JavaInfo.RulesJavaJavaInfo, JavaInfo.WorkspaceJavaInfo {

public static final String STARLARK_NAME = "JavaInfo";

@SerializationConstant
public static final JavaInfoProvider LEGACY_BUILTINS_PROVIDER = new BuiltinsJavaInfoProvider();

// Not serialized
public static final JavaInfoProvider RULES_JAVA_PROVIDER = new RulesJavaJavaInfoProvider();
// Not serialized
Expand Down Expand Up @@ -146,8 +142,6 @@ static <T> T nullIfNone(Object object, Class<T> type) {
}

static final JavaInfo EMPTY_JAVA_INFO_FOR_TESTING = Builder.create().build();
static final BuiltinsJavaInfo EMPTY_BUILTINS_JAVA_INFO_FOR_TESTING =
(BuiltinsJavaInfo) new Builder().setProvider(LEGACY_BUILTINS_PROVIDER).build();

private final JavaCompilationArgsProvider providerJavaCompilationArgs;
private final JavaSourceJarsProvider providerJavaSourceJars;
Expand Down Expand Up @@ -218,9 +212,6 @@ public static <T extends JavaInfoInternalProvider> T getProvider(

public static JavaInfo getJavaInfo(TransitiveInfoCollection target) throws RuleErrorException {
JavaInfo info = target.get(PROVIDER);
if (info == null) {
info = target.get(LEGACY_BUILTINS_PROVIDER);
}
if (info == null) {
info = target.get(RULES_JAVA_PROVIDER);
}
Expand All @@ -232,9 +223,7 @@ public static JavaInfo getJavaInfo(TransitiveInfoCollection target) throws RuleE

public static JavaInfo wrap(Info info) throws RuleErrorException {
Provider.Key key = info.getProvider().getKey();
if (key.equals(LEGACY_BUILTINS_PROVIDER.getKey())) {
return LEGACY_BUILTINS_PROVIDER.wrap(info);
} else if (key.equals(RULES_JAVA_PROVIDER.getKey())) {
if (key.equals(RULES_JAVA_PROVIDER.getKey())) {
return RULES_JAVA_PROVIDER.wrap(info);
} else if (key.equals(WORKSPACE_PROVIDER.getKey())) {
return WORKSPACE_PROVIDER.wrap(info);
Expand Down Expand Up @@ -516,48 +505,6 @@ public int hashCode() {
providerJavaPlugin);
}

@VisibleForTesting // package-private for testing.
static final class BuiltinsJavaInfo extends JavaInfo {

private BuiltinsJavaInfo(StructImpl javaInfo)
throws EvalException, TypeException, RuleErrorException {
super(javaInfo);
}

private BuiltinsJavaInfo(
JavaCcInfoProvider javaCcInfoProvider,
JavaCompilationArgsProvider javaCompilationArgsProvider,
JavaCompilationInfoProvider javaCompilationInfoProvider,
JavaGenJarsProvider javaGenJarsProvider,
JavaModuleFlagsProvider javaModuleFlagsProvider,
JavaPluginInfo javaPluginInfo,
JavaRuleOutputJarsProvider javaRuleOutputJarsProvider,
JavaSourceJarsProvider javaSourceJarsProvider,
ImmutableList<Artifact> directRuntimeJars,
boolean neverlink,
ImmutableList<String> javaConstraints,
Location creationLocation) {
super(
javaCcInfoProvider,
javaCompilationArgsProvider,
javaCompilationInfoProvider,
javaGenJarsProvider,
javaModuleFlagsProvider,
javaPluginInfo,
javaRuleOutputJarsProvider,
javaSourceJarsProvider,
directRuntimeJars,
neverlink,
javaConstraints,
creationLocation);
}

@Override
public JavaInfoProvider getProvider() {
return LEGACY_BUILTINS_PROVIDER;
}
}

static final class RulesJavaJavaInfo extends JavaInfo {

private RulesJavaJavaInfo(StructImpl javaInfo)
Expand Down Expand Up @@ -612,20 +559,6 @@ public JavaInfoProvider getProvider() {
}
}

/** Legacy Provider class for {@link JavaInfo} objects. */
public static final class BuiltinsJavaInfoProvider extends JavaInfoProvider {
private BuiltinsJavaInfoProvider() {
super(
keyForBuiltins(Label.parseCanonicalUnchecked("@_builtins//:common/java/java_info.bzl")));
}

@Override
protected JavaInfo makeNewInstance(StructImpl info)
throws RuleErrorException, TypeException, EvalException {
return new BuiltinsJavaInfo(info);
}
}

/** Legacy Provider class for {@link JavaInfo} objects. */
public static final class RulesJavaJavaInfoProvider extends JavaInfoProvider {
private RulesJavaJavaInfoProvider() {
Expand Down Expand Up @@ -654,8 +587,7 @@ protected JavaInfo makeNewInstance(StructImpl info)

/** Provider class for {@link JavaInfo} objects. */
public static sealed class JavaInfoProvider extends StarlarkProviderWrapper<JavaInfo>
implements Provider
permits BuiltinsJavaInfoProvider, RulesJavaJavaInfoProvider, WorkspaceJavaInfoProvider {
implements Provider permits RulesJavaJavaInfoProvider, WorkspaceJavaInfoProvider {
private JavaInfoProvider() {
this(
keyForBuild(
Expand Down Expand Up @@ -778,21 +710,7 @@ public Builder setProvider(Provider provider) {
}

public JavaInfo build() {
if (provider.getKey().equals(LEGACY_BUILTINS_PROVIDER.getKey())) {
return new BuiltinsJavaInfo(
/* javaCcInfoProvider= */ null,
providerJavaCompilationArgs,
providerJavaCompilationInfo,
/* javaGenJarsProvider= */ null,
/* javaModuleFlagsProvider= */ null,
/* javaPluginInfo= */ null,
providerJavaRuleOutputJars,
providerJavaSourceJars,
runtimeJars,
neverlink,
javaConstraints,
creationLocation);
} else if (provider.getKey().equals(WORKSPACE_PROVIDER.getKey())) {
if (provider.getKey().equals(WORKSPACE_PROVIDER.getKey())) {
return new WorkspaceJavaInfo(
/* javaCcInfoProvider= */ null,
providerJavaCompilationArgs,
Expand Down Expand Up @@ -877,14 +795,6 @@ public Class<? extends JavaInfo> getEncodedClass() {
@Override
public void serialize(SerializationContext context, JavaInfo obj, CodedOutputStream codedOut)
throws SerializationException, IOException {
switch (obj.getProvider()) {
case BuiltinsJavaInfoProvider unused -> codedOut.writeBoolNoTag(true);
case RulesJavaJavaInfoProvider unused ->
throw new UnsupportedOperationException("not implemented");
case WorkspaceJavaInfoProvider unused ->
throw new UnsupportedOperationException("not implemented");
case JavaInfoProvider unused -> codedOut.writeBoolNoTag(false);
}
for (FieldHandler handler : handlers) {
handler.serialize(context, codedOut, obj);
}
Expand All @@ -898,10 +808,7 @@ public DeferredValue<JavaInfo> deserializeDeferred(

JavaInfo obj;
try {
obj =
codedIn.readBool()
? (BuiltinsJavaInfo) unsafe().allocateInstance(BuiltinsJavaInfo.class)
: (JavaInfo) unsafe().allocateInstance(JavaInfo.class);
obj = (JavaInfo) unsafe().allocateInstance(JavaInfo.class);
} catch (InstantiationException e) {
throw new SerializationException("Could not instantiate JavaInfo with Unsafe", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package com.google.devtools.build.lib.rules.java;

import static com.google.devtools.build.lib.skyframe.BzlLoadValue.keyForBuild;
import static com.google.devtools.build.lib.skyframe.BzlLoadValue.keyForBuiltins;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -43,8 +42,6 @@ public final class JavaPackageConfigurationProvider implements StarlarkValue {

private static final StarlarkProviderWrapper<JavaPackageConfigurationProvider> PROVIDER =
new Provider();
private static final StarlarkProviderWrapper<JavaPackageConfigurationProvider> BUILTINS_PROVIDER =
new BuiltinsProvider();

private final StructImpl underlying;

Expand All @@ -55,11 +52,7 @@ private JavaPackageConfigurationProvider(StructImpl underlying) {
@VisibleForTesting
public static JavaPackageConfigurationProvider get(ConfiguredTarget target)
throws RuleErrorException {
JavaPackageConfigurationProvider info = target.get(PROVIDER);
if (info == null) {
info = target.get(BUILTINS_PROVIDER);
}
return info;
return target.get(PROVIDER);
}

/** Package specifications for which the configuration should be applied. */
Expand Down Expand Up @@ -135,16 +128,6 @@ public JavaPackageConfigurationProvider wrap(Info value) throws RuleErrorExcepti
}
}

private static class BuiltinsProvider extends JavaPackageConfigurationProvider.Provider {

private BuiltinsProvider() {
super(
keyForBuiltins(
Label.parseCanonicalUnchecked(
"@_builtins//:common/java/java_package_configuration.bzl")));
}
}

static ImmutableList<JavaPackageConfigurationProvider> wrapSequence(Sequence<StructImpl> sequence)
throws RuleErrorException {
ImmutableList.Builder<JavaPackageConfigurationProvider> builder = ImmutableList.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package com.google.devtools.build.lib.rules.java;

import static com.google.devtools.build.lib.skyframe.BzlLoadValue.keyForBuild;
import static com.google.devtools.build.lib.skyframe.BzlLoadValue.keyForBuiltins;

import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -50,18 +49,10 @@
public abstract class JavaPluginInfo extends NativeInfo
implements JavaPluginInfoApi<Artifact, JavaPluginData, JavaOutput> {
public static final String PROVIDER_NAME = "JavaPluginInfo";
public static final Provider LEGACY_BUILTINS_PROVIDER = new BuiltinsProvider();
public static final Provider PROVIDER = new Provider();
public static final Provider RULES_JAVA_PROVIDER = new RulesJavaProvider();
public static final Provider WORKSPACE_PROVIDER = new WorkspaceProvider();

private static final JavaPluginInfo EMPTY_BUILTIN =
new AutoValue_JavaPluginInfo(
ImmutableList.of(),
JavaPluginData.empty(),
JavaPluginData.empty(),
LEGACY_BUILTINS_PROVIDER);

private static final JavaPluginInfo EMPTY =
new AutoValue_JavaPluginInfo(
ImmutableList.of(), JavaPluginData.empty(), JavaPluginData.empty(), PROVIDER);
Expand All @@ -75,42 +66,22 @@ public abstract class JavaPluginInfo extends NativeInfo
ImmutableList.of(), JavaPluginData.empty(), JavaPluginData.empty(), WORKSPACE_PROVIDER);

public static JavaPluginInfo wrap(Info info) throws RuleErrorException {
com.google.devtools.build.lib.packages.Provider.Key key = info.getProvider().getKey();
// this wrapped instance is not propagated back to Starlark, so we don't need every type
// we just use the two types that are checked for in tests
if (key.equals(LEGACY_BUILTINS_PROVIDER.getKey())) {
return LEGACY_BUILTINS_PROVIDER.wrap(info);
} else {
return PROVIDER.wrap(info);
}
// we just use the single type that is checked for in tests
return PROVIDER.wrap(info);
}

@VisibleForTesting
public static JavaPluginInfo get(ConfiguredTarget target) throws RuleErrorException {
// we just use the two types that are checked for in tests
JavaPluginInfo info = target.get(PROVIDER);
JavaPluginInfo builtinInfo = target.get(LEGACY_BUILTINS_PROVIDER);
if (info == null) {
return builtinInfo;
} else if (builtinInfo == null) {
return info;
}
return mergeWithoutJavaOutputs(info, builtinInfo);
// we just use the single type that is checked for in tests
return target.get(PROVIDER);
}

@Override
public com.google.devtools.build.lib.packages.Provider getProvider() {
return providerType();
}

/** Legacy Provider class for {@link JavaPluginInfo} objects. */
public static class BuiltinsProvider extends Provider {
private BuiltinsProvider() {
super(
keyForBuiltins(Label.parseCanonicalUnchecked("@_builtins//:common/java/java_info.bzl")));
}
}

/** Provider class for {@link JavaPluginInfo} objects in rules_java itself. */
public static class RulesJavaProvider extends Provider {
private RulesJavaProvider() {
Expand Down Expand Up @@ -290,9 +261,7 @@ public static JavaPluginInfo mergeWithoutJavaOutputs(
}

public static JavaPluginInfo empty(com.google.devtools.build.lib.packages.Provider providerType) {
if (providerType.equals(LEGACY_BUILTINS_PROVIDER)) {
return EMPTY_BUILTIN;
} else if (providerType.equals(RULES_JAVA_PROVIDER)) {
if (providerType.equals(RULES_JAVA_PROVIDER)) {
return EMPTY_RULES_JAVA;
} else if (providerType.equals(WORKSPACE_PROVIDER)) {
return EMPTY_WORKSPACE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment envi
ImmutableList.of(
ImmutableList.of(JavaPluginInfo.PROVIDER.id()),
ImmutableList.of(JavaPluginInfo.RULES_JAVA_PROVIDER.id()),
ImmutableList.of(JavaPluginInfo.WORKSPACE_PROVIDER.id()),
ImmutableList.of(JavaPluginInfo.LEGACY_BUILTINS_PROVIDER.id())))
ImmutableList.of(JavaPluginInfo.WORKSPACE_PROVIDER.id())))
.silentRuleClassFilter()
.value(JavaSemantics.JAVA_PLUGINS))
.build();
Expand Down Expand Up @@ -88,12 +87,6 @@ public ConfiguredTarget create(RuleContext ruleContext)
ruleContext
.getRulePrerequisitesCollection()
.getPrerequisites(":java_plugins", JavaPluginInfo.PROVIDER);
if (plugins.isEmpty()) {
plugins =
ruleContext
.getRulePrerequisitesCollection()
.getPrerequisites(":java_plugins", JavaPluginInfo.LEGACY_BUILTINS_PROVIDER);
}
if (plugins.isEmpty()) {
plugins =
ruleContext
Expand All @@ -108,16 +101,13 @@ public ConfiguredTarget create(RuleContext ruleContext)
}
JavaPluginInfo javaPluginInfo =
JavaPluginInfo.mergeWithoutJavaOutputs(plugins, JavaPluginInfo.PROVIDER);
JavaPluginInfo builtinsProviderInfo =
JavaPluginInfo.mergeWithoutJavaOutputs(plugins, JavaPluginInfo.LEGACY_BUILTINS_PROVIDER);
JavaPluginInfo rulesJavaProviderInfo =
JavaPluginInfo.mergeWithoutJavaOutputs(plugins, JavaPluginInfo.RULES_JAVA_PROVIDER);
JavaPluginInfo workspaceProviderInfo =
JavaPluginInfo.mergeWithoutJavaOutputs(plugins, JavaPluginInfo.WORKSPACE_PROVIDER);

return new RuleConfiguredTargetBuilder(ruleContext)
.addStarlarkDeclaredProvider(javaPluginInfo)
.addStarlarkDeclaredProvider(builtinsProviderInfo)
.addStarlarkDeclaredProvider(rulesJavaProviderInfo)
.addStarlarkDeclaredProvider(workspaceProviderInfo)
.addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY)
Expand Down
Loading

0 comments on commit eae9d4d

Please sign in to comment.