Skip to content

Commit

Permalink
Remove support for javabase and java_toolchain flags.
Browse files Browse the repository at this point in the history
Removes JavaRuntimeAliasRule, JavaToolchainAliasRule and its targets. Makes javabase and java_toolchain flags a no-op. Removes backwards support from java_toolchain_alias, java_runtime_alias, java_runtime_version_alias.

Closes #12704.

PiperOrigin-RevId: 391502514
  • Loading branch information
comius authored and copybara-github committed Aug 18, 2021
1 parent d21345d commit e1c404e
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@
import com.google.devtools.build.lib.rules.java.JavaRuleClasses.IjarBaseRule;
import com.google.devtools.build.lib.rules.java.JavaRuleClasses.JavaRuntimeBaseRule;
import com.google.devtools.build.lib.rules.java.JavaRuleClasses.JavaToolchainBaseRule;
import com.google.devtools.build.lib.rules.java.JavaRuntimeAliasRule;
import com.google.devtools.build.lib.rules.java.JavaRuntimeRule;
import com.google.devtools.build.lib.rules.java.JavaStarlarkCommon;
import com.google.devtools.build.lib.rules.java.JavaToolchainAliasRule;
import com.google.devtools.build.lib.rules.java.JavaToolchainRule;
import com.google.devtools.build.lib.rules.java.ProguardLibraryRule;
import com.google.devtools.build.lib.rules.java.ProguardSpecProvider;
Expand Down Expand Up @@ -81,8 +79,6 @@ public void init(ConfiguredRuleClassProvider.Builder builder) {
builder.addRuleDefinition(JavaToolchainRule.create(BazelJavaToolchain.class));
builder.addRuleDefinition(new JavaPackageConfigurationRule());
builder.addRuleDefinition(new JavaRuntimeRule());
builder.addRuleDefinition(new JavaRuntimeAliasRule());
builder.addRuleDefinition(new JavaToolchainAliasRule());
builder.addRuleDefinition(new JavaPluginsFlagAliasRule());

builder.addRuleDefinition(new ExtraActionRule());
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/google/devtools/build/lib/rules/java/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ java_library(
"JavaPluginsFlagAliasRule.java",
"JavaPrimaryClassProvider.java",
"JavaRuntime.java",
"JavaRuntimeAliasRule.java",
"JavaRuntimeClasspathProvider.java",
"JavaRuntimeRule.java",
"JavaStarlarkCommon.java",
"JavaToolchain.java",
"JavaToolchainAliasRule.java",
"JavaToolchainRule.java",
"ProguardLibrary.java",
"ProguardLibraryRule.java",
Expand All @@ -47,7 +45,6 @@ java_library(
deps = [
":RpcSupport",
":java-compilation",
":java-implicit-attributes",
"//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/actions:execution_requirements",
Expand Down Expand Up @@ -77,7 +74,6 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/concurrent",
"//src/main/java/com/google/devtools/build/lib/packages",
"//src/main/java/com/google/devtools/build/lib/packages/semantics",
"//src/main/java/com/google/devtools/build/lib/rules:alias",
"//src/main/java/com/google/devtools/build/lib/rules/apple",
"//src/main/java/com/google/devtools/build/lib/rules/cpp",
"//src/main/java/com/google/devtools/build/lib/rules/proto",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.starlarkbuildapi.java.JavaConfigurationApi;
import java.util.Map;
import java.util.Objects;
import javax.annotation.Nullable;

/** A java compiler configuration containing the flags required for compilation. */
Expand Down Expand Up @@ -94,16 +93,13 @@ public enum ImportDepsCheckingLevel {
private final NamedLabel bytecodeOptimizer;
private final boolean splitBytecodeOptimizationPass;
private final boolean enforceProguardFileExtension;
private final Label toolchainLabel;
private final Label runtimeLabel;
private final boolean runAndroidLint;
private final boolean limitAndroidLintToAndroidCompatible;
private final boolean explicitJavaTestDeps;
private final boolean jplPropagateCcLinkParamsStore;
private final boolean addTestSupportToCompileTimeDeps;
private final ImmutableList<Label> pluginList;
private final boolean disallowResourceJars;
private final boolean disallowLegacyJavaToolchainFlags;
private final boolean experimentalTurbineAnnotationProcessing;
private final boolean experimentalEnableJspecify;
private final boolean requireJavaPluginInfo;
Expand All @@ -129,8 +125,6 @@ public JavaConfiguration(BuildOptions buildOptions) throws InvalidConfigurationE
this.extraProguardSpecs = ImmutableList.copyOf(javaOptions.extraProguardSpecs);
this.splitBytecodeOptimizationPass = javaOptions.splitBytecodeOptimizationPass;
this.enforceProguardFileExtension = javaOptions.enforceProguardFileExtension;
this.toolchainLabel = javaOptions.javaToolchain;
this.runtimeLabel = javaOptions.javaBase;
this.useLegacyBazelJavaTest = javaOptions.legacyBazelJavaTest;
this.strictDepsJavaProtos = javaOptions.strictDepsJavaProtos;
this.isDisallowStrictDepsForJpl = javaOptions.isDisallowStrictDepsForJpl;
Expand Down Expand Up @@ -163,26 +157,21 @@ public JavaConfiguration(BuildOptions buildOptions) throws InvalidConfigurationE
this.bytecodeOptimizer = NamedLabel.create(mnemonic, Optional.fromNullable(optimizerLabel));

this.pluginList = ImmutableList.copyOf(javaOptions.pluginList);
this.disallowLegacyJavaToolchainFlags = javaOptions.disallowLegacyJavaToolchainFlags;
this.experimentalTurbineAnnotationProcessing =
javaOptions.experimentalTurbineAnnotationProcessing;
this.experimentalEnableJspecify = javaOptions.experimentalEnableJspecify;

if (javaOptions.disallowLegacyJavaToolchainFlags) {
checkLegacyToolchainFlagIsUnset(
"javabase", javaOptions.javaBase, javaOptions.defaultJavaBase());
checkLegacyToolchainFlagIsUnset(
"host_javabase", javaOptions.getHostJavaBase(), javaOptions.defaultHostJavaBase());
checkLegacyToolchainFlagIsUnset(
"java_toolchain", javaOptions.javaToolchain, javaOptions.defaultJavaToolchain());
checkLegacyToolchainFlagIsUnset(
"host_java_toolchain", javaOptions.hostJavaToolchain, javaOptions.defaultJavaToolchain());
checkLegacyToolchainFlagIsUnset("javabase", javaOptions.javaBase);
checkLegacyToolchainFlagIsUnset("host_javabase", javaOptions.hostJavaBase);
checkLegacyToolchainFlagIsUnset("java_toolchain", javaOptions.javaToolchain);
checkLegacyToolchainFlagIsUnset("host_java_toolchain", javaOptions.hostJavaToolchain);
}
}

private static void checkLegacyToolchainFlagIsUnset(String flag, Label label, Label defaultValue)
private static void checkLegacyToolchainFlagIsUnset(String flag, Label label)
throws InvalidConfigurationException {
if (!Objects.equals(label, defaultValue)) {
if (label != null) {
throw new InvalidConfigurationException(
String.format(
"--%s=%s is no longer supported, use --platforms instead (see #7849)", flag, label));
Expand Down Expand Up @@ -287,24 +276,6 @@ public boolean enforceProguardFileExtension() {
return enforceProguardFileExtension;
}

/** Returns the label of the default java_toolchain rule */
@StarlarkConfigurationField(
name = "java_toolchain",
doc = "Returns the label of the default java_toolchain rule.",
defaultLabel = "//tools/jdk:toolchain",
defaultInToolRepository = true)
public Label getToolchainLabel() {
if (disallowLegacyJavaToolchainFlags) {
throw new IllegalStateException("--java_toolchain is no longer supported");
}
return toolchainLabel;
}

/** Returns the label of the {@code java_runtime} rule representing the JVM in use. */
public Label getRuntimeLabel() {
return runtimeLabel;
}

/** Stores a String name and an optional associated label. */
@AutoValue
public abstract static class NamedLabel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,41 +71,34 @@ public ImportDepsCheckingLevelConverter() {
+ " instead; see #7849")
public boolean disallowLegacyJavaToolchainFlags;

private static final String DEFAULT_JAVABASE = "@bazel_tools//tools/jdk:jdk";

@Deprecated
@Option(
name = "javabase",
defaultValue = DEFAULT_JAVABASE,
defaultValue = "null",
converter = LabelConverter.class,
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.UNKNOWN},
help =
"JAVABASE used for the JDK invoked by Blaze. This is the "
+ "java_runtime which will be used to execute "
+ "external Java commands.")
help = "No-op. Kept here for backwards compatibility.")
public Label javaBase;

private static final String DEFAULT_JAVA_TOOLCHAIN = "@bazel_tools//tools/jdk:remote_toolchain";

@Deprecated
@Option(
name = "java_toolchain",
defaultValue = DEFAULT_JAVA_TOOLCHAIN,
defaultValue = "null",
converter = LabelConverter.class,
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.UNKNOWN},
help = "The name of the toolchain rule for Java.")
help = "No-op. Kept here for backwards compatibility.")
public Label javaToolchain;

@Deprecated
@Option(
name = "host_java_toolchain",
defaultValue = DEFAULT_JAVA_TOOLCHAIN,
defaultValue = "null",
converter = LabelConverter.class,
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.UNKNOWN},
help = "The Java toolchain used to build tools that are executed during a build.")
help = "No-op. Kept here for backwards compatibility.")
public Label hostJavaToolchain;

@Deprecated
Expand All @@ -115,9 +108,7 @@ public ImportDepsCheckingLevelConverter() {
converter = LabelConverter.class,
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.UNKNOWN},
help =
"JAVABASE used for the host JDK. This is the java_runtime which is used to execute "
+ "tools during a build.")
help = "No-op. Kept here for backwards compatibility.")
public Label hostJavaBase;

@Option(
Expand Down Expand Up @@ -576,41 +567,20 @@ public ImportDepsCheckingLevelConverter() {
effectTags = {OptionEffectTag.UNKNOWN},
help = "Enable experimental jspecify integration.")
public boolean experimentalEnableJspecify;

Label defaultJavaBase() {
return Label.parseAbsoluteUnchecked(DEFAULT_JAVABASE);
}

Label getHostJavaBase() {
if (hostJavaBase == null) {
return defaultHostJavaBase();
}
return hostJavaBase;
}

Label defaultHostJavaBase() {
return Label.parseAbsoluteUnchecked("@bazel_tools//tools/jdk:remote_jdk11");
}

Label defaultJavaToolchain() {
return Label.parseAbsoluteUnchecked(DEFAULT_JAVA_TOOLCHAIN);
}

@Override
public FragmentOptions getHost() {
// Note validation actions don't run in host config, so no need copying flags related to that.
// TODO(b/171078539): revisit if relevant validations are run in host config
JavaOptions host = (JavaOptions) getDefault();

host.javaBase = getHostJavaBase();
if (hostJvmOpts == null || hostJvmOpts.isEmpty()) {
host.jvmOpts = ImmutableList.of("-XX:ErrorFile=/dev/stderr");
} else {
host.jvmOpts = hostJvmOpts;
}


host.javacOpts = hostJavacOpts;
host.javaToolchain = hostJavaToolchain;

host.javaLauncher = hostJavaLauncher;

Expand Down Expand Up @@ -648,10 +618,8 @@ public FragmentOptions getHost() {
host.proguard = proguard;

// Save host options for further use.
host.hostJavaBase = hostJavaBase;
host.hostJavacOpts = hostJavacOpts;
host.hostJavaLauncher = hostJavaLauncher;
host.hostJavaToolchain = hostJavaToolchain;
host.hostJavaRuntimeVersion = hostJavaRuntimeVersion;
host.hostJavaLanguageVersion = hostJavaLanguageVersion;

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ public void setupMockClient(MockToolsConfig config, List<String> workspaceConten
" 'java_toolchain_alias',",
" 'java_runtime_alias',",
" 'java_host_runtime_alias',",
" 'legacy_java_toolchain_alias',",
" 'legacy_java_runtime_alias',",
")",
"package(default_visibility=['//visibility:public'])",
"java_toolchain(",
Expand Down Expand Up @@ -170,9 +168,7 @@ public void setupMockClient(MockToolsConfig config, List<String> workspaceConten
"java_runtime(name = 'host_jdk', srcs = [])",
"java_runtime(name = 'remote_jdk11', srcs = [])",
"java_toolchain_alias(name = 'current_java_toolchain')",
"legacy_java_toolchain_alias(name = 'legacy_current_java_toolchain')",
"java_runtime_alias(name = 'current_java_runtime')",
"legacy_java_runtime_alias(name = 'legacy_current_java_runtime')",
"java_host_runtime_alias(name = 'current_host_java_runtime')",
"filegroup(name='langtools', srcs=['jdk/lib/tools.jar'])",
"filegroup(name='bootclasspath', srcs=['jdk/jre/lib/rt.jar'])",
Expand Down
6 changes: 2 additions & 4 deletions src/test/shell/bazel/bazel_example_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,16 @@ function test_java_test_with_junitrunner() {

function test_genrule_and_genquery() {
# With toolchain resolution java runtime only appears in cquery results.
# //tools/jdk:jdk label appears in the dependency list while --javabase
# is still available, because of migration rules.
assert_build_output ./bazel-bin/examples/gen/genquery examples/gen:genquery
local want=./bazel-genfiles/examples/gen/genrule.txt
assert_build_output $want examples/gen:genrule

diff $want ./bazel-bin/examples/gen/genquery \
|| fail "genrule and genquery output differs"

grep -qE "^@bazel_tools//tools/jdk:jdk$" $want || {
grep -vqE "^@local_jdk//:jdk$" $want || {
cat $want
fail "@bazel_tools//tools/jdk:jdk not found in genquery output"
fail "@local_jdk//:jdk found in genquery output"
}
}

Expand Down
Loading

0 comments on commit e1c404e

Please sign in to comment.