59
59
import com .google .devtools .build .lib .events .StoredEventHandler ;
60
60
import com .google .devtools .build .lib .packages .Aspect ;
61
61
import com .google .devtools .build .lib .packages .BuildType ;
62
+ import com .google .devtools .build .lib .packages .ConfiguredAttributeMapper .ValidationException ;
62
63
import com .google .devtools .build .lib .packages .ExecGroup ;
63
64
import com .google .devtools .build .lib .packages .NoSuchTargetException ;
64
65
import com .google .devtools .build .lib .packages .NonconfigurableAttributeMapper ;
92
93
import java .util .Set ;
93
94
import java .util .function .Predicate ;
94
95
import javax .annotation .Nullable ;
96
+ import net .starlark .java .syntax .Location ;
95
97
96
98
/**
97
99
* Helper logic for {@link ConfiguredTargetFunction}: performs the analysis phase through
@@ -124,13 +126,16 @@ static class State implements SkyKeyComputeState, IncompatibleTargetProducer.Res
124
126
* <p>Non-null only while the computation is in-flight.
125
127
*/
126
128
@ Nullable private Driver incompatibleTargetProducer ;
129
+
127
130
/**
128
131
* If a value is present, it means the target was directly incompatible.
129
132
*
130
133
* <p>Non-null after the {@link #incompatibleTargetProducer} completes.
131
134
*/
132
135
private Optional <RuleConfiguredTargetValue > incompatibleTarget ;
133
136
137
+ private ValidationException validationException ;
138
+
134
139
/** Null if not yet computed or if {@link #resolveConfigurationsResult} is non-null. */
135
140
@ Nullable private OrderedSetMultimap <DependencyKind , DependencyKey > dependentNodeMapResult ;
136
141
@@ -171,6 +176,11 @@ static class State implements SkyKeyComputeState, IncompatibleTargetProducer.Res
171
176
public void accept (Optional <RuleConfiguredTargetValue > incompatibleTarget ) {
172
177
this .incompatibleTarget = incompatibleTarget ;
173
178
}
179
+
180
+ @ Override
181
+ public void acceptValidationException (ValidationException e ) {
182
+ this .validationException = e ;
183
+ }
174
184
}
175
185
176
186
/**
@@ -475,14 +485,15 @@ private static boolean checkForIncompatibleTarget(
475
485
@ Nullable ConfigConditions configConditions ,
476
486
@ Nullable PlatformInfo targetPlatformInfo ,
477
487
@ Nullable NestedSetBuilder <Package > transitivePackages )
478
- throws InterruptedException , IncompatibleTargetException {
488
+ throws InterruptedException , IncompatibleTargetException , DependencyEvaluationException {
479
489
if (state .incompatibleTarget == null ) {
490
+ BuildConfigurationValue configuration = targetAndConfiguration .getConfiguration ();
480
491
if (state .incompatibleTargetProducer == null ) {
481
492
state .incompatibleTargetProducer =
482
493
new Driver (
483
494
new IncompatibleTargetProducer (
484
495
targetAndConfiguration .getTarget (),
485
- targetAndConfiguration . getConfiguration () ,
496
+ configuration ,
486
497
configConditions ,
487
498
targetPlatformInfo ,
488
499
transitivePackages ,
@@ -492,7 +503,26 @@ private static boolean checkForIncompatibleTarget(
492
503
return false ;
493
504
}
494
505
state .incompatibleTargetProducer = null ;
495
- if (state .incompatibleTarget .isPresent ()) {
506
+ if (state .validationException != null ) {
507
+ Label label = targetAndConfiguration .getLabel ();
508
+ Location location = targetAndConfiguration .getTarget ().getLocation ();
509
+ env .getListener ()
510
+ .post (
511
+ new AnalysisRootCauseEvent (
512
+ configuration , label , state .validationException .getMessage ()));
513
+ throw new DependencyEvaluationException (
514
+ new ConfiguredValueCreationException (
515
+ location ,
516
+ state .validationException .getMessage (),
517
+ label ,
518
+ configuration .getEventId (),
519
+ null ,
520
+ null ),
521
+ // These errors occur within DependencyResolver, which is attached to the current
522
+ // target. i.e. no dependent ConfiguredTargetFunction call happens to report its own
523
+ // error.
524
+ /* depReportedOwnError= */ false );
525
+ } else if (state .incompatibleTarget .isPresent ()) {
496
526
throw new IncompatibleTargetException (state .incompatibleTarget .get ());
497
527
}
498
528
}
0 commit comments