@@ -30,16 +30,20 @@ _SKIP_TEST = {
30
30
}
31
31
32
32
def _simple_binary_impl (ctx ):
33
- output = ctx .actions .declare_file (ctx .label .name )
34
- ctx .actions .write (output , "" , is_executable = True )
33
+ executable = ctx .actions .declare_file (ctx .label .name )
34
+ ctx .actions .write (executable , "" , is_executable = True )
35
35
return [DefaultInfo (
36
- executable = output ,
36
+ executable = executable ,
37
+ files = depset ([executable ] + ctx .files .extra_default_outputs ),
37
38
runfiles = ctx .runfiles (ctx .files .data ),
38
39
)]
39
40
40
41
_simple_binary = rule (
41
42
implementation = _simple_binary_impl ,
42
- attrs = {"data" : attr .label_list (allow_files = True )},
43
+ attrs = {
44
+ "data" : attr .label_list (allow_files = True ),
45
+ "extra_default_outputs" : attr .label_list (allow_files = True ),
46
+ },
43
47
executable = True ,
44
48
)
45
49
@@ -239,6 +243,95 @@ def _test_in_build_interpreter_impl(env, target):
239
243
240
244
_tests .append (_test_in_build_interpreter )
241
245
246
+ def _test_interpreter_binary_with_multiple_outputs (name ):
247
+ rt_util .helper_target (
248
+ _simple_binary ,
249
+ name = name + "_built_interpreter" ,
250
+ extra_default_outputs = ["extra_default_output.txt" ],
251
+ data = ["runfile.txt" ],
252
+ )
253
+
254
+ rt_util .helper_target (
255
+ py_runtime ,
256
+ name = name + "_subject" ,
257
+ interpreter = name + "_built_interpreter" ,
258
+ python_version = "PY3" ,
259
+ )
260
+ analysis_test (
261
+ name = name ,
262
+ target = name + "_subject" ,
263
+ impl = _test_interpreter_binary_with_multiple_outputs_impl ,
264
+ )
265
+
266
+ def _test_interpreter_binary_with_multiple_outputs_impl (env , target ):
267
+ target = env .expect .that_target (target )
268
+ py_runtime_info = target .provider (
269
+ PyRuntimeInfo ,
270
+ factory = py_runtime_info_subject ,
271
+ )
272
+ py_runtime_info .interpreter ().short_path_equals ("{package}/{test_name}_built_interpreter" )
273
+ py_runtime_info .files ().contains_exactly ([
274
+ "{package}/extra_default_output.txt" ,
275
+ "{package}/runfile.txt" ,
276
+ "{package}/{test_name}_built_interpreter" ,
277
+ ])
278
+
279
+ target .default_outputs ().contains_exactly ([
280
+ "{package}/extra_default_output.txt" ,
281
+ "{package}/runfile.txt" ,
282
+ "{package}/{test_name}_built_interpreter" ,
283
+ ])
284
+
285
+ target .runfiles ().contains_exactly ([
286
+ "{workspace}/{package}/runfile.txt" ,
287
+ "{workspace}/{package}/{test_name}_built_interpreter" ,
288
+ ])
289
+
290
+ _tests .append (_test_interpreter_binary_with_multiple_outputs )
291
+
292
+ def _test_interpreter_binary_with_single_output_and_runfiles (name ):
293
+ rt_util .helper_target (
294
+ _simple_binary ,
295
+ name = name + "_built_interpreter" ,
296
+ data = ["runfile.txt" ],
297
+ )
298
+
299
+ rt_util .helper_target (
300
+ py_runtime ,
301
+ name = name + "_subject" ,
302
+ interpreter = name + "_built_interpreter" ,
303
+ python_version = "PY3" ,
304
+ )
305
+ analysis_test (
306
+ name = name ,
307
+ target = name + "_subject" ,
308
+ impl = _test_interpreter_binary_with_single_output_and_runfiles_impl ,
309
+ )
310
+
311
+ def _test_interpreter_binary_with_single_output_and_runfiles_impl (env , target ):
312
+ target = env .expect .that_target (target )
313
+ py_runtime_info = target .provider (
314
+ PyRuntimeInfo ,
315
+ factory = py_runtime_info_subject ,
316
+ )
317
+ py_runtime_info .interpreter ().short_path_equals ("{package}/{test_name}_built_interpreter" )
318
+ py_runtime_info .files ().contains_exactly ([
319
+ "{package}/runfile.txt" ,
320
+ "{package}/{test_name}_built_interpreter" ,
321
+ ])
322
+
323
+ target .default_outputs ().contains_exactly ([
324
+ "{package}/runfile.txt" ,
325
+ "{package}/{test_name}_built_interpreter" ,
326
+ ])
327
+
328
+ target .runfiles ().contains_exactly ([
329
+ "{workspace}/{package}/runfile.txt" ,
330
+ "{workspace}/{package}/{test_name}_built_interpreter" ,
331
+ ])
332
+
333
+ _tests .append (_test_interpreter_binary_with_single_output_and_runfiles )
334
+
242
335
def _test_must_have_either_inbuild_or_system_interpreter (name ):
243
336
if br_util .is_bazel_6_or_higher ():
244
337
py_runtime_kwargs = {}
0 commit comments