// Copyright 2015 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.skyframe; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.cmdline.TargetParsingException; import com.google.devtools.build.lib.cmdline.TargetPattern.Type; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; import com.google.devtools.build.lib.pkgcache.FilteringPolicies; import com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternKey; import com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternSkyKeyOrException; import com.google.devtools.build.skyframe.LegacySkyKey; import com.google.devtools.build.skyframe.SkyKey; import com.google.devtools.build.skyframe.SkyValue; import java.util.List; /** * The value returned by {@link PrepareDepsOfPatternFunction}. Because that function is * invoked only for its side effect (i.e. ensuring the graph contains targets matching the * pattern and its transitive dependencies), this value carries no information. * *
Because the returned value is always equal to objects that share its type, this value and the * {@link PrepareDepsOfPatternFunction} which computes it are incompatible with change pruning. It * should only be requested by consumers who do not require reevaluation when * {@link PrepareDepsOfPatternFunction} is reevaluated. Safe consumers include, e.g., top-level * consumers, and other functions which invoke {@link PrepareDepsOfPatternFunction} solely for its * side-effects. */ public class PrepareDepsOfPatternValue implements SkyValue { // Note that this value does not guarantee singleton-like reference equality because we use Java // deserialization. Java deserialization can create other instances. public static final PrepareDepsOfPatternValue INSTANCE = new PrepareDepsOfPatternValue(); private PrepareDepsOfPatternValue() { } @Override public boolean equals(Object o) { return o instanceof PrepareDepsOfPatternValue; } @Override public int hashCode() { return 42; } /** * Returns a {@link PrepareDepsOfPatternSkyKeysAndExceptions}, containing * {@link PrepareDepsOfPatternSkyKeyValue} and {@link PrepareDepsOfPatternSkyKeyException} * instances that have {@link TargetPatternKey} arguments. Negative target patterns of type other * than {@link Type#TARGETS_BELOW_DIRECTORY} are not permitted. If a provided pattern fails to * parse or is negative but not a {@link Type#TARGETS_BELOW_DIRECTORY}, there will be a * corresponding {@link PrepareDepsOfPatternSkyKeyException} in the iterable returned by * {@link PrepareDepsOfPatternSkyKeysAndExceptions#getExceptions} whose * {@link PrepareDepsOfPatternSkyKeyException#getException} and * {@link PrepareDepsOfPatternSkyKeyException#getOriginalPattern} methods return the * {@link TargetParsingException} and original pattern, respectively. * *
There may be fewer returned elements in
* {@link PrepareDepsOfPatternSkyKeysAndExceptions#getValues} than patterns provided as input.
* This function will combine negative {@link Type#TARGETS_BELOW_DIRECTORY} patterns with
* preceding patterns to return an iterable of SkyKeys that avoids loading excluded directories
* during evaluation.
*
* @param patterns The list of patterns, e.g. [//foo/..., -//foo/biz/...]. If a pattern's first
* character is "-", it is treated as a negative pattern.
* @param offset The offset to apply to relative target patterns.
*/
@ThreadSafe
public static PrepareDepsOfPatternSkyKeysAndExceptions keys(
List