Skip to content

Commit

Permalink
Add native libraries from CcInfo to java_import
Browse files Browse the repository at this point in the history
JavaReadline was missing in java.library.path, which is now added inside JavaInfo constructor and java_common.compile with native_libraries parameters.

PiperOrigin-RevId: 486155074
Change-Id: I3064da4ba7724329111e7e1fa7c96a1b50574177
  • Loading branch information
kotlaja authored and copybara-github committed Nov 4, 2022
1 parent 5f3f59b commit a67c823
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/starlark/builtins_bzl/common/java/java_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _check_empty_jars_error(ctx, jars):
if len(jars) == 0 and ctx.fragments.java.disallow_java_import_empty_jars() and hasattr(ctx.attr, "_allowlist_java_import_empty_jars") and not getattr(ctx.attr, "_allowlist_java_import_empty_jars").isAvailableFor(ctx.label):
fail("empty java_import.jars is no longer supported " + ctx.label.package)

def _create_java_info_with_dummy_output_file(ctx, srcjar, deps, exports, runtime_deps_list, neverlink):
def _create_java_info_with_dummy_output_file(ctx, srcjar, deps, exports, runtime_deps_list, neverlink, cc_info_list):
dummy_jar = ctx.actions.declare_file(ctx.label.name + "_dummy.jar")
dummy_src_jar = srcjar
if dummy_src_jar == None:
Expand All @@ -86,6 +86,7 @@ def _create_java_info_with_dummy_output_file(ctx, srcjar, deps, exports, runtime
runtime_deps = runtime_deps_list,
neverlink = neverlink,
exports = [export[JavaInfo] for export in exports if JavaInfo in export], # Watchout, maybe you need to add them there manually.
native_libraries = cc_info_list,
)

def bazel_java_import_rule(
Expand Down Expand Up @@ -137,6 +138,7 @@ def bazel_java_import_rule(

compilation_to_runtime_jar_map = _process_with_ijars_if_needed(collected_jars, ctx)
runtime_deps_list = [runtime_dep[JavaInfo] for runtime_dep in runtime_deps if JavaInfo in runtime_dep]
cc_info_list = [dep[CcInfo] for dep in deps if CcInfo in dep]
java_info = None
if len(collected_jars) > 0:
java_infos = []
Expand All @@ -149,11 +151,12 @@ def bazel_java_import_rule(
neverlink = neverlink,
source_jar = srcjar,
exports = [export[JavaInfo] for export in exports if JavaInfo in export], # Watchout, maybe you need to add them there manually.
native_libraries = cc_info_list,
))
java_info = java_common.merge(java_infos)
else:
# TODO(kotlaja): Remove next line once all java_import targets with empty jars attribute are cleaned from depot (b/246559727).
java_info = _create_java_info_with_dummy_output_file(ctx, srcjar, deps, exports, runtime_deps_list, neverlink)
java_info = _create_java_info_with_dummy_output_file(ctx, srcjar, deps, exports, runtime_deps_list, neverlink, cc_info_list)

if len(constraints):
java_info = semantics.add_constraints(java_info, constraints)
Expand Down

0 comments on commit a67c823

Please sign in to comment.