Add a test that disabling compile jar in java_common.compile() is restricted
@@ -3087,6 +3087,38 @@ public class JavaStarlarkApiTest extends BuildViewTestCase {
assertThat(turbineActionNoProc.getArguments()).doesNotContain("--processors");
}
+ @Test
+ public void testCompileWithDisablingCompileJarIsPrivateApi() throws Exception {
+ JavaToolchainTestUtil.writeBuildFileForJavaToolchain(scratch);
+ scratch.file(
+ "foo/custom_rule.bzl",
+ "def _impl(ctx):",
+ " java_common.compile(",
+ " ctx,",
+ " output = ctx.actions.declare_file('output.jar'),",
+ " java_toolchain = ctx.attr._java_toolchain[java_common.JavaToolchainInfo],",
+ " enable_compile_jar_action = False,",
+ " )",
+ " return []",
+ "java_custom_library = rule(",
+ " implementation = _impl,",
+ " attrs = {",
+ " 'srcs': attr.label_list(),",
+ " '_java_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),",
+ " },",
+ " fragments = ['java']",
+ ")");
+ scratch.file(
+ "foo/BUILD",
+ "load(':custom_rule.bzl', 'java_custom_library')",
+ "java_custom_library(name = 'custom')");
+ reporter.removeHandler(failFastHandler);
+
+ getConfiguredTarget("//foo:custom");
+
+ assertContainsEvent("Rule in 'foo' cannot use private API");
+ }
+
private InstrumentedFilesInfo getInstrumentedFilesProvider(String label) throws Exception {
return getConfiguredTarget(label).get(InstrumentedFilesInfo.STARLARK_CONSTRUCTOR);
}
