25
25
import com .google .devtools .build .lib .actions .ActionExecutionContext ;
26
26
import com .google .devtools .build .lib .actions .ActionInput ;
27
27
import com .google .devtools .build .lib .actions .ActionInputHelper ;
28
- import com .google .devtools .build .lib .actions .Artifact ;
29
- import com .google .devtools .build .lib .actions .Artifact .DerivedArtifact ;
30
28
import com .google .devtools .build .lib .actions .Artifact .SpecialArtifact ;
31
- import com .google .devtools .build .lib .actions .Artifact .TreeFileArtifact ;
32
29
import com .google .devtools .build .lib .actions .ArtifactPathResolver ;
33
30
import com .google .devtools .build .lib .actions .EnvironmentalExecException ;
34
31
import com .google .devtools .build .lib .actions .ExecException ;
35
32
import com .google .devtools .build .lib .actions .ExecutionRequirements ;
36
- import com .google .devtools .build .lib .actions .FileArtifactValue ;
37
33
import com .google .devtools .build .lib .actions .ResourceSet ;
38
34
import com .google .devtools .build .lib .actions .SimpleSpawn ;
39
35
import com .google .devtools .build .lib .actions .Spawn ;
40
36
import com .google .devtools .build .lib .actions .SpawnContinuation ;
41
37
import com .google .devtools .build .lib .actions .SpawnResult ;
42
38
import com .google .devtools .build .lib .actions .TestExecException ;
43
- import com .google .devtools .build .lib .actions .cache .MetadataHandler ;
44
39
import com .google .devtools .build .lib .analysis .actions .SpawnAction ;
45
40
import com .google .devtools .build .lib .analysis .test .TestAttempt ;
46
41
import com .google .devtools .build .lib .analysis .test .TestResult ;
55
50
import com .google .devtools .build .lib .events .Reporter ;
56
51
import com .google .devtools .build .lib .server .FailureDetails .Execution .Code ;
57
52
import com .google .devtools .build .lib .server .FailureDetails .TestAction ;
58
- import com .google .devtools .build .lib .skyframe .TreeArtifactValue ;
59
53
import com .google .devtools .build .lib .util .Pair ;
60
54
import com .google .devtools .build .lib .util .io .FileOutErr ;
61
55
import com .google .devtools .build .lib .vfs .FileStatus ;
73
67
import java .util .List ;
74
68
import java .util .Map ;
75
69
import java .util .TreeMap ;
76
- import java .util .concurrent .ConcurrentHashMap ;
77
- import java .util .concurrent .ConcurrentMap ;
78
70
import javax .annotation .Nullable ;
79
71
80
72
/** Runs TestRunnerAction actions. */
@@ -143,7 +135,7 @@ public TestRunnerSpawn createTestRunnerSpawn(
143
135
action .getTestProperties ().isPersistentTestRunner ()
144
136
? action .getTools ()
145
137
: NestedSetBuilder .emptySet (Order .STABLE_ORDER ),
146
- createSpawnOutputs (action ),
138
+ ImmutableSet . copyOf (action . getSpawnOutputs () ),
147
139
localResourceUsage );
148
140
Path execRoot = actionExecutionContext .getExecRoot ();
149
141
ArtifactPathResolver pathResolver = actionExecutionContext .getPathResolver ();
@@ -154,21 +146,6 @@ public TestRunnerSpawn createTestRunnerSpawn(
154
146
action , actionExecutionContext , spawn , tmpDir , workingDirectory , execRoot );
155
147
}
156
148
157
- private ImmutableSet <ActionInput > createSpawnOutputs (TestRunnerAction action ) {
158
- ImmutableSet .Builder <ActionInput > builder = ImmutableSet .builder ();
159
- for (ActionInput output : action .getSpawnOutputs ()) {
160
- if (output .getExecPath ().equals (action .getXmlOutputPath ())) {
161
- // HACK: Convert type of test.xml from BasicActionInput to DerivedArtifact. We want to
162
- // inject metadata of test.xml if it is generated remotely and it's currently only possible
163
- // to inject Artifact.
164
- builder .add (createArtifactOutput (action , output .getExecPath ()));
165
- } else {
166
- builder .add (output );
167
- }
168
- }
169
- return builder .build ();
170
- }
171
-
172
149
private static ImmutableList <Pair <String , Path >> renameOutputs (
173
150
ActionExecutionContext actionExecutionContext ,
174
151
TestRunnerAction action ,
@@ -317,84 +294,11 @@ private static Map<String, String> setupEnvironment(
317
294
relativeTmpDir = tmpDir .asFragment ();
318
295
}
319
296
return DEFAULT_LOCAL_POLICY .computeTestEnvironment (
320
- action , clientEnv , getTimeout (action ), runfilesDir .relativeTo (execRoot ), relativeTmpDir );
321
- }
322
-
323
- static class TestMetadataHandler implements MetadataHandler {
324
- private final MetadataHandler metadataHandler ;
325
- private final ImmutableSet <Artifact > outputs ;
326
- private final ConcurrentMap <Artifact , FileArtifactValue > fileMetadataMap =
327
- new ConcurrentHashMap <>();
328
-
329
- TestMetadataHandler (MetadataHandler metadataHandler , ImmutableSet <Artifact > outputs ) {
330
- this .metadataHandler = metadataHandler ;
331
- this .outputs = outputs ;
332
- }
333
-
334
- @ Nullable
335
- @ Override
336
- public ActionInput getInput (String execPath ) {
337
- return metadataHandler .getInput (execPath );
338
- }
339
-
340
- @ Nullable
341
- @ Override
342
- public FileArtifactValue getMetadata (ActionInput input ) throws IOException {
343
- return metadataHandler .getMetadata (input );
344
- }
345
-
346
- @ Override
347
- public void setDigestForVirtualArtifact (Artifact artifact , byte [] digest ) {
348
- metadataHandler .setDigestForVirtualArtifact (artifact , digest );
349
- }
350
-
351
- @ Override
352
- public FileArtifactValue constructMetadataForDigest (
353
- Artifact output , FileStatus statNoFollow , byte [] injectedDigest ) throws IOException {
354
- return metadataHandler .constructMetadataForDigest (output , statNoFollow , injectedDigest );
355
- }
356
-
357
- @ Override
358
- public ImmutableSet <TreeFileArtifact > getTreeArtifactChildren (SpecialArtifact treeArtifact ) {
359
- return metadataHandler .getTreeArtifactChildren (treeArtifact );
360
- }
361
-
362
- @ Override
363
- public TreeArtifactValue getTreeArtifactValue (SpecialArtifact treeArtifact ) throws IOException {
364
- return metadataHandler .getTreeArtifactValue (treeArtifact );
365
- }
366
-
367
- @ Override
368
- public void markOmitted (Artifact output ) {
369
- metadataHandler .markOmitted (output );
370
- }
371
-
372
- @ Override
373
- public boolean artifactOmitted (Artifact artifact ) {
374
- return metadataHandler .artifactOmitted (artifact );
375
- }
376
-
377
- @ Override
378
- public void resetOutputs (Iterable <? extends Artifact > outputs ) {
379
- metadataHandler .resetOutputs (outputs );
380
- }
381
-
382
- @ Override
383
- public void injectFile (Artifact output , FileArtifactValue metadata ) {
384
- if (outputs .contains (output )) {
385
- metadataHandler .injectFile (output , metadata );
386
- }
387
- fileMetadataMap .put (output , metadata );
388
- }
389
-
390
- @ Override
391
- public void injectTree (SpecialArtifact output , TreeArtifactValue tree ) {
392
- metadataHandler .injectTree (output , tree );
393
- }
394
-
395
- public boolean fileInjected (Artifact output ) {
396
- return fileMetadataMap .containsKey (output );
397
- }
297
+ action ,
298
+ clientEnv ,
299
+ getTimeout (action ),
300
+ runfilesDir .relativeTo (execRoot ),
301
+ relativeTmpDir );
398
302
}
399
303
400
304
private TestAttemptContinuation beginTestAttempt (
@@ -413,26 +317,12 @@ private TestAttemptContinuation beginTestAttempt(
413
317
createStreamedTestOutput (
414
318
Reporter .outErrForReporter (actionExecutionContext .getEventHandler ()), out );
415
319
}
416
-
417
- // We use TestMetadataHandler here mainly because the one provided by actionExecutionContext
418
- // doesn't allow to inject undeclared outputs and test.xml is undeclared by the test action.
419
- TestMetadataHandler testMetadataHandler = null ;
420
- if (actionExecutionContext .getMetadataHandler () != null ) {
421
- testMetadataHandler =
422
- new TestMetadataHandler (
423
- actionExecutionContext .getMetadataHandler (), testAction .getOutputs ());
424
- }
425
-
426
320
long startTimeMillis = actionExecutionContext .getClock ().currentTimeMillis ();
427
321
SpawnStrategyResolver resolver = actionExecutionContext .getContext (SpawnStrategyResolver .class );
428
322
SpawnContinuation spawnContinuation ;
429
323
try {
430
324
spawnContinuation =
431
- resolver .beginExecution (
432
- spawn ,
433
- actionExecutionContext
434
- .withFileOutErr (testOutErr )
435
- .withMetadataHandler (testMetadataHandler ));
325
+ resolver .beginExecution (spawn , actionExecutionContext .withFileOutErr (testOutErr ));
436
326
} catch (InterruptedException e ) {
437
327
if (streamed != null ) {
438
328
streamed .close ();
@@ -442,7 +332,6 @@ private TestAttemptContinuation beginTestAttempt(
442
332
}
443
333
return new BazelTestAttemptContinuation (
444
334
testAction ,
445
- testMetadataHandler ,
446
335
actionExecutionContext ,
447
336
spawn ,
448
337
resolvedPaths ,
@@ -498,12 +387,6 @@ private static BuildEventStreamProtos.TestResult.ExecutionInfo extractExecutionI
498
387
return executionInfo .build ();
499
388
}
500
389
501
- private static Artifact .DerivedArtifact createArtifactOutput (
502
- TestRunnerAction action , PathFragment outputPath ) {
503
- Artifact .DerivedArtifact testLog = (Artifact .DerivedArtifact ) action .getTestLog ();
504
- return new DerivedArtifact (testLog .getRoot (), outputPath , testLog .getArtifactOwner ());
505
- }
506
-
507
390
/**
508
391
* A spawn to generate a test.xml file from the test log. This is only used if the test does not
509
392
* generate a test.xml file itself.
@@ -540,7 +423,7 @@ private static Spawn createXmlGeneratingSpawn(
540
423
/*inputs=*/ NestedSetBuilder .create (
541
424
Order .STABLE_ORDER , action .getTestXmlGeneratorScript (), action .getTestLog ()),
542
425
/*tools=*/ NestedSetBuilder .emptySet (Order .STABLE_ORDER ),
543
- /*outputs=*/ ImmutableSet .of (createArtifactOutput ( action , action .getXmlOutputPath ())),
426
+ /*outputs=*/ ImmutableSet .of (ActionInputHelper . fromPath ( action .getXmlOutputPath ())),
544
427
SpawnAction .DEFAULT_RESOURCE_SET );
545
428
}
546
429
@@ -693,7 +576,6 @@ public void finalizeCancelledTest(List<FailedAttemptResult> failedAttempts) thro
693
576
694
577
private final class BazelTestAttemptContinuation extends TestAttemptContinuation {
695
578
private final TestRunnerAction testAction ;
696
- @ Nullable private final TestMetadataHandler testMetadataHandler ;
697
579
private final ActionExecutionContext actionExecutionContext ;
698
580
private final Spawn spawn ;
699
581
private final ResolvedPaths resolvedPaths ;
@@ -706,7 +588,6 @@ private final class BazelTestAttemptContinuation extends TestAttemptContinuation
706
588
707
589
BazelTestAttemptContinuation (
708
590
TestRunnerAction testAction ,
709
- @ Nullable TestMetadataHandler testMetadataHandler ,
710
591
ActionExecutionContext actionExecutionContext ,
711
592
Spawn spawn ,
712
593
ResolvedPaths resolvedPaths ,
@@ -717,7 +598,6 @@ private final class BazelTestAttemptContinuation extends TestAttemptContinuation
717
598
TestResultData .Builder testResultDataBuilder ,
718
599
ImmutableList <SpawnResult > spawnResults ) {
719
600
this .testAction = testAction ;
720
- this .testMetadataHandler = testMetadataHandler ;
721
601
this .actionExecutionContext = actionExecutionContext ;
722
602
this .spawn = spawn ;
723
603
this .resolvedPaths = resolvedPaths ;
@@ -758,7 +638,6 @@ public TestAttemptContinuation execute()
758
638
if (!nextContinuation .isDone ()) {
759
639
return new BazelTestAttemptContinuation (
760
640
testAction ,
761
- testMetadataHandler ,
762
641
actionExecutionContext ,
763
642
spawn ,
764
643
resolvedPaths ,
@@ -848,7 +727,6 @@ public TestAttemptContinuation execute()
848
727
appendCoverageLog (coverageOutErr , fileOutErr );
849
728
return new BazelCoveragePostProcessingContinuation (
850
729
testAction ,
851
- testMetadataHandler ,
852
730
actionExecutionContext ,
853
731
spawn ,
854
732
resolvedPaths ,
@@ -884,21 +762,15 @@ public TestAttemptContinuation execute()
884
762
throw new EnvironmentalExecException (e , Code .TEST_OUT_ERR_IO_EXCEPTION );
885
763
}
886
764
887
- Path xmlOutputPath = resolvedPaths .getXmlOutputPath ();
888
- boolean testXmlGenerated = xmlOutputPath .exists ();
889
- if (!testXmlGenerated && testMetadataHandler != null ) {
890
- testXmlGenerated =
891
- testMetadataHandler .fileInjected (
892
- createArtifactOutput (testAction , testAction .getXmlOutputPath ()));
893
- }
894
765
895
766
// If the test did not create a test.xml, and --experimental_split_xml_generation is enabled,
896
767
// then we run a separate action to create a test.xml from test.log. We do this as a spawn
897
768
// rather than doing it locally in-process, as the test.log file may only exist remotely (when
898
769
// remote execution is enabled), and we do not want to have to download it.
770
+ Path xmlOutputPath = resolvedPaths .getXmlOutputPath ();
899
771
if (executionOptions .splitXmlGeneration
900
772
&& fileOutErr .getOutputPath ().exists ()
901
- && !testXmlGenerated ) {
773
+ && !xmlOutputPath . exists () ) {
902
774
Spawn xmlGeneratingSpawn =
903
775
createXmlGeneratingSpawn (testAction , spawn .getEnvironment (), spawnResults .get (0 ));
904
776
SpawnStrategyResolver spawnStrategyResolver =
@@ -909,10 +781,7 @@ public TestAttemptContinuation execute()
909
781
try {
910
782
SpawnContinuation xmlContinuation =
911
783
spawnStrategyResolver .beginExecution (
912
- xmlGeneratingSpawn ,
913
- actionExecutionContext
914
- .withFileOutErr (xmlSpawnOutErr )
915
- .withMetadataHandler (testMetadataHandler ));
784
+ xmlGeneratingSpawn , actionExecutionContext .withFileOutErr (xmlSpawnOutErr ));
916
785
return new BazelXmlCreationContinuation (
917
786
resolvedPaths , xmlSpawnOutErr , testResultDataBuilder , spawnResults , xmlContinuation );
918
787
} catch (InterruptedException e ) {
@@ -1010,7 +879,6 @@ public TestAttemptContinuation execute() throws InterruptedException, ExecExcept
1010
879
1011
880
private final class BazelCoveragePostProcessingContinuation extends TestAttemptContinuation {
1012
881
private final ResolvedPaths resolvedPaths ;
1013
- @ Nullable private final TestMetadataHandler testMetadataHandler ;
1014
882
private final FileOutErr fileOutErr ;
1015
883
private final Closeable streamed ;
1016
884
private final TestResultData .Builder testResultDataBuilder ;
@@ -1022,7 +890,6 @@ private final class BazelCoveragePostProcessingContinuation extends TestAttemptC
1022
890
1023
891
BazelCoveragePostProcessingContinuation (
1024
892
TestRunnerAction testAction ,
1025
- @ Nullable TestMetadataHandler testMetadataHandler ,
1026
893
ActionExecutionContext actionExecutionContext ,
1027
894
Spawn spawn ,
1028
895
ResolvedPaths resolvedPaths ,
@@ -1032,7 +899,6 @@ private final class BazelCoveragePostProcessingContinuation extends TestAttemptC
1032
899
ImmutableList <SpawnResult > primarySpawnResults ,
1033
900
SpawnContinuation spawnContinuation ) {
1034
901
this .testAction = testAction ;
1035
- this .testMetadataHandler = testMetadataHandler ;
1036
902
this .actionExecutionContext = actionExecutionContext ;
1037
903
this .spawn = spawn ;
1038
904
this .resolvedPaths = resolvedPaths ;
@@ -1057,7 +923,6 @@ public TestAttemptContinuation execute() throws InterruptedException, ExecExcept
1057
923
if (!nextContinuation .isDone ()) {
1058
924
return new BazelCoveragePostProcessingContinuation (
1059
925
testAction ,
1060
- testMetadataHandler ,
1061
926
actionExecutionContext ,
1062
927
spawn ,
1063
928
resolvedPaths ,
@@ -1093,7 +958,6 @@ public TestAttemptContinuation execute() throws InterruptedException, ExecExcept
1093
958
1094
959
return new BazelTestAttemptContinuation (
1095
960
testAction ,
1096
- testMetadataHandler ,
1097
961
actionExecutionContext ,
1098
962
spawn ,
1099
963
resolvedPaths ,
0 commit comments