14
14
15
15
package com .google .devtools .build .lib .analysis .actions ;
16
16
17
- import static com .google .common .collect .ImmutableSet .toImmutableSet ;
18
17
import static com .google .devtools .build .lib .actions .ActionAnalysisMetadata .mergeMaps ;
19
18
import static com .google .devtools .build .lib .packages .ExecGroup .DEFAULT_EXEC_GROUP_NAME ;
20
19
@@ -104,7 +103,7 @@ public interface ExtraActionInfoSupplier {
104
103
105
104
private static final String GUID = "ebd6fce3-093e-45ee-adb6-bf513b602f0d" ;
106
105
107
- private static final Interner <ImmutableSortedMap <String , String >> executionInfoInterner =
106
+ public static final Interner <ImmutableSortedMap <String , String >> executionInfoInterner =
108
107
BlazeInterners .newWeakInterner ();
109
108
110
109
private final CommandLines commandLines ;
@@ -119,6 +118,7 @@ public interface ExtraActionInfoSupplier {
119
118
private final ImmutableMap <String , String > executionInfo ;
120
119
121
120
private final ExtraActionInfoSupplier extraActionInfoSupplier ;
121
+ private final Artifact primaryOutput ;
122
122
private final Consumer <Pair <ActionExecutionContext , List <SpawnResult >>> resultConsumer ;
123
123
private final boolean stripOutputPaths ;
124
124
@@ -132,6 +132,7 @@ public interface ExtraActionInfoSupplier {
132
132
* @param inputs the set of all files potentially read by this action; must not be subsequently
133
133
* modified.
134
134
* @param outputs the set of all files written by this action; must not be subsequently modified.
135
+ * @param primaryOutput the primary output of this action
135
136
* @param resourceSetOrBuilder the resources consumed by executing this Action.
136
137
* @param env the action environment
137
138
* @param commandLines the command lines to execute. This includes the main argv vector and any
@@ -147,6 +148,7 @@ public SpawnAction(
147
148
NestedSet <Artifact > tools ,
148
149
NestedSet <Artifact > inputs ,
149
150
Iterable <Artifact > outputs ,
151
+ Artifact primaryOutput ,
150
152
ResourceSetOrBuilder resourceSetOrBuilder ,
151
153
CommandLines commandLines ,
152
154
CommandLineLimits commandLineLimits ,
@@ -159,6 +161,7 @@ public SpawnAction(
159
161
tools ,
160
162
inputs ,
161
163
outputs ,
164
+ primaryOutput ,
162
165
resourceSetOrBuilder ,
163
166
commandLines ,
164
167
commandLineLimits ,
@@ -185,6 +188,7 @@ public SpawnAction(
185
188
* @param inputs the set of all files potentially read by this action; must not be subsequently
186
189
* modified
187
190
* @param outputs the set of all files written by this action; must not be subsequently modified.
191
+ * @param primaryOutput the primary output of this action
188
192
* @param resourceSetOrBuilder the resources consumed by executing this Action.
189
193
* @param env the action's environment
190
194
* @param executionInfo out-of-band information for scheduling the spawn
@@ -202,6 +206,7 @@ public SpawnAction(
202
206
NestedSet <Artifact > tools ,
203
207
NestedSet <Artifact > inputs ,
204
208
Iterable <? extends Artifact > outputs ,
209
+ Artifact primaryOutput ,
205
210
ResourceSetOrBuilder resourceSetOrBuilder ,
206
211
CommandLines commandLines ,
207
212
CommandLineLimits commandLineLimits ,
@@ -216,6 +221,7 @@ public SpawnAction(
216
221
Consumer <Pair <ActionExecutionContext , List <SpawnResult >>> resultConsumer ,
217
222
boolean stripOutputPaths ) {
218
223
super (owner , tools , inputs , runfilesSupplier , outputs , env );
224
+ this .primaryOutput = primaryOutput ;
219
225
this .resourceSetOrBuilder = resourceSetOrBuilder ;
220
226
this .executionInfo =
221
227
executionInfo .isEmpty ()
@@ -232,6 +238,11 @@ public SpawnAction(
232
238
this .stripOutputPaths = stripOutputPaths ;
233
239
}
234
240
241
+ @ Override
242
+ public Artifact getPrimaryOutput () {
243
+ return primaryOutput ;
244
+ }
245
+
235
246
@ VisibleForTesting
236
247
public CommandLines getCommandLines () {
237
248
return commandLines ;
@@ -250,10 +261,12 @@ public List<String> getArguments() throws CommandLineExpansionException, Interru
250
261
}
251
262
252
263
@ Override
253
- public Sequence <CommandLineArgsApi > getStarlarkArgs () {
264
+ public Sequence <CommandLineArgsApi > getStarlarkArgs () throws EvalException {
254
265
ImmutableList .Builder <CommandLineArgsApi > result = ImmutableList .builder ();
255
266
ImmutableSet <Artifact > directoryInputs =
256
- getInputs ().toList ().stream ().filter (Artifact ::isDirectory ).collect (toImmutableSet ());
267
+ getInputs ().toList ().stream ()
268
+ .filter (artifact -> artifact .isDirectory ())
269
+ .collect (ImmutableSet .toImmutableSet ());
257
270
258
271
for (CommandLineAndParamFileInfo commandLine : commandLines .getCommandLines ()) {
259
272
result .add (Args .forRegisteredAction (commandLine , directoryInputs ));
@@ -523,7 +536,7 @@ public ExtraActionInfo.Builder getExtraActionInfo(ActionKeyContext actionKeyCont
523
536
* <p>Subclasses of SpawnAction may override this in order to provide action-specific behaviour.
524
537
* This can be necessary, for example, when the action discovers inputs.
525
538
*/
526
- private SpawnInfo getExtraActionSpawnInfo ()
539
+ protected SpawnInfo getExtraActionSpawnInfo ()
527
540
throws CommandLineExpansionException , InterruptedException {
528
541
SpawnInfo .Builder info = SpawnInfo .newBuilder ();
529
542
Spawn spawn = getSpawnForExtraAction ();
@@ -588,7 +601,7 @@ private ActionSpawn(
588
601
throws CommandLineExpansionException {
589
602
super (
590
603
arguments ,
591
- ImmutableMap .of (),
604
+ ImmutableMap .< String , String > of (),
592
605
parent .getExecutionInfo (),
593
606
parent .getRunfilesSupplier (),
594
607
parent ,
@@ -792,7 +805,8 @@ private SpawnAction buildSpawnAction(
792
805
owner ,
793
806
tools ,
794
807
inputsAndTools ,
795
- ImmutableSet .copyOf (outputs ),
808
+ ImmutableList .copyOf (outputs ),
809
+ outputs .get (0 ),
796
810
resourceSetOrBuilder ,
797
811
commandLines ,
798
812
commandLineLimits ,
@@ -812,7 +826,8 @@ protected SpawnAction createSpawnAction(
812
826
ActionOwner owner ,
813
827
NestedSet <Artifact > tools ,
814
828
NestedSet <Artifact > inputsAndTools ,
815
- ImmutableSet <Artifact > outputs ,
829
+ ImmutableList <Artifact > outputs ,
830
+ Artifact primaryOutput ,
816
831
ResourceSetOrBuilder resourceSetOrBuilder ,
817
832
CommandLines commandLines ,
818
833
CommandLineLimits commandLineLimits ,
@@ -828,6 +843,7 @@ protected SpawnAction createSpawnAction(
828
843
tools ,
829
844
inputsAndTools ,
830
845
outputs ,
846
+ primaryOutput ,
831
847
resourceSetOrBuilder ,
832
848
commandLines ,
833
849
commandLineLimits ,
@@ -933,6 +949,13 @@ public Builder addOutputs(Iterable<Artifact> artifacts) {
933
949
return this ;
934
950
}
935
951
952
+ /**
953
+ * Checks whether the action produces any outputs
954
+ */
955
+ public boolean hasOutputs () {
956
+ return !outputs .isEmpty ();
957
+ }
958
+
936
959
/**
937
960
* Sets RecourceSet for builder. If ResourceSetBuilder set, then ResourceSetBuilder will
938
961
* override setResources.
0 commit comments