// Copyright 2014 Google Inc. 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.packages;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition;
import com.google.devtools.build.lib.packages.License.DistributionType;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.FuncallExpression;
import com.google.devtools.build.lib.syntax.GlobList;
import com.google.devtools.build.lib.syntax.Label;
import com.google.devtools.build.lib.syntax.Label.SyntaxException;
import com.google.devtools.build.lib.util.BinaryPredicate;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
/**
* An instance of a build rule in the build language. A rule has a name, a
* package to which it belongs, a class such as cc_library, and
* set of typed attributes. The set of attribute names and types is a property
* of the rule's class. The use of the term "class" here has nothing to do
* with Java classes. All rules are implemented by the same Java classes, Rule
* and RuleClass.
*
*
Here is a typical rule as it appears in a BUILD file:
*
*/
public final class Rule implements Target {
/** Dependency predicate that includes all dependencies */
public static final BinaryPredicate ALL_DEPS =
new BinaryPredicate() {
@Override
public boolean apply(Rule x, Attribute y) {
return true;
}
};
/** Dependency predicate that excludes host dependencies */
public static final BinaryPredicate NO_HOST_DEPS =
new BinaryPredicate() {
@Override
public boolean apply(Rule rule, Attribute attribute) {
// isHostConfiguration() is only defined for labels and label lists.
if (attribute.getType() != Type.LABEL && attribute.getType() != Type.LABEL_LIST) {
return true;
}
return attribute.getConfigurationTransition() != ConfigurationTransition.HOST;
}
};
/** Dependency predicate that excludes implicit dependencies */
public static final BinaryPredicate NO_IMPLICIT_DEPS =
new BinaryPredicate() {
@Override
public boolean apply(Rule rule, Attribute attribute) {
return rule.isAttributeValueExplicitlySpecified(attribute);
}
};
/**
* Dependency predicate that excludes those edges that are not present in the
* configured target graph.
*/
public static final BinaryPredicate NO_NODEP_ATTRIBUTES =
new BinaryPredicate() {
@Override
public boolean apply(Rule rule, Attribute attribute) {
return attribute.getType() != Type.NODEP_LABEL
&& attribute.getType() != Type.NODEP_LABEL_LIST;
}
};
/** Label predicate that allows every label. */
public static final Predicate