Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 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 | package com.google.devtools.build.lib.skyframe; |
| 15 | |
Mark Schaller | f6e32d6 | 2015-05-19 20:27:43 +0000 | [diff] [blame] | 16 | import com.google.common.collect.ImmutableSet; |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 17 | import com.google.common.collect.Interner; |
Kristina Chodorow | ec5c07a | 2016-01-25 17:12:29 +0000 | [diff] [blame] | 18 | import com.google.devtools.build.lib.cmdline.RepositoryName; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 19 | import com.google.devtools.build.lib.collect.nestedset.NestedSet; |
Janak Ramakrishnan | f7ff616 | 2015-06-02 20:20:31 +0000 | [diff] [blame] | 20 | import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; |
| 21 | import com.google.devtools.build.lib.collect.nestedset.Order; |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 22 | import com.google.devtools.build.lib.concurrent.BlazeInterners; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 23 | import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; |
| 24 | import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; |
shahan | bbbf3dc | 2018-02-23 15:41:52 -0800 | [diff] [blame] | 25 | import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; |
Googler | 41797b6 | 2021-11-19 12:07:05 -0800 | [diff] [blame] | 26 | import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant; |
Mark Schaller | f6e32d6 | 2015-05-19 20:27:43 +0000 | [diff] [blame] | 27 | import com.google.devtools.build.lib.vfs.PathFragment; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 28 | import com.google.devtools.build.lib.vfs.RootedPath; |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 29 | import com.google.devtools.build.skyframe.SkyFunctionName; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 30 | import com.google.devtools.build.skyframe.SkyValue; |
Mark Schaller | f6e32d6 | 2015-05-19 20:27:43 +0000 | [diff] [blame] | 31 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 32 | /** |
| 33 | * This value represents the result of looking up all the packages under a given package path root, |
| 34 | * starting at a given directory. |
| 35 | */ |
| 36 | @Immutable |
| 37 | @ThreadSafe |
Michajlo Matijkiw | d8b4be1 | 2015-09-15 23:04:17 +0000 | [diff] [blame] | 38 | public class RecursivePkgValue implements SkyValue { |
Googler | 41797b6 | 2021-11-19 12:07:05 -0800 | [diff] [blame] | 39 | @SerializationConstant |
Janak Ramakrishnan | f7ff616 | 2015-06-02 20:20:31 +0000 | [diff] [blame] | 40 | static final RecursivePkgValue EMPTY = |
adgar | 8c3b3fb | 2019-06-03 13:35:28 -0700 | [diff] [blame] | 41 | new RecursivePkgValue(NestedSetBuilder.<String>emptySet(Order.STABLE_ORDER), false); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 42 | |
| 43 | private final NestedSet<String> packages; |
adgar | 8c3b3fb | 2019-06-03 13:35:28 -0700 | [diff] [blame] | 44 | private final boolean hasErrors; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 45 | |
adgar | 8c3b3fb | 2019-06-03 13:35:28 -0700 | [diff] [blame] | 46 | private RecursivePkgValue(NestedSet<String> packages, boolean hasErrors) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 47 | this.packages = packages; |
adgar | 8c3b3fb | 2019-06-03 13:35:28 -0700 | [diff] [blame] | 48 | this.hasErrors = hasErrors; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 49 | } |
| 50 | |
adgar | 8c3b3fb | 2019-06-03 13:35:28 -0700 | [diff] [blame] | 51 | static RecursivePkgValue create(NestedSetBuilder<String> packages, boolean hasErrors) { |
| 52 | if (packages.isEmpty() && !hasErrors) { |
Janak Ramakrishnan | f7ff616 | 2015-06-02 20:20:31 +0000 | [diff] [blame] | 53 | return EMPTY; |
| 54 | } |
adgar | 8c3b3fb | 2019-06-03 13:35:28 -0700 | [diff] [blame] | 55 | return new RecursivePkgValue(packages.build(), hasErrors); |
Janak Ramakrishnan | f7ff616 | 2015-06-02 20:20:31 +0000 | [diff] [blame] | 56 | } |
| 57 | |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 58 | /** Create a transitive package lookup request. */ |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 59 | @ThreadSafe |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 60 | public static Key key( |
| 61 | RepositoryName repositoryName, |
| 62 | RootedPath rootedPath, |
Lukacs Berki | d72db8d | 2015-09-22 07:40:24 +0000 | [diff] [blame] | 63 | ImmutableSet<PathFragment> excludedPaths) { |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 64 | return Key.create(repositoryName, rootedPath, excludedPaths); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | public NestedSet<String> getPackages() { |
| 68 | return packages; |
| 69 | } |
Mark Schaller | f6e32d6 | 2015-05-19 20:27:43 +0000 | [diff] [blame] | 70 | |
adgar | 8c3b3fb | 2019-06-03 13:35:28 -0700 | [diff] [blame] | 71 | public boolean hasErrors() { |
| 72 | return hasErrors; |
| 73 | } |
| 74 | |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 75 | @AutoCodec.VisibleForSerialization |
shahan | bbbf3dc | 2018-02-23 15:41:52 -0800 | [diff] [blame] | 76 | @AutoCodec |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 77 | static class Key extends RecursivePkgSkyKey { |
| 78 | private static final Interner<Key> interner = BlazeInterners.newWeakInterner(); |
Mark Schaller | f6e32d6 | 2015-05-19 20:27:43 +0000 | [diff] [blame] | 79 | |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 80 | private Key( |
shahan | bbbf3dc | 2018-02-23 15:41:52 -0800 | [diff] [blame] | 81 | RepositoryName repositoryName, |
| 82 | RootedPath rootedPath, |
Lukacs Berki | d72db8d | 2015-09-22 07:40:24 +0000 | [diff] [blame] | 83 | ImmutableSet<PathFragment> excludedPaths) { |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 84 | super(repositoryName, rootedPath, excludedPaths); |
Mark Schaller | f6e32d6 | 2015-05-19 20:27:43 +0000 | [diff] [blame] | 85 | } |
| 86 | |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 87 | @AutoCodec.VisibleForSerialization |
| 88 | @AutoCodec.Instantiator |
| 89 | static Key create( |
| 90 | RepositoryName repositoryName, |
| 91 | RootedPath rootedPath, |
| 92 | ImmutableSet<PathFragment> excludedPaths) { |
| 93 | return interner.intern(new Key(repositoryName, rootedPath, excludedPaths)); |
Mark Schaller | f6e32d6 | 2015-05-19 20:27:43 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | @Override |
janakr | 5fb2a48 | 2018-03-02 17:48:57 -0800 | [diff] [blame] | 97 | public SkyFunctionName functionName() { |
| 98 | return SkyFunctions.RECURSIVE_PKG; |
Mark Schaller | f6e32d6 | 2015-05-19 20:27:43 +0000 | [diff] [blame] | 99 | } |
| 100 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 101 | } |