blob: 32e24ba48d2943f61d7aa997fc43027a17b18214 [file] [log] [blame]
janakr5fb2a482018-03-02 17:48:57 -08001// 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
15package com.google.devtools.build.lib.skyframe;
16
17import com.google.common.base.Preconditions;
18import com.google.common.collect.ImmutableSet;
Googler216ea782024-10-15 04:08:21 -070019import com.google.devtools.build.lib.cmdline.IgnoredSubdirectories;
janakr5fb2a482018-03-02 17:48:57 -080020import com.google.devtools.build.lib.cmdline.RepositoryName;
21import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
Googler00360002024-01-23 12:54:16 -080022import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization;
janakr5fb2a482018-03-02 17:48:57 -080023import com.google.devtools.build.lib.vfs.PathFragment;
24import com.google.devtools.build.lib.vfs.RootedPath;
25import 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
janakr5fb2a482018-03-02 17:48:57 -080037public class RecursivePkgKey {
Googler00360002024-01-23 12:54:16 -080038 @VisibleForSerialization final RepositoryName repositoryName;
39 @VisibleForSerialization final RootedPath rootedPath;
Googler216ea782024-10-15 04:08:21 -070040 @VisibleForSerialization final IgnoredSubdirectories excludedPaths;
janakr5fb2a482018-03-02 17:48:57 -080041
42 public RecursivePkgKey(
Googler216ea782024-10-15 04:08:21 -070043 RepositoryName repositoryName, RootedPath rootedPath, IgnoredSubdirectories excludedPaths) {
44 Preconditions.checkArgument(excludedPaths.allPathsAreUnder(rootedPath.getRootRelativePath()));
janakr5fb2a482018-03-02 17:48:57 -080045 this.repositoryName = repositoryName;
46 this.rootedPath = Preconditions.checkNotNull(rootedPath);
47 this.excludedPaths = Preconditions.checkNotNull(excludedPaths);
48 }
49
jcater331c76f2020-04-01 07:27:52 -070050 public RepositoryName getRepositoryName() {
janakr5fb2a482018-03-02 17:48:57 -080051 return repositoryName;
52 }
53
54 public RootedPath getRootedPath() {
55 return rootedPath;
56 }
57
Googler216ea782024-10-15 04:08:21 -070058 public IgnoredSubdirectories getExcludedPaths() {
janakr5fb2a482018-03-02 17:48:57 -080059 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 }
Googler6f48f1c2024-04-16 14:29:09 -070072 if (!(o instanceof RecursivePkgKey that)) {
janakr5fb2a482018-03-02 17:48:57 -080073 return false;
74 }
75
janakr5fb2a482018-03-02 17:48:57 -080076 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}