25
25
import com .google .common .util .concurrent .MoreExecutors ;
26
26
import com .google .devtools .build .lib .actions .ActionContext ;
27
27
import com .google .devtools .build .lib .actions .ActionExecutionContext ;
28
+ import com .google .devtools .build .lib .actions .ActionExecutionMetadata ;
29
+ import com .google .devtools .build .lib .actions .Artifact ;
28
30
import com .google .devtools .build .lib .actions .DynamicStrategyRegistry ;
29
31
import com .google .devtools .build .lib .actions .DynamicStrategyRegistry .DynamicMode ;
30
32
import com .google .devtools .build .lib .actions .EnvironmentalExecException ;
52
54
import java .util .concurrent .CancellationException ;
53
55
import java .util .concurrent .ExecutionException ;
54
56
import java .util .concurrent .ExecutorService ;
55
- import java .util .concurrent .TimeUnit ;
56
57
import java .util .concurrent .atomic .AtomicBoolean ;
57
58
import java .util .concurrent .atomic .AtomicReference ;
58
59
import java .util .function .Function ;
@@ -221,10 +222,7 @@ public ImmutableList<SpawnResult> exec(
221
222
return nonDynamicResults ;
222
223
}
223
224
224
- // Extra logging to debug b/194373457
225
- logger .atInfo ().atMostEvery (1 , TimeUnit .SECONDS ).log (
226
- "Spawn %s dynamically executed both ways" , spawn .getResourceOwner ().describe ());
227
- debugLog ("Dynamic execution of %s beginning%n" , spawn .getResourceOwner ().prettyPrint ());
225
+ debugLog ("Dynamic execution of %s beginning%n" , getSpawnReadableId (spawn ));
228
226
// else both can exec. Fallthrough to below.
229
227
230
228
AtomicReference <DynamicMode > strategyThatCancelled = new AtomicReference <>(null );
@@ -265,14 +263,9 @@ public ImmutableList<SpawnResult> exec(
265
263
tryScheduleLocalJob ();
266
264
}
267
265
}
268
- logger .atInfo ().atMostEvery (1 , TimeUnit .SECONDS ).log (
269
- "Dynamic execution of %s ended with local %s, remote %s%n" ,
270
- spawn .getResourceOwner ().prettyPrint (),
271
- localBranch .isCancelled () ? "cancelled" : "done" ,
272
- remoteBranch .isCancelled () ? "cancelled" : "done" );
273
266
debugLog (
274
267
"Dynamic execution of %s ended with local %s, remote %s%n" ,
275
- spawn . getResourceOwner (). prettyPrint ( ),
268
+ getSpawnReadableId ( spawn ),
276
269
localBranch .isCancelled () ? "cancelled" : "done" ,
277
270
remoteBranch .isCancelled () ? "cancelled" : "done" );
278
271
}
@@ -382,35 +375,21 @@ private ImmutableList<SpawnResult> maybeExecuteNonDynamically(
382
375
.build ();
383
376
debugLog (
384
377
"Dynamic execution of %s can be done neither locally nor remotely%n" ,
385
- spawn . getResourceOwner (). prettyPrint ( ));
378
+ getSpawnReadableId ( spawn ));
386
379
throw new UserExecException (failure );
387
380
} else if (!localCanExec && remoteCanExec ) {
388
- // Extra logging to debug b/194373457
389
- logger .atInfo ().atMostEvery (1 , TimeUnit .SECONDS ).log (
390
- "Dynamic execution of %s can only be done remotely: Local execution policy %s it, "
391
- + "local strategies are %s.%n" ,
392
- spawn .getResourceOwner ().prettyPrint (),
393
- executionPolicy .canRunLocally () ? "allows" : "forbids" ,
394
- dynamicStrategyRegistry .getDynamicSpawnActionContexts (spawn , DynamicMode .LOCAL ));
395
381
debugLog (
396
382
"Dynamic execution of %s can only be done remotely: Local execution policy %s it, "
397
383
+ "local strategies are %s.%n" ,
398
- spawn . getResourceOwner (). prettyPrint ( ),
384
+ getSpawnReadableId ( spawn ),
399
385
executionPolicy .canRunLocally () ? "allows" : "forbids" ,
400
386
dynamicStrategyRegistry .getDynamicSpawnActionContexts (spawn , DynamicMode .LOCAL ));
401
387
return RemoteBranch .runRemotely (spawn , actionExecutionContext , null , delayLocalExecution );
402
388
} else if (localCanExec && !remoteCanExec ) {
403
- // Extra logging to debug b/194373457
404
- logger .atInfo ().atMostEvery (1 , TimeUnit .SECONDS ).log (
405
- "Dynamic execution of %s can only be done locally: Remote execution policy %s it, "
406
- + "remote strategies are %s.%n" ,
407
- spawn .getResourceOwner ().prettyPrint (),
408
- executionPolicy .canRunRemotely () ? "allows" : "forbids" ,
409
- dynamicStrategyRegistry .getDynamicSpawnActionContexts (spawn , REMOTE ));
410
389
debugLog (
411
390
"Dynamic execution of %s can only be done locally: Remote execution policy %s it, "
412
391
+ "remote strategies are %s.%n" ,
413
- spawn . getResourceOwner (). prettyPrint ( ),
392
+ getSpawnReadableId ( spawn ),
414
393
executionPolicy .canRunRemotely () ? "allows" : "forbids" ,
415
394
dynamicStrategyRegistry .getDynamicSpawnActionContexts (spawn , REMOTE ));
416
395
return LocalBranch .runLocally (
@@ -503,7 +482,7 @@ static ImmutableList<SpawnResult> waitBranches(
503
482
Event .info (
504
483
String .format (
505
484
"Cancelling remote branch of %s after local exception %s" ,
506
- spawn . getResourceOwner (). prettyPrint ( ), e .getMessage ())));
485
+ getSpawnReadableId ( spawn ), e .getMessage ())));
507
486
}
508
487
remoteBranch .cancel ();
509
488
throw e ;
@@ -515,9 +494,7 @@ static ImmutableList<SpawnResult> waitBranches(
515
494
throw new AssertionError (
516
495
String .format (
517
496
"Neither branch of %s cancelled the other one. Local was %s and remote was %s." ,
518
- spawn .getResourceOwner ().getPrimaryOutput ().prettyPrint (),
519
- localBranch .branchState (),
520
- remoteBranch .branchState ()));
497
+ getSpawnReadableId (spawn ), localBranch .branchState (), remoteBranch .branchState ()));
521
498
} else if (localResult != null ) {
522
499
return localResult ;
523
500
} else if (remoteResult != null ) {
@@ -528,9 +505,7 @@ static ImmutableList<SpawnResult> waitBranches(
528
505
throw new AssertionError (
529
506
String .format (
530
507
"Neither branch of %s completed. Local was %s and remote was %s." ,
531
- spawn .getResourceOwner ().getPrimaryOutput ().prettyPrint (),
532
- localBranch .branchState (),
533
- remoteBranch .branchState ()));
508
+ getSpawnReadableId (spawn ), localBranch .branchState (), remoteBranch .branchState ()));
534
509
}
535
510
}
536
511
@@ -558,9 +533,8 @@ private static ImmutableList<SpawnResult> waitBranch(
558
533
.handle (
559
534
Event .info (
560
535
String .format (
561
- "Null results from %s branch of %s" ,
562
- mode ,
563
- branch .getSpawn ().getResourceOwner ().getPrimaryOutput ().prettyPrint ())));
536
+ "Null results from %s branch of %s" ,
537
+ mode , getSpawnReadableId (branch .getSpawn ()))));
564
538
}
565
539
return spawnResults ;
566
540
} catch (CancellationException e ) {
@@ -571,8 +545,7 @@ private static ImmutableList<SpawnResult> waitBranch(
571
545
Event .info (
572
546
String .format (
573
547
"CancellationException of %s branch of %s, returning null" ,
574
- mode ,
575
- branch .getSpawn ().getResourceOwner ().getPrimaryOutput ().prettyPrint ())));
548
+ mode , getSpawnReadableId (branch .getSpawn ()))));
576
549
}
577
550
return null ;
578
551
} catch (ExecutionException e ) {
@@ -591,8 +564,7 @@ private static ImmutableList<SpawnResult> waitBranch(
591
564
String .format (
592
565
"Caught InterruptedException from ExecException for %s branch of %s, which"
593
566
+ " may cause a crash." ,
594
- mode ,
595
- branch .getSpawn ().getResourceOwner ().getPrimaryOutput ().prettyPrint ())));
567
+ mode , getSpawnReadableId (branch .getSpawn ()))));
596
568
return null ;
597
569
} else {
598
570
// Even though we cannot enforce this in the future's signature (but we do in Branch#call),
@@ -661,9 +633,9 @@ static void stopBranch(
661
633
.handle (
662
634
Event .info (
663
635
String .format (
664
- "%s action finished %sly and was %s" ,
665
- cancellingBranch .getSpawn ().getMnemonic (),
636
+ "%s branch of %s finished and was %s" ,
666
637
strategyThatCancelled .get (),
638
+ getSpawnReadableId (cancellingBranch .getSpawn ()),
667
639
cancellingBranch .isCancelled () ? "cancelled" : "not cancelled" )));
668
640
}
669
641
@@ -712,4 +684,24 @@ public void usedContext(ActionContext.ActionContextRegistry actionContextRegistr
712
684
public String toString () {
713
685
return "dynamic" ;
714
686
}
687
+
688
+ private static String getSpawnReadableId (Spawn spawn ) {
689
+ ActionExecutionMetadata action = spawn .getResourceOwner ();
690
+ if (action == null ) {
691
+ return spawn .getMnemonic ();
692
+ }
693
+
694
+ Artifact primaryOutput = action .getPrimaryOutput ();
695
+ // In some cases, primary output could be null despite the method promises. And in that case, we
696
+ // can't use action.prettyPrint as it assumes a non-null primary output.
697
+ if (primaryOutput == null ) {
698
+ String label = "" ;
699
+ if (action .getOwner () != null && action .getOwner ().getLabel () != null ) {
700
+ label = " " + action .getOwner ().getLabel ().toString ();
701
+ }
702
+ return spawn .getMnemonic () + label ;
703
+ }
704
+
705
+ return primaryOutput .prettyPrint ();
706
+ }
715
707
}
0 commit comments