Skip to content

Commit b85eee7

Browse files
authored
Fix transitive dependency propagation for sourceless targets (#1455)
* Update impl.bzl Fix transitive dependency propagation for sourceless targets (e.g. android_library with only exports/deps and no srcs) in _reshade_embedded_kotlinc_jars # Why When a target has no source files, jars is empty, so the reshading comprehension produces nothing. The final java_common.merge then merges an empty list, silently dropping all deps. This breaks downstream consumers that rely on the full processor classpath being propagated transitively through these wrapper targets. * Adding testing
1 parent 66d44b9 commit b85eee7

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

kotlin/internal/jvm/impl.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ def kt_compiler_deps_aspect_impl(target, ctx):
498498
]
499499

500500
def _reshade_embedded_kotlinc_jars(target, ctx, jars, deps):
501+
# No jars to reshade — just propagate transitive deps (e.g. sourceless libraries).
502+
if not jars:
503+
return java_common.merge(deps) if deps else java_common.merge([])
504+
501505
reshaded = [
502506
jarjar_action(
503507
actions = ctx.actions,

src/test/starlark/internal/jvm/jvm_deps_tests.bzl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
load("@bazel_skylib//lib:structs.bzl", _structs = "structs")
2+
load("@rules_java//java:defs.bzl", "java_library")
23
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
34
load("@rules_testing//lib:analysis_test.bzl", "analysis_test")
45
load("@rules_testing//lib:test_suite.bzl", "test_suite")
56
load("@rules_testing//lib:util.bzl", "util")
7+
load("//kotlin:core.bzl", "kt_compiler_plugin")
8+
load("//kotlin:jvm.bzl", "kt_jvm_import")
69
load("//kotlin/internal:defs.bzl", _KtJvmInfo = "KtJvmInfo")
710
load("//kotlin/internal/jvm:jvm_deps.bzl", _jvm_deps_utils = "jvm_deps_utils")
811

@@ -392,6 +395,46 @@ def _dep_infos_ordering_test(name):
392395
},
393396
)
394397

398+
def _sourceless_dep_propagation_test_impl(env, target):
399+
"""Verify that a sourceless wrapper propagates transitive deps
400+
401+
Regression test for a bug where _reshade_embedded_kotlinc_jars would produce an empty merge
402+
when jars was empty (sourceless target), silently dropping all transitive deps.
403+
"""
404+
files = target[DefaultInfo].files.to_list()
405+
env.expect.that_bool(len(files) > 0).equals(True)
406+
407+
def _sourceless_dep_propagation_test(name):
408+
"""A sourceless library wrapping a real dep must propagate it."""
409+
410+
actual_dep_jar = util.empty_file(name + "_actual_dep.jar")
411+
412+
util.helper_target(
413+
kt_jvm_import,
414+
name = name + "_actual_dep",
415+
jars = [actual_dep_jar],
416+
)
417+
418+
util.helper_target(
419+
java_library,
420+
name = name + "_sourceless_wrapper",
421+
exports = [":" + name + "_actual_dep"],
422+
)
423+
424+
util.helper_target(
425+
kt_compiler_plugin,
426+
name = name + "_subject",
427+
id = "test.sourceless_propagation",
428+
target_embedded_compiler = True,
429+
deps = [":" + name + "_sourceless_wrapper"],
430+
)
431+
432+
analysis_test(
433+
name = name,
434+
impl = _sourceless_dep_propagation_test_impl,
435+
target = name + "_subject",
436+
)
437+
395438
def jvm_deps_test_suite(name):
396439
test_suite(
397440
name,
@@ -401,5 +444,6 @@ def jvm_deps_test_suite(name):
401444
_transitive_from_exports_test,
402445
_transitive_from_associates_test,
403446
_dep_infos_ordering_test,
447+
_sourceless_dep_propagation_test,
404448
],
405449
)

0 commit comments

Comments
 (0)