Skip to content

Commit cb8b7be

Browse files
authored
Include associates transitive compile jars in classpath (#1331)
1 parent 9734aa6 commit cb8b7be

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

kotlin/internal/jvm/jvm_deps.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def _jvm_deps(ctx, toolchains, associate_deps, deps, exports = [], runtime_deps
4141
] + [
4242
d.transitive_compile_time_jars
4343
for d in dep_infos
44+
] + [
45+
d.transitive_compile_time_jars
46+
for d in associates.dep_infos
4447
]
4548

4649
compile_depset_list = depset(transitive = transitive + [associates.jars]).to_list()

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,69 @@ def _transitive_from_exports_test_impl(env, target):
165165
classpath.contains(_file(env.ctx.attr.associate_jar).short_path)
166166
classpath.not_contains(_file(env.ctx.attr.associate_abi_jar).short_path)
167167

168+
def _transitive_from_associates_test_impl(env, target):
169+
##
170+
# the one where target A associates with target B
171+
# target B has a dependency to target C
172+
# target A uses C, the world explodes
173+
# what this means is the associates transitive_compile_time_jars has this
174+
# <generated file B.jar>,
175+
# <generated file C.jar>,
176+
# <source file various-sdk-libs.jar>
177+
# we will use the "direct jar" as a direct dep of the associate ie C
178+
##
179+
associates_direct_deps = [
180+
JavaInfo(
181+
compile_jar = _file(env.ctx.attr.direct_dep_jar),
182+
output_jar = _file(env.ctx.attr.direct_dep_jar),
183+
),
184+
]
185+
186+
associate_deps = [
187+
{
188+
JavaInfo: JavaInfo(
189+
compile_jar = _file(env.ctx.attr.associate_jar),
190+
output_jar = _file(env.ctx.attr.associate_jar),
191+
deps = associates_direct_deps,
192+
),
193+
_KtJvmInfo: _KtJvmInfo(
194+
module_name = "associate_name",
195+
),
196+
},
197+
]
198+
199+
fake_ctx = struct(
200+
label = target.label,
201+
attr = struct(
202+
module_name = "",
203+
tags = [],
204+
),
205+
)
206+
207+
nothing_configured_toolchains = struct(
208+
kt = struct(
209+
experimental_remove_private_classes_in_abi_jars = False,
210+
experimental_prune_transitive_deps = False,
211+
experimental_strict_associate_dependencies = False,
212+
jvm_stdlibs = JavaInfo(
213+
compile_jar = _file(env.ctx.attr.jvm_jar),
214+
output_jar = _file(env.ctx.attr.jvm_jar),
215+
),
216+
),
217+
)
218+
219+
result = _jvm_deps_utils.jvm_deps(
220+
ctx = fake_ctx,
221+
toolchains = nothing_configured_toolchains,
222+
associate_deps = associate_deps,
223+
deps = [],
224+
)
225+
226+
classpath = env.expect.that_depset_of_files(result.compile_jars)
227+
228+
classpath.contains(_file(env.ctx.attr.direct_dep_jar).short_path)
229+
classpath.contains(_file(env.ctx.attr.associate_jar).short_path)
230+
168231
def _abi_test(name, impl):
169232
util.helper_target(
170233
native.filegroup,
@@ -200,12 +263,16 @@ def _fat_abi_test(name):
200263
def _transitive_from_exports_test(name):
201264
_abi_test(name, _transitive_from_exports_test_impl)
202265

266+
def _transitive_from_associates_test(name):
267+
_abi_test(name, _transitive_from_associates_test_impl)
268+
203269
def jvm_deps_test_suite(name):
204270
test_suite(
205271
name,
206272
tests = [
207273
_strict_abi_test,
208274
_fat_abi_test,
209275
_transitive_from_exports_test,
276+
_transitive_from_associates_test,
210277
],
211278
)

0 commit comments

Comments
 (0)