Support deploy_env in java_binary rule
This adds support for `deploy_env`, an internal feature that supports transitive classpath subtraction to create deployable jars suited for different environments.
This PR cherrypicks commit, as described in and will help with scenarios describe there, as well as
Closes
@@ -16,6 +16,7 @@ package com.google.devtools.build.lib.bazel.rules.java;
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.syntax.Type.BOOLEAN;
import com.google.devtools.build.lib.analysis.BaseRuleClasses;
@@ -28,6 +29,7 @@ import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.rules.cpp.CppConfiguration;
import com.google.devtools.build.lib.rules.cpp.CppRuleClasses;
import com.google.devtools.build.lib.rules.java.JavaConfiguration;
+import com.google.devtools.build.lib.util.FileTypeSet;
/**
* Rule definition for the java_binary rule.
@@ -78,16 +80,29 @@ public final class BazelJavaBinaryRule implements RuleDefinition {
</ul>
<!-- #END_BLAZE_RULE.IMPLICIT_OUTPUTS --> */
.setImplicitOutputsFunction(BazelJavaRuleClasses.JAVA_BINARY_IMPLICIT_OUTPUTS)
- .override(attr("$is_executable", BOOLEAN).nonconfigurable("automatic").value(
+ /* <!-- #BLAZE_RULE(java_binary).ATTRIBUTE(deploy_env) -->
+ A list of other <code>java_binary</code> targets which represent the deployment
+ environment for this binary.
+ Set this attribute when building a plugin which will be loaded by another
+ <code>java_binary</code>.<br/> Setting this attribute excludes all dependencies from
+ the runtime classpath (and the deploy jar) of this binary that are shared between this
+ binary and the targets specified in <code>deploy_env</code>.
+ <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
+ .add(
+ attr("deploy_env", LABEL_LIST)
+ .allowedRuleClasses("java_binary")
+ .allowedFileTypes(FileTypeSet.NO_FILE))
+ .override(
+ attr("$is_executable", BOOLEAN)
+ .nonconfigurable("automatic")
+ .value(
new Attribute.ComputedDefault() {
@Override
public Object getDefault(AttributeMap rule) {
return rule.get("create_executable", BOOLEAN);
}
}))
- .add(
- attr("$jacocorunner", LABEL).value(env.getToolsLabel(
- "//tools/jdk:JacocoCoverage")))
+ .add(attr("$jacocorunner", LABEL).value(env.getToolsLabel("//tools/jdk:JacocoCoverage")))
.addRequiredToolchains(CppRuleClasses.ccToolchainTypeAttribute(env))
.build();
}
