13
13
// limitations under the License.
14
14
package com .google .devtools .build .lib .analysis ;
15
15
16
+ import static com .google .common .base .Preconditions .checkNotNull ;
17
+ import static com .google .common .base .Preconditions .checkState ;
16
18
import static com .google .common .collect .ImmutableList .toImmutableList ;
17
19
18
20
import com .google .common .annotations .VisibleForTesting ;
19
- import com .google .common .base .Preconditions ;
20
21
import com .google .common .collect .ImmutableList ;
21
22
import com .google .common .collect .ImmutableMap ;
22
23
import com .google .common .collect .ImmutableSet ;
63
64
import com .google .devtools .build .lib .packages .NativeAspectClass ;
64
65
import com .google .devtools .build .lib .packages .NoSuchPackageException ;
65
66
import com .google .devtools .build .lib .packages .NoSuchTargetException ;
67
+ import com .google .devtools .build .lib .packages .Package ;
66
68
import com .google .devtools .build .lib .packages .Rule ;
67
69
import com .google .devtools .build .lib .packages .StarlarkAspectClass ;
68
70
import com .google .devtools .build .lib .packages .Target ;
@@ -166,7 +168,7 @@ public BuildView(
166
168
this .directories = directories ;
167
169
this .coverageReportActionFactory = coverageReportActionFactory ;
168
170
this .ruleClassProvider = ruleClassProvider ;
169
- this .skyframeExecutor = Preconditions . checkNotNull (skyframeExecutor );
171
+ this .skyframeExecutor = checkNotNull (skyframeExecutor );
170
172
this .skyframeBuildView = skyframeExecutor .getSkyframeBuildView ();
171
173
}
172
174
@@ -232,13 +234,7 @@ public AnalysisResult update(
232
234
skyframeBuildView .resetProgressReceiver ();
233
235
skyframeExecutor .setBaselineConfiguration (targetOptions );
234
236
235
- ImmutableMap .Builder <Label , Target > labelToTargetsMapBuilder =
236
- ImmutableMap .builderWithExpectedSize (loadingResult .getTargetLabels ().size ());
237
- loadingResult
238
- .getTargets (eventHandler , skyframeExecutor .getPackageManager ())
239
- .forEach (target -> labelToTargetsMapBuilder .put (target .getLabel (), target ));
240
- ImmutableMap <Label , Target > labelToTargetMap = labelToTargetsMapBuilder .buildOrThrow ();
241
-
237
+ ImmutableMap <Label , Target > labelToTargetMap = constructLabelToTargetMap (loadingResult );
242
238
eventBus .post (new AnalysisPhaseStartedEvent (labelToTargetMap .values ()));
243
239
244
240
// Prepare the analysis phase
@@ -291,7 +287,7 @@ public AnalysisResult update(
291
287
(RuleContextConstraintSemantics ) ruleClassProvider .getConstraintSemantics ());
292
288
// We wait until now to setup for execution, in case the artifact factory was reset
293
289
// due to a config change.
294
- Preconditions . checkNotNull (executionSetupCallback ).prepareForExecution ();
290
+ checkNotNull (executionSetupCallback ).prepareForExecution ();
295
291
skyframeAnalysisResult =
296
292
skyframeBuildView .analyzeAndExecuteTargets (
297
293
eventHandler ,
@@ -303,8 +299,8 @@ public AnalysisResult update(
303
299
explicitTargetPatterns ,
304
300
eventBus ,
305
301
bugReporter ,
306
- Preconditions . checkNotNull (resourceManager ), // non-null for skymeld.
307
- Preconditions . checkNotNull (buildResultListener ), // non-null for skymeld.
302
+ checkNotNull (resourceManager ), // non-null for skymeld.
303
+ checkNotNull (buildResultListener ), // non-null for skymeld.
308
304
(configuredTargets , allTargetsToTest ) ->
309
305
memoizedGetCoverageArtifactsHelper (
310
306
configuredTargets , allTargetsToTest , eventHandler , eventBus , loadingResult ),
@@ -414,6 +410,20 @@ public AnalysisResult update(
414
410
return result ;
415
411
}
416
412
413
+ private ImmutableMap <Label , Target > constructLabelToTargetMap (
414
+ TargetPatternPhaseValue loadingResult ) throws InterruptedException {
415
+ ImmutableSet <Label > labels = loadingResult .getTargetLabels ();
416
+ ImmutableMap .Builder <Label , Target > builder =
417
+ ImmutableMap .builderWithExpectedSize (labels .size ());
418
+ for (Label label : labels ) {
419
+ Package pkg =
420
+ checkNotNull (skyframeExecutor .getExistingPackage (label .getPackageIdentifier ()), label );
421
+ Target target = checkNotNull (pkg .getTargets ().get (label .getName ()), label );
422
+ builder .put (label , target );
423
+ }
424
+ return builder .buildOrThrow ();
425
+ }
426
+
417
427
private ImmutableList <TopLevelAspectsKey > createTopLevelAspectKeys (
418
428
List <String > aspects ,
419
429
ImmutableMap <String , String > aspectsParameters ,
@@ -533,7 +543,7 @@ private AnalysisResult createResult(
533
543
// build-info and build-changelist.
534
544
ImmutableList <Artifact > buildInfoArtifacts =
535
545
skyframeExecutor .getWorkspaceStatusArtifacts (eventHandler );
536
- Preconditions . checkState (buildInfoArtifacts .size () == 2 , buildInfoArtifacts );
546
+ checkState (buildInfoArtifacts .size () == 2 , buildInfoArtifacts );
537
547
538
548
// Extra actions
539
549
addExtraActionsIfRequested (
0 commit comments