diff options
Diffstat (limited to 'src/test')
3 files changed, 63 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 569f3c36e8..7c7004a5c8 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 @@ -126,6 +126,7 @@ public class SkylarkSemanticsConsistencyTest { "--incompatible_disable_objc_provider_resources=" + rand.nextBoolean(), "--incompatible_disallow_dict_plus=" + rand.nextBoolean(), "--incompatible_disallow_filetype=" + rand.nextBoolean(), + "--incompatible_disallow_legacy_javainfo=" + rand.nextBoolean(), "--incompatible_disallow_old_style_args_add=" + rand.nextBoolean(), "--incompatible_disallow_slash_operator=" + rand.nextBoolean(), "--incompatible_new_actions_api=" + rand.nextBoolean(), @@ -150,6 +151,7 @@ public class SkylarkSemanticsConsistencyTest { .incompatibleDisableObjcProviderResources(rand.nextBoolean()) .incompatibleDisallowDictPlus(rand.nextBoolean()) .incompatibleDisallowFileType(rand.nextBoolean()) + .incompatibleDisallowLegacyJavaInfo(rand.nextBoolean()) .incompatibleDisallowOldStyleArgsAdd(rand.nextBoolean()) .incompatibleDisallowSlashOperator(rand.nextBoolean()) .incompatibleNewActionsApi(rand.nextBoolean()) diff --git a/src/test/java/com/google/devtools/build/lib/rules/java/JavaInfoSkylarkApiTest.java b/src/test/java/com/google/devtools/build/lib/rules/java/JavaInfoSkylarkApiTest.java index 8fb0b29785..5c156c4797 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/java/JavaInfoSkylarkApiTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/java/JavaInfoSkylarkApiTest.java @@ -24,6 +24,7 @@ import com.google.devtools.build.lib.packages.Info; import com.google.devtools.build.lib.packages.SkylarkProvider.SkylarkKey; import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.OutputJar; import com.google.devtools.build.lib.testutil.TestConstants; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -47,6 +48,13 @@ public class JavaInfoSkylarkApiTest extends BuildViewTestCase { this.legacyJavaInfoConstructor = legacyJavaInfoConstructor; } + @Before + public void setIncompatibleFlag() throws Exception { + if (legacyJavaInfoConstructor) { + setSkylarkSemanticsOptions("--noincompatible_disallow_legacy_javainfo"); + } + } + @Test public void buildHelperCreateJavaInfoWithOutputJarOnly() throws Exception { ruleBuilder().build(); @@ -677,6 +685,32 @@ public class JavaInfoSkylarkApiTest extends BuildViewTestCase { "my_rule(name = 'my_skylark_rule')"); } + @Test + public void testIncompatibleDisallowLegacyJavaInfo() throws Exception { + setSkylarkSemanticsOptions("--incompatible_disallow_legacy_javainfo"); + ImmutableList.Builder<String> lines = ImmutableList.builder(); + lines.add( + "result = provider()", + "def _impl(ctx):", + " output_jar = ctx.actions.declare_file('output_jar')", + " source_jar = ctx.actions.declare_file('source_jar')", + " javaInfo = JavaInfo(", + " output_jar = output_jar,", + " source_jars = [source_jar],", // No longer allowed + " )", + " return [result(property = javaInfo)]", + "my_rule = rule(", + " implementation = _impl,", + ")"); + scratch.file("foo/extension.bzl", lines.build().toArray(new String[] {})); + checkError( + "foo", + "my_skylark_rule", + "Cannot use deprecated argument when --incompatible_disallow_legacy_javainfo is set. ", + "load(':extension.bzl', 'my_rule')", + "my_rule(name = 'my_skylark_rule')"); + } + private RuleBuilder ruleBuilder() { return new RuleBuilder(); } 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 da39f19f8e..8270921d4c 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 @@ -1642,6 +1642,33 @@ public class JavaSkylarkApiTest extends BuildViewTestCase { assertThat(javaToolchainLabel.toString()).isEqualTo("//java/com/google/test:toolchain"); } + @Test + public void testIncompatibleDisallowLegacyJavaInfo() throws Exception { + setSkylarkSemanticsOptions("--incompatible_disallow_legacy_javainfo"); + scratch.file( + "java/test/custom_rule.bzl", + "def _impl(ctx):", + " jar = ctx.actions.declare_file('jar')", + " java_common.create_provider(", + " compile_time_jars = [jar],", + " transitive_compile_time_jars = [jar],", + " runtime_jars = [jar],", + " use_ijar = False,", + " )", + "java_custom_library = rule(", + " implementation = _impl,", + ")"); + checkError( + "java/test", + "custom", + "create_provider is deprecated and cannot be used when " + + "--incompatible_disallow_legacy_javainfo is set. ", + "load(':custom_rule.bzl', 'java_custom_library')", + "java_custom_library(", + " name = 'custom',", + ")"); + } + private static boolean javaCompilationArgsHaveTheSameParent( JavaCompilationArgsProvider args, JavaCompilationArgsProvider otherArgs) { if (!nestedSetsOfArtifactHaveTheSameParent( |