Re-arrange --{host_,}java_launcher
--
MOS_MIGRATED_REVID=128405574
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java
index f126a9ad..e3d59df 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java
@@ -18,12 +18,14 @@
import static com.google.devtools.build.lib.packages.Attribute.attr;
import static com.google.devtools.build.lib.packages.BuildType.LABEL;
import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static com.google.devtools.build.lib.packages.BuildType.NODEP_LABEL_LIST;
import static com.google.devtools.build.lib.packages.BuildType.TRISTATE;
import static com.google.devtools.build.lib.packages.ImplicitOutputsFunction.fromFunctions;
import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
import static com.google.devtools.build.lib.syntax.Type.STRING;
import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.analysis.BaseRuleClasses;
import com.google.devtools.build.lib.analysis.RuleDefinition;
@@ -43,7 +45,6 @@
import com.google.devtools.build.lib.rules.java.JavaToolchainProvider;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.util.FileTypeSet;
-
import java.util.Set;
/**
@@ -327,18 +328,18 @@
this to 0 if the <code>launcher</code> or <code>main_class</code> attributes
are set.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(attr("create_executable", BOOLEAN)
- .nonconfigurable("internal")
- .value(true))
- .add(attr("$testsupport", LABEL).value(
- new Attribute.ComputedDefault("use_testrunner") {
- @Override
- public Object getDefault(AttributeMap rule) {
- return rule.get("use_testrunner", Type.BOOLEAN)
- ? env.getToolsLabel(JUNIT_TESTRUNNER)
- : null;
- }
- }))
+ .add(attr("create_executable", BOOLEAN).nonconfigurable("internal").value(true))
+ .add(
+ attr("$testsupport", LABEL)
+ .value(
+ new Attribute.ComputedDefault("use_testrunner") {
+ @Override
+ public Object getDefault(AttributeMap rule) {
+ return rule.get("use_testrunner", Type.BOOLEAN)
+ ? env.getToolsLabel(JUNIT_TESTRUNNER)
+ : null;
+ }
+ }))
/* <!-- #BLAZE_RULE($base_java_binary).ATTRIBUTE(deploy_manifest_lines) -->
A list of lines to add to the <code>META-INF/manifest.mf</code> file generated for the
<code>*_deploy.jar</code> target. The contents of this attribute are <em>not</em> subject
@@ -382,10 +383,18 @@
specified by the launcher target. (This does not apply to the opt-out
label.)</p>
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(attr("launcher", LABEL)
- .allowedFileTypes(FileTypeSet.NO_FILE)
- .allowedRuleClasses("cc_binary"))
- .add(attr(":java_launcher", LABEL).value(JavaSemantics.JAVA_LAUNCHER)) // blaze flag
+ .add(
+ attr("launcher", LABEL)
+ .allowedFileTypes(FileTypeSet.NO_FILE)
+ .allowedRuleClasses("cc_binary"))
+ .add(attr(":java_launcher", LABEL).value(JavaSemantics.JAVA_LAUNCHER)) // blaze flag
+ .add(
+ attr("$no_launcher", NODEP_LABEL_LIST)
+ .value(
+ ImmutableList.of(
+ // TODO(b/30038239): migrate to //tools/jdk:no_launcher and delete
+ env.getToolsLabel("//third_party/java/jdk:jdk_launcher"),
+ env.getToolsLabel("//tools/jdk:no_launcher"))))
.build();
}
@Override
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java
index 0ec9779..562391a 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java
@@ -32,7 +32,6 @@
import com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction.Substitution;
import com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction.Template;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
-import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.rules.java.DeployArchiveBuilder;
@@ -70,17 +69,9 @@
private static final String JAVABUILDER_CLASS_NAME =
"com.google.devtools.build.buildjar.BazelJavaBuilder";
- private static final Label JDK_LAUNCHER_LABEL =
- Label.parseAbsoluteUnchecked("@bazel_tools//third_party/java/jdk:jdk_launcher");
-
private BazelJavaSemantics() {
}
- @Override
- public boolean isJdkLauncher(Label label) {
- return JDK_LAUNCHER_LABEL.equals(label);
- }
-
private boolean isJavaBinaryOrJavaTest(RuleContext ruleContext) {
String ruleClass = ruleContext.getRule().getRuleClass();
return ruleClass.equals("java_binary") || ruleClass.equals("java_test");
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java
index 0b9ac8c..65606e5 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaBinary.java
@@ -84,7 +84,7 @@
// TODO(cushon): disallow combining launcher=JDK_LAUNCHER_LABEL with create_executable=0
// and use isAttributeExplicitlySpecified here
Label launcherAttribute = ruleContext.attributes().get("launcher", BuildType.LABEL);
- if (launcherAttribute != null && !semantics.isJdkLauncher(launcherAttribute)) {
+ if (launcherAttribute != null && !JavaHelper.isJdkLauncher(ruleContext, launcherAttribute)) {
ruleContext.ruleError("launcher specified but create_executable is false");
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaHelper.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaHelper.java
index 0e709d0..e429567 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaHelper.java
@@ -13,11 +13,14 @@
// limitations under the License.
package com.google.devtools.build.lib.rules.java;
+import static com.google.devtools.build.lib.packages.BuildType.NODEP_LABEL_LIST;
+
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.AnalysisUtils;
import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
+import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.shell.ShellUtils;
@@ -40,7 +43,7 @@
*/
public static TransitiveInfoCollection launcherForTarget(JavaSemantics semantics,
RuleContext ruleContext) {
- String launcher = filterLauncherForTarget(semantics, ruleContext);
+ String launcher = filterLauncherForTarget(ruleContext);
return (launcher == null) ? null : ruleContext.getPrerequisite(launcher, Mode.TARGET);
}
@@ -50,7 +53,7 @@
*/
public static Artifact launcherArtifactForTarget(JavaSemantics semantics,
RuleContext ruleContext) {
- String launcher = filterLauncherForTarget(semantics, ruleContext);
+ String launcher = filterLauncherForTarget(ruleContext);
return (launcher == null) ? null : ruleContext.getPrerequisiteArtifact(launcher, Mode.TARGET);
}
@@ -58,7 +61,7 @@
* Control structure abstraction for safely extracting a prereq from the launcher attribute
* or --java_launcher flag.
*/
- private static String filterLauncherForTarget(JavaSemantics semantics, RuleContext ruleContext) {
+ private static String filterLauncherForTarget(RuleContext ruleContext) {
// create_executable=0 disables the launcher
if (ruleContext.getRule().isAttrDefined("create_executable", Type.BOOLEAN)
&& !ruleContext.attributes().get("create_executable", Type.BOOLEAN)) {
@@ -67,7 +70,7 @@
// BUILD rule "launcher" attribute
if (ruleContext.getRule().isAttrDefined("launcher", BuildType.LABEL)
&& ruleContext.attributes().get("launcher", BuildType.LABEL) != null) {
- if (semantics.isJdkLauncher(ruleContext.attributes().get("launcher", BuildType.LABEL))) {
+ if (isJdkLauncher(ruleContext, ruleContext.attributes().get("launcher", BuildType.LABEL))) {
return null;
}
return "launcher";
@@ -76,7 +79,7 @@
JavaConfiguration javaConfig = ruleContext.getFragment(JavaConfiguration.class);
if (ruleContext.getRule().isAttrDefined(":java_launcher", BuildType.LABEL)
&& javaConfig.getJavaLauncherLabel() != null
- && !semantics.isJdkLauncher(javaConfig.getJavaLauncherLabel())) {
+ && !isJdkLauncher(ruleContext, javaConfig.getJavaLauncherLabel())) {
return ":java_launcher";
}
return null;
@@ -141,4 +144,13 @@
public static NestedSet<Artifact> getHostJavabaseInputs(RuleContext ruleContext) {
return AnalysisUtils.getMiddlemanFor(ruleContext, ":host_jdk");
}
+
+ /**
+ * Returns true if the given Label is of the pseudo-cc_binary that tells Bazel a Java target's
+ * JAVABIN is never to be replaced by the contents of --java_launcher; only the JDK's launcher
+ * will ever be used.
+ */
+ public static boolean isJdkLauncher(RuleContext ruleContext, Label label) {
+ return ruleContext.attributes().get("$no_launcher", NODEP_LABEL_LIST).contains(label);
+ }
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaSemantics.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaSemantics.java
index ed81f99..2e1435e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaSemantics.java
@@ -381,12 +381,4 @@
* proguard mapping, or null if the proguard version doesn't support this.
*/
Artifact getProtoMapping(RuleContext ruleContext) throws InterruptedException;
-
- /**
- * Returns true if the given Label is of the pseudo-cc_binary that tells Blaze a java target's
- * JAVABIN is never to be replaced by the contents of --java_launcher; only the JDK's launcher
- * will ever be used.
- */
- boolean isJdkLauncher(Label label);
}
-