Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toggle for ijar in java_import #14967

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.JavaOutput;
import com.google.devtools.build.lib.packages.Type;
import java.util.LinkedHashSet;
import java.util.Set;

Expand Down Expand Up @@ -202,7 +203,8 @@ private ImmutableList<Artifact> processWithIjarIfNeeded(
RuleContext ruleContext,
ImmutableMap.Builder<Artifact, Artifact> compilationToRuntimeJarMap) {
ImmutableList.Builder<Artifact> interfaceJarsBuilder = ImmutableList.builder();
boolean useIjar = ruleContext.getFragment(JavaConfiguration.class).getUseIjars();
boolean useIjar = ruleContext.getFragment(JavaConfiguration.class).getUseIjars()
&& ruleContext.attributes().get("use_ijar", Type.BOOLEAN);
for (Artifact jar : jars) {
Artifact interfaceJar =
useIjar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment envi
for IDE plug-ins or <code>tools.jar</code> for anything running on
a standard JDK.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(attr("use_ijar", BOOLEAN).value(false))
/* <!-- #BLAZE_RULE($java_import_base).ATTRIBUTE(use_ijar) -->
If you import an oft-changing JAR that doesn't have a Kotlin interface,
you can enable this as a caching optimization.
Temporarily available until ijar is updated to properly handle Kotlin.
For more, see https://github.com/bazelbuild/bazel/issues/4549.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.add(attr("neverlink", BOOLEAN).value(false))
/* <!-- #BLAZE_RULE($java_import_base).ATTRIBUTE(constraints) -->
Extra constraints imposed on this rule as a Java library.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ public final void writeBuildFile() throws Exception {
scratch.file(
"java/jarlib/BUILD",
"java_import(name = 'libraryjar',",
" jars = ['library.jar'])",
" jars = ['library.jar'],",
" use_ijar = True)",
"java_import(name = 'libraryjar_with_srcjar',",
" jars = ['library.jar'],",
" srcjar = 'library.srcjar')");
" srcjar = 'library.srcjar',",
" use_ijar = True)");
}

@Test
Expand Down Expand Up @@ -130,11 +132,14 @@ public void testDeps() throws Exception {
" jars = ['import.jar'],",
" deps = ['//java/jarlib2:depjar'],",
" exports = ['//java/jarlib2:exportjar'],",
" use_ijar = True",
")",
"java_import(name = 'depjar',",
" jars = ['depjar.jar'])",
" jars = ['depjar.jar'],",
" use_ijar = True)",
"java_import(name = 'exportjar',",
" jars = ['exportjar.jar'])");
" jars = ['exportjar.jar'],",
" use_ijar = True)");

ConfiguredTarget importJar = getConfiguredTarget("//java/jarlib2:import-jar");

Expand Down Expand Up @@ -210,7 +215,8 @@ public void testFromGenrule() throws Exception {
"java_import(name = 'library-jar',",
" jars = [':generated_jar'],",
" srcjar = ':generated_src_jar',",
" exports = ['//java/jarlib:libraryjar'])");
" exports = ['//java/jarlib:libraryjar'],",
" use_ijar = True)");
ConfiguredTarget jarLib = getConfiguredTarget("//java/genrules:library-jar");

JavaCompilationArgsProvider compilationArgs =
Expand Down Expand Up @@ -441,7 +447,8 @@ public void testTransitiveDependencies() throws Exception {
" deps = ['//java/jarlib:libraryjar'])",
"java_import(name = 'library2-jar',",
" jars = ['library2.jar'],",
" exports = [':lib'])",
" exports = [':lib'],",
" use_ijar = True)",
"java_library(name = 'javalib2',",
" srcs = ['Other.java'],",
" deps = [':library2-jar'])");
Expand All @@ -464,6 +471,7 @@ public void testRuntimeDepsAreNotOnClasspath() throws Exception {
" name = 'import_dep',",
" jars = ['import_compile.jar'],",
" runtime_deps = ['import_runtime.jar'],",
" use_ijar = True",
")",
"java_library(",
" name = 'library_dep',",
Expand Down