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 add_exports & add_opens parameters to JavaInfo constructor #20036

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions src/main/starlark/builtins_bzl/common/java/java_info.bzl
timothyg-stripe marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,9 @@ def _javainfo_init(
exports = [],
exported_plugins = [],
jdeps = None,
native_libraries = []):
native_libraries = [],
add_exports = [],
add_opens = []):
"""The JavaInfo constructor

Args:
Expand Down Expand Up @@ -693,6 +695,8 @@ def _javainfo_init(
is typically produced by a compiler. IDEs and other tools can use this information for
more efficient processing. Optional.
native_libraries: ([CcInfo]) Native library dependencies that are needed for this library.
add_exports: ([str]) The <module>/<package>s this library was given access to.
add_opens: ([str]) The <module>/<package>s this library was given reflective access to.

Returns:
(dict) arguments to the JavaInfo provider constructor
Expand Down Expand Up @@ -734,11 +738,11 @@ def _javainfo_init(
],
),
module_flags_info = _create_module_flags_info(
add_exports = depset(transitive = [
add_exports = depset(add_exports, transitive = [
dep.module_flags_info.add_exports
for dep in concatenated_deps.deps_exports
]),
add_opens = depset(transitive = [
add_opens = depset(add_opens, transitive = [
dep.module_flags_info.add_opens
for dep in concatenated_deps.deps_exports
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,20 +857,41 @@ public void buildHelperCreateJavaInfoWithModuleFlags() throws Exception {
"java_library(",
" name = 'my_java_lib_direct',",
" srcs = ['java/A.java'],",
" add_exports = ['java.base/java.lang'],",
" add_opens = ['java.base/java.lang'],",
")",
"java_library(",
" name = 'my_java_lib_runtime',",
" srcs = ['java/A.java'],",
" add_opens = ['java.base/java.util'],",
")",
"java_library(",
" name = 'my_java_lib_exports',",
" srcs = ['java/A.java'],",
" add_opens = ['java.base/java.math'],",
")",
"my_rule(",
" name = 'my_starlark_rule',",
" dep = [':my_java_lib_direct'],",
" dep_runtime = [':my_java_lib_runtime'],",
" dep_exports = [':my_java_lib_exports'],",
" output_jar = 'my_starlark_rule_lib.jar',",
" add_exports = ['java.base/java.lang.invoke'],",
")");
assertNoEvents();

JavaModuleFlagsProvider ruleOutputs =
fetchJavaInfo().getProvider(JavaModuleFlagsProvider.class);

assertThat(ruleOutputs.toFlags())
.containsExactly("--add-opens=java.base/java.lang=ALL-UNNAMED");
.containsExactly(
"--add-exports=java.base/java.lang=ALL-UNNAMED",
"--add-exports=java.base/java.lang.invoke=ALL-UNNAMED",
// NB: no java.base/java.util as the JavaInfo constructor doesn't
// look at runtime_deps for module flags.
"--add-opens=java.base/java.lang=ALL-UNNAMED",
"--add-opens=java.base/java.math=ALL-UNNAMED")
.inOrder();
}

@Test
Expand Down Expand Up @@ -1240,6 +1261,8 @@ private String[] newJavaInfo() {
" native_headers_jar = ctx.file.native_headers_jar,",
" manifest_proto = ctx.file.manifest_proto,",
" native_libraries = dp_libs,",
" add_exports = ctx.attr.add_exports,",
" add_opens = ctx.attr.add_opens,",
" )",
" return [result(property = javaInfo)]");
return lines.build().toArray(new String[] {});
Expand Down Expand Up @@ -1271,6 +1294,8 @@ private void build() throws Exception {
" 'generated_source_jar' : attr.label(allow_single_file=True),",
" 'native_headers_jar' : attr.label(allow_single_file=True),",
" 'manifest_proto' : attr.label(allow_single_file=True),",
" 'add_exports' : attr.string_list(),",
" 'add_opens' : attr.string_list(),",
useIJar || stampJar || sourceFiles
? " '_toolchain': attr.label(default = Label('//java/com/google/test:toolchain')),"
: "",
Expand Down