@@ -62,12 +62,14 @@ private enum CommandMode {
62
62
private static final GoogleLogger logger = GoogleLogger .forEnclosingClass ();
63
63
64
64
private final CommandMode commandMode ;
65
+ private final boolean downloadToplevel ;
65
66
private final MemoizingEvaluator memoizingEvaluator ;
66
67
private final AbstractActionInputPrefetcher actionInputPrefetcher ;
67
68
private final PathToMetadataConverter pathToMetadataConverter ;
68
69
69
70
public ToplevelArtifactsDownloader (
70
71
String commandName ,
72
+ boolean downloadToplevel ,
71
73
MemoizingEvaluator memoizingEvaluator ,
72
74
AbstractActionInputPrefetcher actionInputPrefetcher ,
73
75
PathToMetadataConverter pathToMetadataConverter ) {
@@ -84,6 +86,7 @@ public ToplevelArtifactsDownloader(
84
86
default :
85
87
this .commandMode = CommandMode .UNKNOWN ;
86
88
}
89
+ this .downloadToplevel = downloadToplevel ;
87
90
this .memoizingEvaluator = memoizingEvaluator ;
88
91
this .actionInputPrefetcher = actionInputPrefetcher ;
89
92
this .pathToMetadataConverter = pathToMetadataConverter ;
@@ -133,6 +136,10 @@ public void onFailure(Throwable throwable) {
133
136
@ Subscribe
134
137
@ AllowConcurrentEvents
135
138
public void onAspectComplete (AspectCompleteEvent event ) {
139
+ if (!shouldDownloadToplevelOutputs (event .getAspectKey ().getBaseConfiguredTargetKey ())) {
140
+ return ;
141
+ }
142
+
136
143
if (event .failed ()) {
137
144
return ;
138
145
}
@@ -143,7 +150,7 @@ public void onAspectComplete(AspectCompleteEvent event) {
143
150
@ Subscribe
144
151
@ AllowConcurrentEvents
145
152
public void onTargetComplete (TargetCompleteEvent event ) {
146
- if (!shouldDownloadToplevelOutputsForTarget (event .getConfiguredTargetKey ())) {
153
+ if (!shouldDownloadToplevelOutputs (event .getConfiguredTargetKey ())) {
147
154
return ;
148
155
}
149
156
@@ -156,28 +163,32 @@ public void onTargetComplete(TargetCompleteEvent event) {
156
163
event .getExecutableTargetData ().getRunfiles ());
157
164
}
158
165
159
- private boolean shouldDownloadToplevelOutputsForTarget (ConfiguredTargetKey configuredTargetKey ) {
160
- if (commandMode != CommandMode .TEST ) {
161
- return true ;
162
- }
163
-
164
- // Do not download test binary in test mode.
165
- try {
166
- var configuredTargetValue =
167
- (ConfiguredTargetValue ) memoizingEvaluator .getExistingValue (configuredTargetKey );
168
- if (configuredTargetValue == null ) {
169
- return false ;
170
- }
171
- ConfiguredTarget configuredTarget = configuredTargetValue .getConfiguredTarget ();
172
- if (configuredTarget instanceof RuleConfiguredTarget ) {
173
- var ruleConfiguredTarget = (RuleConfiguredTarget ) configuredTarget ;
174
- var isTestRule = isTestRuleName (ruleConfiguredTarget .getRuleClassString ());
175
- return !isTestRule ;
176
- }
177
- return true ;
178
- } catch (InterruptedException ignored ) {
179
- Thread .currentThread ().interrupt ();
180
- return false ;
166
+ private boolean shouldDownloadToplevelOutputs (ConfiguredTargetKey configuredTargetKey ) {
167
+ switch (commandMode ) {
168
+ case RUN :
169
+ // Always download outputs of toplevel targets in RUN mode
170
+ return true ;
171
+ case TEST :
172
+ // Do not download test binary in test mode.
173
+ try {
174
+ var configuredTargetValue =
175
+ (ConfiguredTargetValue ) memoizingEvaluator .getExistingValue (configuredTargetKey );
176
+ if (configuredTargetValue == null ) {
177
+ return false ;
178
+ }
179
+ ConfiguredTarget configuredTarget = configuredTargetValue .getConfiguredTarget ();
180
+ if (configuredTarget instanceof RuleConfiguredTarget ) {
181
+ var ruleConfiguredTarget = (RuleConfiguredTarget ) configuredTarget ;
182
+ var isTestRule = isTestRuleName (ruleConfiguredTarget .getRuleClassString ());
183
+ return !isTestRule ;
184
+ }
185
+ return true ;
186
+ } catch (InterruptedException ignored ) {
187
+ Thread .currentThread ().interrupt ();
188
+ return false ;
189
+ }
190
+ default :
191
+ return downloadToplevel ;
181
192
}
182
193
}
183
194
0 commit comments