janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 1 | // Copyright 2018 The Bazel Authors. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package com.google.devtools.build.lib.skyframe; |
| 16 | |
| 17 | import com.google.common.base.Preconditions; |
| 18 | import com.google.common.collect.ImmutableSet; |
Googler | 216ea78 | 2024-10-15 04:08:21 -0700 | [diff] [blame] | 19 | import com.google.devtools.build.lib.cmdline.IgnoredSubdirectories; |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 20 | import com.google.devtools.build.lib.cmdline.RepositoryName; |
| 21 | import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; |
Googler | 0036000 | 2024-01-23 12:54:16 -0800 | [diff] [blame] | 22 | import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 23 | import com.google.devtools.build.lib.vfs.PathFragment; |
| 24 | import com.google.devtools.build.lib.vfs.RootedPath; |
| 25 | import java.util.Objects; |
| 26 | |
| 27 | /** |
| 28 | * A RecursivePkgKey is a tuple of a {@link RootedPath}, {@code rootedPath}, defining the directory |
| 29 | * to recurse beneath in search of packages, and an {@link ImmutableSet} of {@link PathFragment}s, |
| 30 | * {@code excludedPaths}, relative to {@code rootedPath.getRoot}, defining the set of subdirectories |
| 31 | * strictly beneath {@code rootedPath} to skip. |
| 32 | * |
| 33 | * <p>Throws {@link IllegalArgumentException} if {@code excludedPaths} contains any paths that are |
| 34 | * equal to {@code rootedPath} or that are not beneath {@code rootedPath}. |
| 35 | */ |
| 36 | @ThreadSafe |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 37 | public class RecursivePkgKey { |
Googler | 0036000 | 2024-01-23 12:54:16 -0800 | [diff] [blame] | 38 | @VisibleForSerialization final RepositoryName repositoryName; |
| 39 | @VisibleForSerialization final RootedPath rootedPath; |
Googler | 216ea78 | 2024-10-15 04:08:21 -0700 | [diff] [blame] | 40 | @VisibleForSerialization final IgnoredSubdirectories excludedPaths; |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 41 | |
| 42 | public RecursivePkgKey( |
Googler | 216ea78 | 2024-10-15 04:08:21 -0700 | [diff] [blame] | 43 | RepositoryName repositoryName, RootedPath rootedPath, IgnoredSubdirectories excludedPaths) { |
| 44 | Preconditions.checkArgument(excludedPaths.allPathsAreUnder(rootedPath.getRootRelativePath())); |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 45 | this.repositoryName = repositoryName; |
| 46 | this.rootedPath = Preconditions.checkNotNull(rootedPath); |
| 47 | this.excludedPaths = Preconditions.checkNotNull(excludedPaths); |
| 48 | } |
| 49 | |
jcater | 331c76f | 2020-04-01 07:27:52 -0700 | [diff] [blame] | 50 | public RepositoryName getRepositoryName() { |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 51 | return repositoryName; |
| 52 | } |
| 53 | |
| 54 | public RootedPath getRootedPath() { |
| 55 | return rootedPath; |
| 56 | } |
| 57 | |
Googler | 216ea78 | 2024-10-15 04:08:21 -0700 | [diff] [blame] | 58 | public IgnoredSubdirectories getExcludedPaths() { |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 59 | return excludedPaths; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public String toString() { |
| 64 | return "rootedPath=" + rootedPath + ", excludedPaths=<omitted>"; |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public boolean equals(Object o) { |
| 69 | if (this == o) { |
| 70 | return true; |
| 71 | } |
Googler | 6f48f1c | 2024-04-16 14:29:09 -0700 | [diff] [blame] | 72 | if (!(o instanceof RecursivePkgKey that)) { |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 73 | return false; |
| 74 | } |
| 75 | |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 76 | return excludedPaths.equals(that.excludedPaths) |
| 77 | && rootedPath.equals(that.rootedPath) |
| 78 | && repositoryName.equals(that.repositoryName); |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public int hashCode() { |
| 83 | return Objects.hash(rootedPath, excludedPaths, repositoryName); |
| 84 | } |
| 85 | } |