Skip to content

Commit

Permalink
Support deploy_env in java_binary rule
Browse files Browse the repository at this point in the history
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 @ulfjack's commit, as described in #1402, and will help with scenarios describe there, as well as #5856.

Closes #6013.

PiperOrigin-RevId: 228690507
  • Loading branch information
ulfjack authored and Copybara-Service committed Jan 10, 2019
1 parent 94e5016 commit a92347e
Showing 1 changed file with 24 additions and 9 deletions.
Expand Up @@ -16,6 +16,7 @@

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;
Expand All @@ -28,6 +29,7 @@
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.
Expand Down Expand Up @@ -78,16 +80,29 @@ native binary. This will contain the launcher plus any native (C++) dependencies
</ul>
<!-- #END_BLAZE_RULE.IMPLICIT_OUTPUTS --> */
.setImplicitOutputsFunction(BazelJavaRuleClasses.JAVA_BINARY_IMPLICIT_OUTPUTS)
.override(attr("$is_executable", BOOLEAN).nonconfigurable("automatic").value(
new Attribute.ComputedDefault() {
@Override
public Object getDefault(AttributeMap rule) {
return rule.get("create_executable", BOOLEAN);
}
}))
/* <!-- #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("$jacocorunner", LABEL).value(env.getToolsLabel(
"//tools/jdk:JacocoCoverage")))
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")))
.addRequiredToolchains(CppRuleClasses.ccToolchainTypeAttribute(env))
.build();
}
Expand Down

0 comments on commit a92347e

Please sign in to comment.