blob: 29d0e91f0f4f79f18246f0ff66604e3aa555462d [file] [log] [blame]
Rumou Duan73876202016-06-06 18:52:08 +00001// 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.
14package com.google.devtools.build.lib.skyframe;
15
janakrbadc2c52021-12-20 10:37:01 -080016import com.google.common.annotations.VisibleForTesting;
janakrcb314a22018-02-15 10:33:53 -080017import com.google.common.base.MoreObjects;
Googler0a43c702023-05-30 13:11:37 -070018import com.google.common.collect.ImmutableList;
Googler0a43c702023-05-30 13:11:37 -070019import com.google.devtools.build.lib.actions.ActionAnalysisMetadata;
jhorvitz3daedc32020-07-22 18:33:55 -070020import com.google.devtools.build.lib.actions.ActionLookupKey;
cparsonse2d200f2018-03-06 16:15:11 -080021import com.google.devtools.build.lib.actions.BasicActionLookupValue;
Rumou Duan73876202016-06-06 18:52:08 +000022import com.google.devtools.build.lib.cmdline.Label;
Googler9757df92023-10-02 08:03:35 -070023import com.google.devtools.build.lib.skyframe.config.BuildConfigurationKey;
Googler68c07162024-01-08 13:52:47 -080024import com.google.devtools.build.lib.skyframe.serialization.VisibleForSerialization;
janakrb2a396b2018-02-15 12:42:38 -080025import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
Rumou Duan73876202016-06-06 18:52:08 +000026import com.google.devtools.build.skyframe.SkyFunctionName;
Googler70f7c802023-11-06 07:44:15 -080027import com.google.devtools.build.skyframe.SkyKey;
Googler68c07162024-01-08 13:52:47 -080028import com.google.devtools.build.skyframe.SkyKey.SkyKeyInterner;
Rumou Duan73876202016-06-06 18:52:08 +000029
janakrbadc2c52021-12-20 10:37:01 -080030/** Value that stores expanded actions from ActionTemplate. */
cparsonse2d200f2018-03-06 16:15:11 -080031public final class ActionTemplateExpansionValue extends BasicActionLookupValue {
Googler0a43c702023-05-30 13:11:37 -070032
33 ActionTemplateExpansionValue(ImmutableList<ActionAnalysisMetadata> generatingActions) {
Googlerce6ad292019-12-20 10:29:21 -080034 super(generatingActions);
Rumou Duan73876202016-06-06 18:52:08 +000035 }
36
Googler3c7d5712023-07-14 06:33:31 -070037 public static ActionTemplateExpansionKey key(ActionLookupKey actionLookupKey, int actionIndex) {
janakrb2a396b2018-02-15 12:42:38 -080038 return ActionTemplateExpansionKey.of(actionLookupKey, actionIndex);
Rumou Duan73876202016-06-06 18:52:08 +000039 }
40
mschaller904dfe42019-01-07 18:25:02 -080041 /** Key for {@link ActionTemplateExpansionValue} nodes. */
janakrb2a396b2018-02-15 12:42:38 -080042 @AutoCodec
Googlerc0e7d042023-05-03 10:23:04 -070043 public static final class ActionTemplateExpansionKey implements ActionLookupKey {
Googler70f7c802023-11-06 07:44:15 -080044 private static final SkyKeyInterner<ActionTemplateExpansionKey> interner = SkyKey.newInterner();
janakrb2a396b2018-02-15 12:42:38 -080045
Googler3c7d5712023-07-14 06:33:31 -070046 private final ActionLookupKey actionLookupKey;
janakrcb314a22018-02-15 10:33:53 -080047 private final int actionIndex;
Rumou Duan73876202016-06-06 18:52:08 +000048
Googler3c7d5712023-07-14 06:33:31 -070049 private ActionTemplateExpansionKey(ActionLookupKey actionLookupKey, int actionIndex) {
janakrcb314a22018-02-15 10:33:53 -080050 this.actionLookupKey = actionLookupKey;
51 this.actionIndex = actionIndex;
Rumou Duan73876202016-06-06 18:52:08 +000052 }
53
janakrbadc2c52021-12-20 10:37:01 -080054 @VisibleForTesting
Googler3c7d5712023-07-14 06:33:31 -070055 public static ActionTemplateExpansionKey of(ActionLookupKey actionLookupKey, int actionIndex) {
janakrb2a396b2018-02-15 12:42:38 -080056 return interner.intern(new ActionTemplateExpansionKey(actionLookupKey, actionIndex));
57 }
58
Googler68c07162024-01-08 13:52:47 -080059 @VisibleForSerialization
60 @AutoCodec.Interner
61 static ActionTemplateExpansionKey intern(ActionTemplateExpansionKey key) {
62 return interner.intern(key);
63 }
64
Rumou Duan73876202016-06-06 18:52:08 +000065 @Override
janakr573807d2018-01-11 14:02:35 -080066 public SkyFunctionName functionName() {
Rumou Duan73876202016-06-06 18:52:08 +000067 return SkyFunctions.ACTION_TEMPLATE_EXPANSION;
68 }
69
Rumou Duan73876202016-06-06 18:52:08 +000070 @Override
71 public Label getLabel() {
janakrcb314a22018-02-15 10:33:53 -080072 return actionLookupKey.getLabel();
Rumou Duan73876202016-06-06 18:52:08 +000073 }
74
jhorvitz216b2b62021-11-01 08:28:55 -070075 @Override
76 public BuildConfigurationKey getConfigurationKey() {
77 return actionLookupKey.getConfigurationKey();
78 }
79
Googler3c7d5712023-07-14 06:33:31 -070080 public ActionLookupKey getActionLookupKey() {
janakrcb314a22018-02-15 10:33:53 -080081 return actionLookupKey;
82 }
83
84 /**
85 * Index of the action in question in the node keyed by {@link #getActionLookupKey}. Should be
jhorvitz3daedc32020-07-22 18:33:55 -070086 * passed to {@link com.google.devtools.build.lib.actions.ActionLookupValue#getAction}.
janakrcb314a22018-02-15 10:33:53 -080087 */
jhorvitz5d349572021-09-21 09:34:12 -070088 public int getActionIndex() {
janakrcb314a22018-02-15 10:33:53 -080089 return actionIndex;
Rumou Duan73876202016-06-06 18:52:08 +000090 }
91
92 @Override
Googler70f7c802023-11-06 07:44:15 -080093 public SkyKeyInterner<ActionTemplateExpansionKey> getSkyKeyInterner() {
94 return interner;
95 }
96
97 @Override
Rumou Duan73876202016-06-06 18:52:08 +000098 public int hashCode() {
janakrcb314a22018-02-15 10:33:53 -080099 return 37 * actionLookupKey.hashCode() + actionIndex;
Rumou Duan73876202016-06-06 18:52:08 +0000100 }
101
102 @Override
103 public boolean equals(Object obj) {
janakrcb314a22018-02-15 10:33:53 -0800104 if (this == obj) {
105 return true;
Rumou Duan73876202016-06-06 18:52:08 +0000106 }
Googler6f48f1c2024-04-16 14:29:09 -0700107 if (!(obj instanceof ActionTemplateExpansionKey that)) {
Rumou Duan73876202016-06-06 18:52:08 +0000108 return false;
109 }
janakrcb314a22018-02-15 10:33:53 -0800110 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 Duan73876202016-06-06 18:52:08 +0000120 }
121 }
122}