Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 1 | // Copyright 2016 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 | badc2c5 | 2021-12-20 10:37:01 -0800 | [diff] [blame] | 16 | import com.google.common.annotations.VisibleForTesting; |
janakr | cb314a2 | 2018-02-15 10:33:53 -0800 | [diff] [blame] | 17 | import com.google.common.base.MoreObjects; |
Googler | 0a43c70 | 2023-05-30 13:11:37 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
Googler | 0a43c70 | 2023-05-30 13:11:37 -0700 | [diff] [blame] | 19 | import com.google.devtools.build.lib.actions.ActionAnalysisMetadata; |
jhorvitz | 3daedc3 | 2020-07-22 18:33:55 -0700 | [diff] [blame] | 20 | import com.google.devtools.build.lib.actions.ActionLookupKey; |
cparsons | e2d200f | 2018-03-06 16:15:11 -0800 | [diff] [blame] | 21 | import com.google.devtools.build.lib.actions.BasicActionLookupValue; |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 22 | import com.google.devtools.build.lib.cmdline.Label; |
Googler | 9757df9 | 2023-10-02 08:03:35 -0700 | [diff] [blame] | 23 | import com.google.devtools.build.lib.skyframe.config.BuildConfigurationKey; |
Googler | 68c0716 | 2024-01-08 13:52:47 -0800 | [diff] [blame] | 24 | import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization; |
janakr | b2a396b | 2018-02-15 12:42:38 -0800 | [diff] [blame] | 25 | import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 26 | import com.google.devtools.build.skyframe.SkyFunctionName; |
Googler | 70f7c80 | 2023-11-06 07:44:15 -0800 | [diff] [blame] | 27 | import com.google.devtools.build.skyframe.SkyKey; |
Googler | 68c0716 | 2024-01-08 13:52:47 -0800 | [diff] [blame] | 28 | import com.google.devtools.build.skyframe.SkyKey.SkyKeyInterner; |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 29 | |
janakr | badc2c5 | 2021-12-20 10:37:01 -0800 | [diff] [blame] | 30 | /** Value that stores expanded actions from ActionTemplate. */ |
cparsons | e2d200f | 2018-03-06 16:15:11 -0800 | [diff] [blame] | 31 | public final class ActionTemplateExpansionValue extends BasicActionLookupValue { |
Googler | 0a43c70 | 2023-05-30 13:11:37 -0700 | [diff] [blame] | 32 | |
| 33 | ActionTemplateExpansionValue(ImmutableList<ActionAnalysisMetadata> generatingActions) { |
Googler | ce6ad29 | 2019-12-20 10:29:21 -0800 | [diff] [blame] | 34 | super(generatingActions); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Googler | 3c7d571 | 2023-07-14 06:33:31 -0700 | [diff] [blame] | 37 | public static ActionTemplateExpansionKey key(ActionLookupKey actionLookupKey, int actionIndex) { |
janakr | b2a396b | 2018-02-15 12:42:38 -0800 | [diff] [blame] | 38 | return ActionTemplateExpansionKey.of(actionLookupKey, actionIndex); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 39 | } |
| 40 | |
mschaller | 904dfe4 | 2019-01-07 18:25:02 -0800 | [diff] [blame] | 41 | /** Key for {@link ActionTemplateExpansionValue} nodes. */ |
janakr | b2a396b | 2018-02-15 12:42:38 -0800 | [diff] [blame] | 42 | @AutoCodec |
Googler | c0e7d04 | 2023-05-03 10:23:04 -0700 | [diff] [blame] | 43 | public static final class ActionTemplateExpansionKey implements ActionLookupKey { |
Googler | 70f7c80 | 2023-11-06 07:44:15 -0800 | [diff] [blame] | 44 | private static final SkyKeyInterner<ActionTemplateExpansionKey> interner = SkyKey.newInterner(); |
janakr | b2a396b | 2018-02-15 12:42:38 -0800 | [diff] [blame] | 45 | |
Googler | 3c7d571 | 2023-07-14 06:33:31 -0700 | [diff] [blame] | 46 | private final ActionLookupKey actionLookupKey; |
janakr | cb314a2 | 2018-02-15 10:33:53 -0800 | [diff] [blame] | 47 | private final int actionIndex; |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 48 | |
Googler | 3c7d571 | 2023-07-14 06:33:31 -0700 | [diff] [blame] | 49 | private ActionTemplateExpansionKey(ActionLookupKey actionLookupKey, int actionIndex) { |
janakr | cb314a2 | 2018-02-15 10:33:53 -0800 | [diff] [blame] | 50 | this.actionLookupKey = actionLookupKey; |
| 51 | this.actionIndex = actionIndex; |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 52 | } |
| 53 | |
janakr | badc2c5 | 2021-12-20 10:37:01 -0800 | [diff] [blame] | 54 | @VisibleForTesting |
Googler | 3c7d571 | 2023-07-14 06:33:31 -0700 | [diff] [blame] | 55 | public static ActionTemplateExpansionKey of(ActionLookupKey actionLookupKey, int actionIndex) { |
janakr | b2a396b | 2018-02-15 12:42:38 -0800 | [diff] [blame] | 56 | return interner.intern(new ActionTemplateExpansionKey(actionLookupKey, actionIndex)); |
| 57 | } |
| 58 | |
Googler | 68c0716 | 2024-01-08 13:52:47 -0800 | [diff] [blame] | 59 | @VisibleForSerialization |
| 60 | @AutoCodec.Interner |
| 61 | static ActionTemplateExpansionKey intern(ActionTemplateExpansionKey key) { |
| 62 | return interner.intern(key); |
| 63 | } |
| 64 | |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 65 | @Override |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 66 | public SkyFunctionName functionName() { |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 67 | return SkyFunctions.ACTION_TEMPLATE_EXPANSION; |
| 68 | } |
| 69 | |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 70 | @Override |
| 71 | public Label getLabel() { |
janakr | cb314a2 | 2018-02-15 10:33:53 -0800 | [diff] [blame] | 72 | return actionLookupKey.getLabel(); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 73 | } |
| 74 | |
jhorvitz | 216b2b6 | 2021-11-01 08:28:55 -0700 | [diff] [blame] | 75 | @Override |
| 76 | public BuildConfigurationKey getConfigurationKey() { |
| 77 | return actionLookupKey.getConfigurationKey(); |
| 78 | } |
| 79 | |
Googler | 3c7d571 | 2023-07-14 06:33:31 -0700 | [diff] [blame] | 80 | public ActionLookupKey getActionLookupKey() { |
janakr | cb314a2 | 2018-02-15 10:33:53 -0800 | [diff] [blame] | 81 | return actionLookupKey; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Index of the action in question in the node keyed by {@link #getActionLookupKey}. Should be |
jhorvitz | 3daedc3 | 2020-07-22 18:33:55 -0700 | [diff] [blame] | 86 | * passed to {@link com.google.devtools.build.lib.actions.ActionLookupValue#getAction}. |
janakr | cb314a2 | 2018-02-15 10:33:53 -0800 | [diff] [blame] | 87 | */ |
jhorvitz | 5d34957 | 2021-09-21 09:34:12 -0700 | [diff] [blame] | 88 | public int getActionIndex() { |
janakr | cb314a2 | 2018-02-15 10:33:53 -0800 | [diff] [blame] | 89 | return actionIndex; |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | @Override |
Googler | 70f7c80 | 2023-11-06 07:44:15 -0800 | [diff] [blame] | 93 | public SkyKeyInterner<ActionTemplateExpansionKey> getSkyKeyInterner() { |
| 94 | return interner; |
| 95 | } |
| 96 | |
| 97 | @Override |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 98 | public int hashCode() { |
janakr | cb314a2 | 2018-02-15 10:33:53 -0800 | [diff] [blame] | 99 | return 37 * actionLookupKey.hashCode() + actionIndex; |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public boolean equals(Object obj) { |
janakr | cb314a2 | 2018-02-15 10:33:53 -0800 | [diff] [blame] | 104 | if (this == obj) { |
| 105 | return true; |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 106 | } |
Googler | 6f48f1c | 2024-04-16 14:29:09 -0700 | [diff] [blame] | 107 | if (!(obj instanceof ActionTemplateExpansionKey that)) { |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 108 | return false; |
| 109 | } |
janakr | cb314a2 | 2018-02-15 10:33:53 -0800 | [diff] [blame] | 110 | return this.actionIndex == that.actionIndex |
| 111 | && this.actionLookupKey.equals(that.actionLookupKey); |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public String toString() { |
| 116 | return MoreObjects.toStringHelper(this) |
| 117 | .add("actionLookupKey", actionLookupKey) |
| 118 | .add("actionIndex", actionIndex) |
| 119 | .toString(); |
Rumou Duan | 7387620 | 2016-06-06 18:52:08 +0000 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | } |