Skip to content

Commit 9ea77be

Browse files
authored
[exports] Propagate runfiles as part of exported resources (#1310)
* Includes runfiles in exports * Fix runfile collection * Repurpose core tests to support kt_jvm_library
1 parent 3c9ac00 commit 9ea77be

File tree

9 files changed

+401
-234
lines changed

9 files changed

+401
-234
lines changed

kotlin/internal/jvm/compile.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,13 +878,14 @@ def _run_kt_java_builder_actions(
878878
strict_deps = toolchains.kt.experimental_strict_kotlin_deps,
879879
)
880880
ap_generated_src_jar = java_info.annotation_processing.source_jar
881+
java_outputs = java_info.java_outputs if hasattr(java_info, "java_outputs") else java_info.outputs.jars
881882
compile_jars = compile_jars + [
882883
jars.ijar
883-
for jars in java_info.outputs.jars
884+
for jars in java_outputs
884885
]
885886
output_jars = output_jars + [
886887
jars.class_jar
887-
for jars in java_info.outputs.jars
888+
for jars in java_outputs
888889
]
889890
java_infos.append(java_info)
890891

kotlin/internal/jvm/impl.bzl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ load("//third_party:jarjar.bzl", "jarjar_action")
3737
def _is_absolute(path):
3838
return path.startswith("/") or (len(path) > 2 and path[1] == ":")
3939

40-
def _make_providers(ctx, providers, transitive_files = depset(order = "default"), *additional_providers):
40+
def _make_providers(ctx, providers, runfiles_targets, transitive_files = depset(order = "default"), *additional_providers):
4141
files = [ctx.outputs.jar]
4242
if providers.java.outputs.jdeps:
4343
files.append(providers.java.outputs.jdeps)
@@ -48,13 +48,13 @@ def _make_providers(ctx, providers, transitive_files = depset(order = "default")
4848
DefaultInfo(
4949
files = depset(files),
5050
runfiles = ctx.runfiles(
51-
# explicitly include data files, otherwise they appear to be missing
5251
files = ctx.files.data,
5352
transitive_files = transitive_files,
54-
# continue to use collect_default until proper transitive data collecting is
55-
# implmented.
56-
collect_default = True,
57-
),
53+
).merge_all([
54+
d[DefaultInfo].default_runfiles
55+
for d in runfiles_targets
56+
if DefaultInfo in d and d[DefaultInfo].default_runfiles
57+
]),
5858
),
5959
] + list(additional_providers)
6060

@@ -230,6 +230,7 @@ def kt_jvm_library_impl(ctx):
230230
outputs = ctx.outputs,
231231
attr = ctx.attr,
232232
),
233+
runfiles_targets = ctx.attr.deps + ctx.attr.exports,
233234
)
234235

235236
def kt_jvm_binary_impl(ctx):
@@ -250,7 +251,8 @@ def kt_jvm_binary_impl(ctx):
250251
return _make_providers(
251252
ctx,
252253
providers,
253-
depset(
254+
runfiles_targets = ctx.attr.deps,
255+
transitive_files = depset(
254256
order = "default",
255257
transitive = [providers.java.transitive_runtime_jars],
256258
direct = ctx.files._java_runtime,
@@ -306,6 +308,7 @@ def kt_jvm_junit_test_impl(ctx):
306308
return _make_providers(
307309
ctx,
308310
providers,
311+
ctx.attr.deps,
309312
depset(
310313
order = "default",
311314
transitive = [runtime_jars, depset(coverage_runfiles), depset(coverage_metadata)],

src/main/starlark/core/compile/cli/toolchain.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ KotlincJvmCompileInfo = provider(
1818
},
1919
)
2020

21+
COMPILE_MNEMONIC = "CliKotlinc"
22+
2123
def _cli_toolchain(ctx):
2224
java_runtime = ctx.toolchains[JAVA_RUNTIME_TOOLCHAIN_TYPE].java_runtime
2325
java_toolchain = ctx.toolchains[JAVA_TOOLCHAIN_TYPE].java
@@ -28,7 +30,7 @@ def _cli_toolchain(ctx):
2830
language_version = ".".join(ctx.attr.api_version.split(".")[:2]),
2931
executable_zip = ctx.attr.zip[DefaultInfo].files_to_run,
3032
kotlinc = ctx.attr.kotlinc[DefaultInfo].files_to_run,
31-
compile_mnemonic = "CliKotlinc",
33+
compile_mnemonic = COMPILE_MNEMONIC,
3234
single_jar = java_toolchain.single_jar,
3335
java_stub_template = ctx.files.java_stub_template[0],
3436
java_runtime = java_runtime,

src/main/starlark/core/compile/rules.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def _kt_jvm_library_impl(ctx):
110110
files = ctx.files.data,
111111
).merge_all([
112112
d[DefaultInfo].default_runfiles
113-
for d in ctx.attr.deps
113+
for d in ctx.attr.deps + ctx.attr.exports
114114
if DefaultInfo in d
115115
]),
116116
),

src/test/starlark/case.bzl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ def case(namespace):
4444
claim = lambda **kwargs: _claim(name = namespace, **kwargs),
4545
)
4646

47-
def suite(name, *tests):
47+
def suite(name, **tests):
4848
test_targets = []
49-
for test in tests:
50-
test_name = str(test).split(" ")[1]
51-
test_targets.append(":" + test_name)
49+
for test_name, test in tests.items():
5250
test(case(test_name))
5351

5452
native.test_suite(

src/test/starlark/compile/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
load(":common_tests.bzl", "test_suite")
1+
load(":rule_tests.bzl", "test_suite")
22

33
test_suite(
4-
name = "common_tests",
4+
name = "rules_tests",
55
)

src/test/starlark/compile/common_tests.bzl

Lines changed: 0 additions & 212 deletions
This file was deleted.

0 commit comments

Comments
 (0)