@@ -18,6 +18,10 @@ These are internal rules not to be used outside of the
18
18
@build_bazel_rules_apple//apple package.
19
19
"""
20
20
21
+ load (
22
+ "@build_bazel_rules_apple//apple/internal:experimental.bzl" ,
23
+ "is_experimental_tree_artifact_enabled" ,
24
+ )
21
25
load (
22
26
"@build_bazel_rules_apple//apple/internal:file_support.bzl" ,
23
27
"file_support" ,
@@ -376,15 +380,15 @@ def _apple_ui_test_attributes():
376
380
},
377
381
)
378
382
379
- def _get_template_substitutions (ctx , test_type ):
383
+ def _get_template_substitutions (test_type , test_bundle , test_host = None ):
380
384
"""Dictionary with the substitutions to be applied to the template script."""
381
385
subs = {}
382
386
383
- if ctx . attr . test_host :
384
- subs ["test_host_path" ] = ctx . attr . test_host [ AppleBundleInfo ]. archive .short_path
387
+ if test_host :
388
+ subs ["test_host_path" ] = test_host .short_path
385
389
else :
386
390
subs ["test_host_path" ] = ""
387
- subs ["test_bundle_path" ] = ctx . outputs . test_bundle .short_path
391
+ subs ["test_bundle_path" ] = test_bundle .short_path
388
392
subs ["test_type" ] = test_type .upper ()
389
393
390
394
return {"%(" + k + ")s" : subs [k ] for k in subs }
@@ -418,11 +422,11 @@ def _apple_test_impl(ctx, test_type):
418
422
runner .test_environment ,
419
423
)
420
424
421
- direct_runfiles = [ctx . outputs . test_bundle ]
425
+ direct_runfiles = []
422
426
transitive_runfiles = []
423
- test_host = ctx . attr . test_host
424
- if test_host :
425
- direct_runfiles . append ( test_host [ AppleBundleInfo ]. archive )
427
+
428
+ direct_outputs = []
429
+ transitive_outputs = []
426
430
427
431
if ctx .configuration .coverage_enabled :
428
432
test_environment = dicts .add (
@@ -439,34 +443,50 @@ def _apple_test_impl(ctx, test_type):
439
443
transitive_runfiles .append (ctx .attr ._mcov .files )
440
444
transitive_runfiles .append (ctx .attr ._apple_coverage_support .files )
441
445
442
- file_support .symlink (
443
- ctx ,
444
- ctx .attr .test_bundle [AppleBundleInfo ].archive ,
445
- ctx .outputs .test_bundle ,
446
- )
446
+ if is_experimental_tree_artifact_enabled (ctx ):
447
+ ctx .actions .write (
448
+ output = ctx .outputs .test_bundle ,
449
+ content = "test" ,
450
+ )
451
+ test_bundle = ctx .attr .test_bundle [AppleBundleInfo ].archive
452
+ else :
453
+ file_support .symlink (
454
+ ctx ,
455
+ ctx .attr .test_bundle [AppleBundleInfo ].archive ,
456
+ ctx .outputs .test_bundle ,
457
+ )
458
+ test_bundle = ctx .outputs .test_bundle
459
+
460
+ direct_outputs .append (test_bundle )
461
+ direct_runfiles .append (test_bundle )
462
+
463
+ test_host = ctx .attr .test_host
464
+ test_host_archive = None
465
+ if test_host :
466
+ test_host_archive = test_host [AppleBundleInfo ].archive
467
+ direct_runfiles .append (test_host_archive )
447
468
448
469
executable = ctx .actions .declare_file ("%s" % ctx .label .name )
449
470
ctx .actions .expand_template (
450
471
template = runner .test_runner_template ,
451
472
output = executable ,
452
- substitutions = _get_template_substitutions (ctx , test_type ),
473
+ substitutions = _get_template_substitutions (
474
+ test_type ,
475
+ test_bundle ,
476
+ test_host = test_host_archive ,
477
+ ),
453
478
)
479
+ direct_outputs .append (executable )
454
480
455
481
# Add required data into the runfiles to make it available during test
456
482
# execution.
457
483
for data_dep in ctx .attr .data :
458
484
transitive_runfiles .append (data_dep .files )
459
485
460
- transitive_outputs = []
461
486
extra_outputs_provider = ctx .attr .test_bundle [AppleExtraOutputsInfo ]
462
487
if extra_outputs_provider :
463
488
transitive_outputs .append (extra_outputs_provider .files )
464
489
465
- outputs = depset (
466
- direct = [ctx .outputs .test_bundle , executable ],
467
- transitive = transitive_outputs ,
468
- )
469
-
470
490
extra_providers = []
471
491
472
492
# TODO(b/110264170): Repropagate the provider that makes the dSYM bundle
@@ -485,7 +505,7 @@ def _apple_test_impl(ctx, test_type):
485
505
testing .TestEnvironment (test_environment ),
486
506
DefaultInfo (
487
507
executable = executable ,
488
- files = outputs ,
508
+ files = depset ( direct_outputs , transitive = transitive_outputs ) ,
489
509
runfiles = ctx .runfiles (
490
510
files = direct_runfiles ,
491
511
transitive_files = depset (transitive = transitive_runfiles ),
0 commit comments