Skip to content

Commit 9e0932f

Browse files
committed
Fix non-file inclusion into runfiles for data. Add runtime_deps and data as sources for runfiles.
1 parent f6fe9e0 commit 9e0932f

File tree

3 files changed

+89
-10
lines changed

3 files changed

+89
-10
lines changed

kotlin/internal/jvm/impl.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@ def kt_jvm_library_impl(ctx):
224224
)
225225
return _make_providers(
226226
ctx,
227-
_compile.kt_jvm_produce_jar_actions(ctx, "kt_jvm_library") if ctx.attr.srcs or ctx.attr.resources else _compile.export_only_providers(
227+
providers = _compile.kt_jvm_produce_jar_actions(ctx, "kt_jvm_library") if ctx.attr.srcs or ctx.attr.resources else _compile.export_only_providers(
228228
ctx = ctx,
229229
actions = ctx.actions,
230230
outputs = ctx.outputs,
231231
attr = ctx.attr,
232232
),
233-
runfiles_targets = ctx.attr.deps + ctx.attr.exports,
233+
runfiles_targets = ctx.attr.deps + ctx.attr.exports + ctx.attr.runtime_deps + ctx.attr.data,
234234
)
235235

236236
def kt_jvm_binary_impl(ctx):
@@ -251,12 +251,12 @@ def kt_jvm_binary_impl(ctx):
251251
return _make_providers(
252252
ctx,
253253
providers,
254-
runfiles_targets = ctx.attr.deps,
255254
transitive_files = depset(
256255
order = "default",
257256
transitive = [providers.java.transitive_runtime_jars],
258257
direct = ctx.files._java_runtime,
259258
),
259+
runfiles_targets = ctx.attr.deps + ctx.attr.runtime_deps + ctx.attr.data,
260260
)
261261

262262
_SPLIT_STRINGS = [
@@ -308,7 +308,7 @@ def kt_jvm_junit_test_impl(ctx):
308308
return _make_providers(
309309
ctx,
310310
providers,
311-
ctx.attr.deps,
311+
ctx.attr.deps + ctx.attr.runtime_deps + ctx.attr.data,
312312
depset(
313313
order = "default",
314314
transitive = [runtime_jars, depset(coverage_runfiles), depset(coverage_metadata)],

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

Lines changed: 2 additions & 2 deletions
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 + ctx.attr.exports
113+
for d in ctx.attr.deps + ctx.attr.exports + ctx.attr.data + ctx.attr.runtime_deps
114114
if DefaultInfo in d
115115
]),
116116
),
@@ -166,7 +166,7 @@ def _kt_jvm_binary_impl(ctx):
166166
transitive_files = launch_runfiles,
167167
).merge_all([
168168
d[DefaultInfo].default_runfiles
169-
for d in ctx.attr.deps
169+
for d in ctx.attr.deps + ctx.attr.data + ctx.attr.runtime_deps
170170
if DefaultInfo in d
171171
]),
172172
executable = executable,

src/test/starlark/compile/rule_tests.bzl

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,84 @@ def _test_neverlink_deps(
122122

123123
return _case
124124

125-
def _test_deps_core(
125+
def _test_runfiles(
126+
rule_under_test,
127+
compile_mnemonic,
128+
srcjar_ext = ".srcjar",
129+
additional_compile_libs = [],
130+
**kwargs):
131+
def _case(test):
132+
transitive_data_file = test.artifact("transitive_data.file")
133+
transitive_data = test.have(
134+
rule_under_test,
135+
name = "transitive_data",
136+
srcs = [],
137+
deps = [],
138+
data = [transitive_data_file],
139+
**kwargs
140+
)
141+
data_file = test.artifact("data.file")
142+
data = test.have(
143+
rule_under_test,
144+
name = "data",
145+
srcs = [],
146+
runtime_deps = [transitive_data],
147+
data = [data_file],
148+
**kwargs
149+
)
150+
151+
got = test.got(
152+
rule_under_test,
153+
name = "got",
154+
srcs = [
155+
test.artifact("gave.kt"),
156+
],
157+
deps = [
158+
data,
159+
],
160+
**kwargs
161+
)
162+
test.claim(
163+
got = got,
164+
what = _outputs,
165+
wants = {
166+
"class_jar": Want(
167+
attr = attr.label(allow_single_file = True),
168+
value = got + ".jar",
169+
),
170+
"source_jar": Want(
171+
attr = attr.label(allow_single_file = True),
172+
value = got + srcjar_ext,
173+
),
174+
"inputs": Want(
175+
attr = attr.label_list(allow_empty = True, allow_files = True),
176+
value = [data],
177+
),
178+
"transitive_compile_deps": Want(
179+
attr = attr.label_list(providers = [[JavaInfo], [KtJvmInfo]]),
180+
value = [data, got] + additional_compile_libs,
181+
),
182+
"transitive_runtime_deps": Want(
183+
attr = attr.label_list(providers = [[JavaInfo], [KtJvmInfo]]),
184+
value = [got],
185+
),
186+
"compile_mnemonic": Want(
187+
attr = attr.string(),
188+
value = compile_mnemonic,
189+
),
190+
"runfiles": Want(
191+
attr = attr.label_list(allow_empty = True, allow_files = True),
192+
value = [
193+
data_file,
194+
transitive_data_file,
195+
],
196+
),
197+
},
198+
)
199+
200+
return _case
201+
202+
def _test_deps(
126203
rule_under_test,
127204
compile_mnemonic,
128205
srcjar_ext = ".srcjar",
@@ -344,13 +421,14 @@ def test_core():
344421
compile_mnemonic = COMPILE_MNEMONIC,
345422
)
346423
return dict(
347-
test_deps_core_kt_jvm_binary = _test_deps_core(**binary),
424+
test_deps_core_kt_jvm_binary = _test_deps(**binary),
348425
test_neverlink_deps_core_kt_jvm_binary = _test_neverlink_deps(**binary),
349426
test_no_deps_core_kt_jvm_binary = _test_no_deps(**binary),
350-
test_deps_core_kt_jvm_library = _test_deps_core(**library),
427+
test_deps_core_kt_jvm_library = _test_deps(**library),
351428
test_neverlink_deps_core_kt_jvm_library = _test_neverlink_deps(**library),
352429
test_no_deps_core_kt_jvm_library = _test_no_deps(**library),
353430
test_exports_core_kt_jvm_library = _test_exports(**library),
431+
test_runfiles_core = _test_runfiles(**library),
354432
)
355433

356434
def test_jvm():
@@ -366,10 +444,11 @@ def test_jvm():
366444
],
367445
)
368446
return dict(
369-
test_deps_kt_jvm_library = _test_deps_core(**library),
447+
test_deps_kt_jvm_library = _test_deps(**library),
370448
test_neverlink_deps_kt_jvm_library = _test_neverlink_deps(**library),
371449
test_no_deps_kt_jvm_library = _test_no_deps(**library),
372450
test_exports_kt_jvm_library = _test_exports(**library),
451+
test_runfiles = _test_runfiles(**library),
373452
)
374453

375454
def test_suite(name):

0 commit comments

Comments
 (0)