janakr | 6d185b8 | 2020-03-30 14:08:01 -0700 | [diff] [blame] | 1 | // Copyright 2014 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 | package com.google.devtools.build.lib.skyframe; |
| 15 | |
janakr | 1a4066a | 2020-04-13 13:24:27 -0700 | [diff] [blame] | 16 | import static com.google.common.base.Preconditions.checkArgument; |
janakr | 6d185b8 | 2020-03-30 14:08:01 -0700 | [diff] [blame] | 17 | |
janakr | 6d185b8 | 2020-03-30 14:08:01 -0700 | [diff] [blame] | 18 | import com.google.common.collect.Interner; |
| 19 | import com.google.devtools.build.lib.actions.ActionLookupValue; |
janakr | 1a4066a | 2020-04-13 13:24:27 -0700 | [diff] [blame] | 20 | import com.google.devtools.build.lib.actions.Artifact; |
janakr | 6d185b8 | 2020-03-30 14:08:01 -0700 | [diff] [blame] | 21 | import com.google.devtools.build.lib.concurrent.BlazeInterners; |
| 22 | import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; |
| 23 | import com.google.devtools.build.skyframe.AbstractSkyKey; |
| 24 | import com.google.devtools.build.skyframe.SkyFunctionName; |
janakr | 6d185b8 | 2020-03-30 14:08:01 -0700 | [diff] [blame] | 25 | import com.google.devtools.build.skyframe.SkyValue; |
| 26 | |
| 27 | /** |
| 28 | * A marker for an {@link ActionLookupValue} which is known to be transitively error-free from |
| 29 | * action conflict issues. |
| 30 | */ |
janakr | 1a4066a | 2020-04-13 13:24:27 -0700 | [diff] [blame] | 31 | public class ActionLookupConflictFindingValue implements SkyValue { |
janakr | 6d185b8 | 2020-03-30 14:08:01 -0700 | [diff] [blame] | 32 | @AutoCodec |
| 33 | static final ActionLookupConflictFindingValue INSTANCE = new ActionLookupConflictFindingValue(); |
| 34 | |
| 35 | private ActionLookupConflictFindingValue() {} |
| 36 | |
janakr | 6d185b8 | 2020-03-30 14:08:01 -0700 | [diff] [blame] | 37 | public static Key key(ActionLookupValue.ActionLookupKey lookupKey) { |
| 38 | return Key.create(lookupKey); |
| 39 | } |
| 40 | |
janakr | 1a4066a | 2020-04-13 13:24:27 -0700 | [diff] [blame] | 41 | public static Key key(Artifact artifact) { |
| 42 | checkArgument(artifact instanceof Artifact.DerivedArtifact, artifact); |
| 43 | return ActionLookupConflictFindingValue.key( |
| 44 | ((Artifact.DerivedArtifact) artifact).getGeneratingActionKey().getActionLookupKey()); |
| 45 | } |
| 46 | |
janakr | 6d185b8 | 2020-03-30 14:08:01 -0700 | [diff] [blame] | 47 | @AutoCodec.VisibleForSerialization |
| 48 | @AutoCodec |
| 49 | static class Key extends AbstractSkyKey<ActionLookupValue.ActionLookupKey> { |
| 50 | private static final Interner<Key> interner = BlazeInterners.newWeakInterner(); |
| 51 | |
| 52 | private Key(ActionLookupValue.ActionLookupKey arg) { |
| 53 | super(arg); |
| 54 | } |
| 55 | |
| 56 | @AutoCodec.VisibleForSerialization |
| 57 | @AutoCodec.Instantiator |
| 58 | static Key create(ActionLookupValue.ActionLookupKey arg) { |
| 59 | return interner.intern(new Key(arg)); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public SkyFunctionName functionName() { |
| 64 | return SkyFunctions.ACTION_LOOKUP_CONFLICT_FINDING; |
| 65 | } |
| 66 | } |
| 67 | } |