// 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.packages; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.events.Location; import com.google.devtools.build.lib.syntax.Type; import java.util.Collection; import javax.annotation.Nullable; /** * The interface for accessing a {@link Rule}'s attributes. * *
Since what an attribute lookup should return can be ambiguous (e.g. for configurable * attributes, should we return a configuration-resolved value or the original, unresolved * selection expression?), different implementations can apply different policies for how to * fulfill these methods. Calling code can then use the appropriate implementation for whatever * its particular needs are. */ public interface AttributeMap { /** * Returns the name of the rule; this is equivalent to {@code getLabel().getName()}. */ String getName(); /** * Returns the label of the rule. */ Label getLabel(); /** * Returns the name of the rule class. */ String getRuleClassName(); /** * Returns true if an attribute with the given name exists. */ boolean has(String attrName); /** * Returns true if an attribute with the given name exists with the given type. * *
Don't use this version unless you really care about the type.
*/
If the rule doesn't have this attribute with the specified type, throws an
* {@link IllegalArgumentException}.
*/
@Nullable
It is probably a good idea to avoid this method in default value and implicit outputs
* computation, because it is confusing that setting an attribute to an empty list (for example)
* is different from not setting it at all.
*/
boolean isAttributeValueExplicitlySpecified(String attributeName);
/** Returns the {@link Location} at which the attribute was defined. */
Location getAttributeLocation(String attrName);
/**
* Returns a {@link Collection} with a {@link DepEdge} for every attribute that contains labels in
* its value (either by *being* a label or being a collection that includes labels).
*/
Collection The {@link Label} is the target node of the {@code (Rule, Label)} edge. The source node
* should already be known. The {@link Attribute} is the attribute giving the edge.
*/
@AutoValue
abstract class DepEdge {
public abstract Label getLabel();
public abstract Attribute getAttribute();
static DepEdge create(Label label, Attribute attribute) {
return new AutoValue_AttributeMap_DepEdge(label, attribute);
}
}
// TODO(bazel-team): These methods are here to support computed defaults that inherit
// package-level default values. Instead, we should auto-inherit and remove the computed
// defaults. If we really need to give access to package-level defaults, we should come up with
// a more generic interface.
String getPackageDefaultHdrsCheck();
Boolean getPackageDefaultTestOnly();
String getPackageDefaultDeprecation();
ImmutableList