// Copyright 2014 The Bazel Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.google.devtools.build.lib.pkgcache; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.buildeventstream.BuildEventContext; import com.google.devtools.build.lib.buildeventstream.BuildEventId; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos; import com.google.devtools.build.lib.buildeventstream.BuildEventWithOrderConstraint; import com.google.devtools.build.lib.buildeventstream.GenericBuildEvent; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.Target; import com.google.devtools.build.lib.packages.TargetUtils; import java.util.Collection; import java.util.List; import javax.annotation.Nullable; /** This event is fired just after target pattern evaluation is completed. */ public class TargetParsingCompleteEvent implements BuildEventWithOrderConstraint { /** A target-like object that is lighter than a target but has all data needed by callers. */ public static class ThinTarget { private final Label label; @Nullable private final String ruleClass; private final String targetKind; private ThinTarget(Target target) { this.label = target.getLabel(); this.targetKind = target.getTargetKind(); this.ruleClass = (target instanceof Rule) ? ((Rule) target).getRuleClass() : null; } public boolean isRule() { return ruleClass != null; } public String getTargetKind() { return targetKind; } public Label getLabel() { return label; } /** Gets the rule class of this target. Caller must already know it {@link #isRule}. */ public String getRuleClass() { return Preconditions.checkNotNull(ruleClass, label); } public boolean isTestSuiteRule() { return isRule() && TargetUtils.isTestSuiteRuleName(getRuleClass()); } public boolean isNotATestOrTestSuite() { return !isRule() || (!isTestSuiteRule() && !TargetUtils.isTestRuleName(getRuleClass())); } } private final ImmutableList originalTargetPattern; private final ImmutableList failedTargetPatterns; private final ImmutableSet targets; private final ImmutableSet filteredTargets; private final ImmutableSet testFilteredTargets; private final ImmutableSet expandedTargets; /** * Construct the event. * * @param targets The targets that were parsed from the command-line pattern. */ public TargetParsingCompleteEvent( Collection targets, Collection filteredTargets, Collection testFilteredTargets, List originalTargetPattern, Collection expandedTargets, List failedTargetPatterns) { this.targets = asThinTargets(targets); this.filteredTargets = asThinTargets(filteredTargets); this.testFilteredTargets = asThinTargets(testFilteredTargets); this.originalTargetPattern = ImmutableList.copyOf(originalTargetPattern); this.expandedTargets = asThinTargets(expandedTargets); this.failedTargetPatterns = ImmutableList.copyOf(failedTargetPatterns); } @VisibleForTesting public TargetParsingCompleteEvent(Collection targets) { this( targets, ImmutableSet.of(), ImmutableSet.of(), ImmutableList.of(), targets, ImmutableList.of()); } public ImmutableList getOriginalTargetPattern() { return originalTargetPattern; } public ImmutableList getFailedTargetPatterns() { return failedTargetPatterns; } /** @return the parsed targets, which will subsequently be loaded */ public ImmutableSet getTargets() { return targets; } public Iterable