35
35
import com .google .devtools .build .lib .analysis .TargetCompleteEvent ;
36
36
import com .google .devtools .build .lib .analysis .TopLevelArtifactHelper .ArtifactsInOutputGroup ;
37
37
import com .google .devtools .build .lib .analysis .configuredtargets .RuleConfiguredTarget ;
38
+ import com .google .devtools .build .lib .analysis .test .CoverageReport ;
38
39
import com .google .devtools .build .lib .analysis .test .TestAttempt ;
39
40
import com .google .devtools .build .lib .remote .AbstractActionInputPrefetcher .Priority ;
40
41
import com .google .devtools .build .lib .remote .util .StaticMetadataProvider ;
@@ -56,7 +57,8 @@ private enum CommandMode {
56
57
UNKNOWN ,
57
58
BUILD ,
58
59
TEST ,
59
- RUN ;
60
+ RUN ,
61
+ COVERAGE ;
60
62
}
61
63
62
64
private static final GoogleLogger logger = GoogleLogger .forEnclosingClass ();
@@ -83,6 +85,9 @@ public ToplevelArtifactsDownloader(
83
85
case "run" :
84
86
this .commandMode = CommandMode .RUN ;
85
87
break ;
88
+ case "coverage" :
89
+ this .commandMode = CommandMode .COVERAGE ;
90
+ break ;
86
91
default :
87
92
this .commandMode = CommandMode .UNKNOWN ;
88
93
}
@@ -104,36 +109,48 @@ public interface PathToMetadataConverter {
104
109
FileArtifactValue getMetadata (Path path );
105
110
}
106
111
112
+ private void downloadTestOutput (Path path ) {
113
+ // Since the event is fired within action execution, the skyframe doesn't know the outputs of
114
+ // test actions yet, so we can't get their metadata through skyframe. However, the fileSystem
115
+ // of the path is an ActionFileSystem, we use it to get the metadata for this file.
116
+ //
117
+ // If the test hit action cache, the filesystem is local filesystem because the actual test
118
+ // action didn't get the chance to execute. In this case the metadata is null which is fine
119
+ // because test outputs are already downloaded (otherwise it cannot hit the action cache).
120
+ FileArtifactValue metadata = pathToMetadataConverter .getMetadata (path );
121
+ if (metadata != null ) {
122
+ ListenableFuture <Void > future =
123
+ actionInputPrefetcher .downloadFileAsync (path .asFragment (), metadata , Priority .LOW );
124
+ addCallback (
125
+ future ,
126
+ new FutureCallback <Void >() {
127
+ @ Override
128
+ public void onSuccess (Void unused ) {}
129
+
130
+ @ Override
131
+ public void onFailure (Throwable throwable ) {
132
+ logger .atWarning ().withCause (throwable ).log (
133
+ "Failed to download test output %s." , path );
134
+ }
135
+ },
136
+ directExecutor ());
137
+ }
138
+ }
139
+
107
140
@ Subscribe
108
141
@ AllowConcurrentEvents
109
142
public void onTestAttempt (TestAttempt event ) {
110
143
for (Pair <String , Path > pair : event .getFiles ()) {
111
144
Path path = checkNotNull (pair .getSecond ());
112
- // Since the event is fired within action execution, the skyframe doesn't know the outputs of
113
- // test actions yet, so we can't get their metadata through skyframe. However, the fileSystem
114
- // of the path is an ActionFileSystem, we use it to get the metadata for this file.
115
- //
116
- // If the test hit action cache, the filesystem is local filesystem because the actual test
117
- // action didn't get the chance to execute. In this case the metadata is null which is fine
118
- // because test outputs are already downloaded (otherwise it cannot hit the action cache).
119
- FileArtifactValue metadata = pathToMetadataConverter .getMetadata (path );
120
- if (metadata != null ) {
121
- ListenableFuture <Void > future =
122
- actionInputPrefetcher .downloadFileAsync (path .asFragment (), metadata , Priority .LOW );
123
- addCallback (
124
- future ,
125
- new FutureCallback <Void >() {
126
- @ Override
127
- public void onSuccess (Void unused ) {}
145
+ downloadTestOutput (path );
146
+ }
147
+ }
128
148
129
- @ Override
130
- public void onFailure (Throwable throwable ) {
131
- logger .atWarning ().withCause (throwable ).log (
132
- "Failed to download test output %s." , path );
133
- }
134
- },
135
- directExecutor ());
136
- }
149
+ @ Subscribe
150
+ @ AllowConcurrentEvents
151
+ public void onCoverageReport (CoverageReport event ) {
152
+ for (var file : event .getFiles ()) {
153
+ downloadTestOutput (file );
137
154
}
138
155
}
139
156
@@ -172,8 +189,9 @@ private boolean shouldDownloadToplevelOutputs(ConfiguredTargetKey configuredTarg
172
189
case RUN :
173
190
// Always download outputs of toplevel targets in RUN mode
174
191
return true ;
192
+ case COVERAGE :
175
193
case TEST :
176
- // Do not download test binary in test mode.
194
+ // Do not download test binary in test/coverage mode.
177
195
try {
178
196
var configuredTargetValue =
179
197
(ConfiguredTargetValue ) memoizingEvaluator .getExistingValue (configuredTargetKey );
0 commit comments