Skip to content

Commit

Permalink
Disable JSpecify integration for java_lite_proto_library.
Browse files Browse the repository at this point in the history
I've extended java_common.compile with enable_jspecify argument as a private API.

PiperOrigin-RevId: 430058214
  • Loading branch information
Googler authored and copybara-github committed Feb 21, 2022
1 parent ba1dfb6 commit 88499f6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ public JavaInfo createJavaCompileAction(
Boolean neverlink,
Boolean enableAnnotationProcessing,
Boolean enableCompileJarAction,
boolean enableJSpecify,
JavaSemantics javaSemantics,
Object injectingRuleKind,
StarlarkThread thread)
Expand All @@ -272,6 +273,7 @@ public JavaInfo createJavaCompileAction(
.addClasspathResources(classpathResources)
.setSourcePathEntries(sourcepathEntries)
.addAdditionalOutputs(annotationProcessorAdditionalOutputs)
.enableJspecify(enableJSpecify)
.setJavacOpts(
ImmutableList.<String>builder()
.addAll(toolchainProvider.getJavacOptions(starlarkRuleContext.getRuleContext()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public JavaInfo createJavaCompileAction(
Boolean neverlink,
Boolean enableAnnotationProcessing,
Boolean enableCompileJarAction,
Boolean enableJSpecify,
Object injectingRuleKind,
StarlarkThread thread)
throws EvalException, InterruptedException {
Expand Down Expand Up @@ -127,6 +128,7 @@ public JavaInfo createJavaCompileAction(
}
// checks for private API access
if (!enableCompileJarAction
|| !enableJSpecify
|| !classpathResources.isEmpty()
|| injectingRuleKind != Starlark.NONE) {
checkPrivateAccess(thread);
Expand Down Expand Up @@ -161,6 +163,7 @@ public JavaInfo createJavaCompileAction(
neverlink,
enableAnnotationProcessing,
enableCompileJarAction,
enableJSpecify,
javaSemantics,
injectingRuleKind,
thread);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ public interface JavaCommonApi<
+ " full class jar in the compilation classpaths of any dependants. Doing so is"
+ " intended for use by non-library targets such as binaries that do not have"
+ " dependants."),
@Param(
name = "enable_jspecify",
positional = false,
named = true,
defaultValue = "True",
documented = false),
@Param(
name = "injecting_rule_kind",
documented = false,
Expand Down Expand Up @@ -266,6 +272,7 @@ JavaInfoT createJavaCompileAction(
Boolean neverlink,
Boolean enableAnnotationProcessing,
Boolean enableCompileJarAction,
Boolean enableJSpecify,
Object injectingRuleKind,
StarlarkThread thread)
throws EvalException, InterruptedException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def _aspect_impl(target, ctx):
deps = deps,
exports = exports,
java_toolchain = ctx.attr._java_toolchain[java_common.JavaToolchainInfo],
enable_jspecify = False,
)
else:
# If there are no proto sources just pass along the compilation dependencies.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3125,6 +3125,38 @@ public void testInjectingRuleKindIsPrivateApi() throws Exception {
assertContainsEvent("Rule in 'foo' cannot use private API");
}

@Test
public void testEnableJSpecifyIsPrivateApi() 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_jspecify = 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");
}

@Test
public void testRuntimeDepsIsPrivateApi() throws Exception {
scratch.file(
Expand Down

0 comments on commit 88499f6

Please sign in to comment.