From 60554e40665c44e0f0423eb43183db3ea7c69514 Mon Sep 17 00:00:00 2001 From: janakr Date: Tue, 27 Mar 2018 10:26:36 -0700 Subject: Get rid of a few more #getConfiguration() calls. We're now passing a ConfiguredTargetAndData into TargetCompleteEvent, which seems reasonable. PiperOrigin-RevId: 190634162 --- .../build/lib/analysis/ConfiguredTarget.java | 2 +- .../build/lib/analysis/PrintActionVisitor.java | 3 +- .../build/lib/analysis/TargetCompleteEvent.java | 62 +++++++++++----------- 3 files changed, 33 insertions(+), 34 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/analysis') diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTarget.java b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTarget.java index c7c0866c32..2a0f751dd2 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTarget.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredTarget.java @@ -56,7 +56,7 @@ public interface ConfiguredTarget extends TransitiveInfoCollection, ClassObject, BuildConfiguration getConfiguration(); default String getConfigurationChecksum() { - return getConfiguration().checksum(); + return getConfiguration() == null ? null : getConfiguration().checksum(); } /** diff --git a/src/main/java/com/google/devtools/build/lib/analysis/PrintActionVisitor.java b/src/main/java/com/google/devtools/build/lib/analysis/PrintActionVisitor.java index abe62c1474..3f2f6aea37 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/PrintActionVisitor.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/PrintActionVisitor.java @@ -20,7 +20,6 @@ import com.google.devtools.build.lib.actions.ActionAnalysisMetadata; import com.google.devtools.build.lib.actions.ActionGraph; import com.google.devtools.build.lib.actions.ActionGraphVisitor; import com.google.devtools.build.lib.actions.ActionOwner; - import java.util.List; /** @@ -42,7 +41,7 @@ public final class PrintActionVisitor extends ActionGraphVisitor { this.target = target; this.actionMnemonicMatcher = actionMnemonicMatcher; actions = Lists.newArrayList(); - targetConfigurationChecksum = target.getConfiguration().checksum(); + targetConfigurationChecksum = target.getConfigurationChecksum(); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java b/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java index aeba06b462..97dde9c546 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java @@ -46,9 +46,9 @@ import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.packages.AttributeMap; import com.google.devtools.build.lib.packages.ConfiguredAttributeMapper; import com.google.devtools.build.lib.packages.Rule; -import com.google.devtools.build.lib.packages.Target; import com.google.devtools.build.lib.packages.TestSize; import com.google.devtools.build.lib.rules.AliasConfiguredTarget; +import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData; import com.google.devtools.build.lib.syntax.Type; import com.google.devtools.build.skyframe.SkyValue; import java.util.Collection; @@ -60,8 +60,7 @@ public final class TargetCompleteEvent BuildEventWithOrderConstraint, EventReportingArtifacts, BuildEventWithConfiguration { - private final ConfiguredTarget target; - private final Target actualTarget; + private final ConfiguredTargetAndData targetAndData; private final NestedSet rootCauses; private final ImmutableList postedAfter; private final Iterable outputs; @@ -69,20 +68,18 @@ public final class TargetCompleteEvent private final boolean isTest; private TargetCompleteEvent( - ConfiguredTarget target, - Target actualTarget, + ConfiguredTargetAndData targetAndData, NestedSet rootCauses, Iterable outputs, boolean isTest) { - this.target = target; - this.actualTarget = actualTarget; + this.targetAndData = targetAndData; this.rootCauses = (rootCauses == null) ? NestedSetBuilder.emptySet(Order.STABLE_ORDER) : rootCauses; ImmutableList.Builder postedAfterBuilder = ImmutableList.builder(); Label label = getTarget().getLabel(); - if (target instanceof AliasConfiguredTarget) { - label = ((AliasConfiguredTarget) target).getOriginalLabel(); + if (targetAndData.getConfiguredTarget() instanceof AliasConfiguredTarget) { + label = ((AliasConfiguredTarget) targetAndData.getConfiguredTarget()).getOriginalLabel(); } postedAfterBuilder.add(BuildEventId.targetConfigured(label)); for (Cause cause : getRootCauses()) { @@ -92,7 +89,7 @@ public final class TargetCompleteEvent this.outputs = outputs; this.isTest = isTest; InstrumentedFilesProvider instrumentedFilesProvider = - this.target.getProvider(InstrumentedFilesProvider.class); + this.targetAndData.getConfiguredTarget().getProvider(InstrumentedFilesProvider.class); if (instrumentedFilesProvider == null) { this.baselineCoverageArtifacts = null; } else { @@ -108,29 +105,28 @@ public final class TargetCompleteEvent /** Construct a successful target completion event. */ public static TargetCompleteEvent successfulBuild( - ConfiguredTarget ct, Target target, NestedSet outputs) { - return new TargetCompleteEvent(ct, target, null, outputs, false); + ConfiguredTargetAndData ct, NestedSet outputs) { + return new TargetCompleteEvent(ct, null, outputs, false); } /** Construct a successful target completion event for a target that will be tested. */ public static TargetCompleteEvent successfulBuildSchedulingTest( - ConfiguredTarget ct, Target target, NestedSet outputs) { - return new TargetCompleteEvent(ct, target, null, outputs, true); + ConfiguredTargetAndData ct, NestedSet outputs) { + return new TargetCompleteEvent(ct, null, outputs, true); } /** * Construct a target completion event for a failed target, with the given non-empty root causes. */ public static TargetCompleteEvent createFailed( - ConfiguredTarget ct, Target target, NestedSet rootCauses) { + ConfiguredTargetAndData ct, NestedSet rootCauses) { Preconditions.checkArgument(!Iterables.isEmpty(rootCauses)); - return new TargetCompleteEvent( - ct, target, rootCauses, ImmutableList.of(), false); + return new TargetCompleteEvent(ct, rootCauses, ImmutableList.of(), false); } /** Returns the target associated with the event. */ public ConfiguredTarget getTarget() { - return target; + return targetAndData.getConfiguredTarget(); } /** Determines whether the target has failed or succeeded. */ @@ -146,10 +142,10 @@ public final class TargetCompleteEvent @Override public BuildEventId getEventId() { Label label = getTarget().getLabel(); - if (target instanceof AliasConfiguredTarget) { - label = ((AliasConfiguredTarget) target).getOriginalLabel(); + if (targetAndData.getConfiguredTarget() instanceof AliasConfiguredTarget) { + label = ((AliasConfiguredTarget) targetAndData.getConfiguredTarget()).getOriginalLabel(); } - BuildConfiguration config = getTarget().getConfiguration(); + BuildConfiguration config = targetAndData.getConfiguration(); BuildEventId configId = config == null ? BuildEventId.nullConfigurationId() : config.getEventId(); return BuildEventId.targetCompleted(label, configId); @@ -165,15 +161,18 @@ public final class TargetCompleteEvent // For tests, announce all the test actions that will minimally happen (except for // interruption). If after the result of a test action another attempt is necessary, // it will be announced with the action that made the new attempt necessary. - Label label = target.getLabel(); - TestProvider.TestParams params = target.getProvider(TestProvider.class).getTestParams(); + Label label = targetAndData.getConfiguredTarget().getLabel(); + TestProvider.TestParams params = + targetAndData.getConfiguredTarget().getProvider(TestProvider.class).getTestParams(); for (int run = 0; run < Math.max(params.getRuns(), 1); run++) { for (int shard = 0; shard < Math.max(params.getShards(), 1); shard++) { childrenBuilder.add( - BuildEventId.testResult(label, run, shard, target.getConfiguration().getEventId())); + BuildEventId.testResult( + label, run, shard, targetAndData.getConfiguration().getEventId())); } } - childrenBuilder.add(BuildEventId.testSummary(label, target.getConfiguration().getEventId())); + childrenBuilder.add( + BuildEventId.testSummary(label, targetAndData.getConfiguration().getEventId())); } return childrenBuilder.build(); } @@ -205,14 +204,14 @@ public final class TargetCompleteEvent BuildEventStreamProtos.TargetComplete.newBuilder(); builder.setSuccess(!failed()); - builder.setTargetKind(actualTarget.getTargetKind()); + builder.setTargetKind(targetAndData.getTarget().getTargetKind()); builder.addAllTag(getTags()); builder.addAllOutputGroup(getOutputFilesByGroup(converters.artifactGroupNamer())); if (isTest) { builder.setTestSize( TargetConfiguredEvent.bepTestSize( - TestSize.getTestSize(actualTarget.getAssociatedRule()))); + TestSize.getTestSize(targetAndData.getTarget().getAssociatedRule()))); } // TODO(aehlig): remove direct reporting of artifacts as soon as clients no longer @@ -251,9 +250,9 @@ public final class TargetCompleteEvent @Override public Collection getConfigurations() { - BuildConfiguration configuration = target.getConfiguration(); + BuildConfiguration configuration = targetAndData.getConfiguration(); if (configuration != null) { - return ImmutableList.of(target.getConfiguration().toBuildEvent()); + return ImmutableList.of(targetAndData.getConfiguration().toBuildEvent()); } else { return ImmutableList.of(); } @@ -261,12 +260,13 @@ public final class TargetCompleteEvent private Iterable getTags() { // We are only interested in targets that are rules. - if (!(target instanceof RuleConfiguredTarget)) { + if (!(targetAndData.getConfiguredTarget() instanceof RuleConfiguredTarget)) { return ImmutableList.of(); } AttributeMap attributes = ConfiguredAttributeMapper.of( - (Rule) actualTarget, ((RuleConfiguredTarget) target).getConfigConditions()); + (Rule) targetAndData.getTarget(), + ((RuleConfiguredTarget) targetAndData.getConfiguredTarget()).getConfigConditions()); // Every rule (implicitly) has a "tags" attribute. return attributes.get("tags", Type.STRING_LIST); } -- cgit v1.2.3