aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java2
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java55
2 files changed, 57 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java b/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java
index fc30103bb6..4a8e303a50 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/SkylarkSemanticsConsistencyTest.java
@@ -130,6 +130,7 @@ public class SkylarkSemanticsConsistencyTest {
"--incompatible_disallow_legacy_javainfo=" + rand.nextBoolean(),
"--incompatible_disallow_old_style_args_add=" + rand.nextBoolean(),
"--incompatible_disallow_slash_operator=" + rand.nextBoolean(),
+ "--incompatible_generate_javacommon_source_jar=" + rand.nextBoolean(),
"--incompatible_new_actions_api=" + rand.nextBoolean(),
"--incompatible_no_support_tools_in_action_inputs=" + rand.nextBoolean(),
"--incompatible_package_name_is_a_function=" + rand.nextBoolean(),
@@ -157,6 +158,7 @@ public class SkylarkSemanticsConsistencyTest {
.incompatibleDisallowLegacyJavaInfo(rand.nextBoolean())
.incompatibleDisallowOldStyleArgsAdd(rand.nextBoolean())
.incompatibleDisallowSlashOperator(rand.nextBoolean())
+ .incompatibleGenerateJavaCommonSourceJar(rand.nextBoolean())
.incompatibleNewActionsApi(rand.nextBoolean())
.incompatibleNoSupportToolsInActionInputs(rand.nextBoolean())
.incompatiblePackageNameIsAFunction(rand.nextBoolean())
diff --git a/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java b/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java
index c5956c0021..cd5eaf171c 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/java/JavaSkylarkApiTest.java
@@ -605,6 +605,61 @@ public class JavaSkylarkApiTest extends BuildViewTestCase {
}
@Test
+ public void testJavaCommonCompileWithOnlyOneSourceJarWithIncompatibleFlag() throws Exception {
+ writeBuildFileForJavaToolchain();
+ setSkylarkSemanticsOptions("--incompatible_generate_javacommon_source_jar=true");
+ scratch.file(
+ "java/test/BUILD",
+ "load(':custom_rule.bzl', 'java_custom_library')",
+ "java_custom_library(",
+ " name = 'custom',",
+ " srcs = ['myjar-src.jar'],",
+ ")");
+ scratch.file(
+ "java/test/custom_rule.bzl",
+ "def _impl(ctx):",
+ " output_jar = ctx.actions.declare_file('lib' + ctx.label.name + '.jar')",
+ " compilation_provider = java_common.compile(",
+ " ctx,",
+ " source_jars = ctx.files.srcs,",
+ " output = output_jar,",
+ " javac_opts = java_common.default_javac_opts(",
+ " ctx, java_toolchain_attr = '_java_toolchain'),",
+ " java_toolchain = ctx.attr._java_toolchain,",
+ " host_javabase = ctx.attr._host_javabase",
+ " )",
+ " return struct(",
+ " files = depset([output_jar]),",
+ " providers = [compilation_provider]",
+ " )",
+ "java_custom_library = rule(",
+ " implementation = _impl,",
+ " outputs = {",
+ " 'my_output': 'lib%{name}.jar'",
+ " },",
+ " attrs = {",
+ " 'srcs': attr.label_list(allow_files=['.jar']),",
+ " '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
+ " '_host_javabase': attr.label(",
+ " default = Label('" + HOST_JAVA_RUNTIME_LABEL + "'))",
+ " },",
+ " fragments = ['java']",
+ ")");
+
+ ConfiguredTarget configuredTarget = getConfiguredTarget("//java/test:custom");
+ JavaInfo info = configuredTarget.get(JavaInfo.PROVIDER);
+ SkylarkList<Artifact> sourceJars = info.getSourceJars();
+ assertThat(artifactFilesNames(sourceJars)).containsExactly("libcustom-src.jar");
+ JavaRuleOutputJarsProvider outputJars = info.getOutputJars();
+ assertThat(outputJars.getOutputJars()).hasSize(1);
+ OutputJar outputJar = outputJars.getOutputJars().get(0);
+ assertThat(outputJar.getClassJar().getFilename()).isEqualTo("libcustom.jar");
+ assertThat(outputJar.getSrcJar().getFilename()).isEqualTo("libcustom-src.jar");
+ assertThat(outputJar.getIJar().getFilename()).isEqualTo("libcustom-hjar.jar");
+ assertThat(outputJars.getJdeps().getFilename()).isEqualTo("libcustom.jdeps");
+ }
+
+ @Test
public void testJavaCommonCompileWithNoSources() throws Exception {
writeBuildFileForJavaToolchain();
scratch.file(