blob: 74bfd902ea15c32b9bc2bd5e105ced8a02baf5d2 [file] [log] [blame]
leba68bc63d2021-09-07 02:51:25 -07001// Copyright 2021 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
16import com.google.devtools.build.lib.actions.ActionLookupKey;
17import com.google.devtools.build.lib.analysis.TopLevelArtifactContext;
leba68bc63d2021-09-07 02:51:25 -070018import com.google.devtools.build.skyframe.SkyFunctionName;
Googlerf1131dd2023-08-31 07:30:34 -070019import com.google.devtools.build.skyframe.SkyKey;
leba94b810f2021-09-29 01:47:53 -070020import java.util.Objects;
leba68bc63d2021-09-07 02:51:25 -070021
22/**
23 * Wraps an {@link ActionLookupKey}. The evaluation of this SkyKey is the entry point of analyzing
24 * the {@link ActionLookupKey} and executing the associated actions.
25 */
Googlerf1131dd2023-08-31 07:30:34 -070026public final class BuildDriverKey implements SkyKey {
Googler3c7d5712023-07-14 06:33:31 -070027 private final ActionLookupKey actionLookupKey;
leba68bc63d2021-09-07 02:51:25 -070028 private final TopLevelArtifactContext topLevelArtifactContext;
lebae8a99922022-05-05 02:20:29 -070029 private final boolean explicitlyRequested;
Marc Zych136a1ee2023-03-27 00:06:13 -070030 private final boolean skipIncompatibleExplicitTargets;
leba121a8572022-05-19 06:11:47 -070031 private final boolean isTopLevelAspectDriver;
lebac7b44912022-03-29 05:16:33 -070032
Googler4e414d72023-05-08 02:36:48 -070033 private final boolean extraActionTopLevelOnly;
34
Googlerc031fab2024-03-18 07:34:32 -070035 // This key is created anew each build, so it's fine to carry this information here.
36 private final boolean keepGoing;
37
lebac7b44912022-03-29 05:16:33 -070038 private BuildDriverKey(
Googler3c7d5712023-07-14 06:33:31 -070039 ActionLookupKey actionLookupKey,
leba5c9c8aa2022-03-15 05:26:30 -070040 TopLevelArtifactContext topLevelArtifactContext,
lebae8a99922022-05-05 02:20:29 -070041 boolean explicitlyRequested,
Marc Zych136a1ee2023-03-27 00:06:13 -070042 boolean skipIncompatibleExplicitTargets,
Googler4e414d72023-05-08 02:36:48 -070043 boolean extraActionTopLevelOnly,
Googlerc031fab2024-03-18 07:34:32 -070044 boolean keepGoing,
Googler9f8bfb42023-05-17 06:33:59 -070045 boolean isTopLevelAspectDriver) {
leba68bc63d2021-09-07 02:51:25 -070046 this.actionLookupKey = actionLookupKey;
47 this.topLevelArtifactContext = topLevelArtifactContext;
lebae8a99922022-05-05 02:20:29 -070048 this.explicitlyRequested = explicitlyRequested;
Marc Zych136a1ee2023-03-27 00:06:13 -070049 this.skipIncompatibleExplicitTargets = skipIncompatibleExplicitTargets;
leba121a8572022-05-19 06:11:47 -070050 this.isTopLevelAspectDriver = isTopLevelAspectDriver;
Googler4e414d72023-05-08 02:36:48 -070051 this.extraActionTopLevelOnly = extraActionTopLevelOnly;
Googlerc031fab2024-03-18 07:34:32 -070052 this.keepGoing = keepGoing;
lebac7b44912022-03-29 05:16:33 -070053 }
54
55 public static BuildDriverKey ofTopLevelAspect(
56 ActionLookupKey actionLookupKey,
57 TopLevelArtifactContext topLevelArtifactContext,
Marc Zych136a1ee2023-03-27 00:06:13 -070058 boolean explicitlyRequested,
Googler4e414d72023-05-08 02:36:48 -070059 boolean skipIncompatibleExplicitTargets,
Googlerc031fab2024-03-18 07:34:32 -070060 boolean extraActionTopLevelOnly,
61 boolean keepGoing) {
lebac7b44912022-03-29 05:16:33 -070062 return new BuildDriverKey(
63 actionLookupKey,
64 topLevelArtifactContext,
lebae8a99922022-05-05 02:20:29 -070065 explicitlyRequested,
Marc Zych136a1ee2023-03-27 00:06:13 -070066 skipIncompatibleExplicitTargets,
Googler4e414d72023-05-08 02:36:48 -070067 extraActionTopLevelOnly,
Googlerc031fab2024-03-18 07:34:32 -070068 keepGoing,
Googler9f8bfb42023-05-17 06:33:59 -070069 /* isTopLevelAspectDriver= */ true);
lebac7b44912022-03-29 05:16:33 -070070 }
71
72 public static BuildDriverKey ofConfiguredTarget(
Googler3c7d5712023-07-14 06:33:31 -070073 ActionLookupKey actionLookupKey,
lebac7b44912022-03-29 05:16:33 -070074 TopLevelArtifactContext topLevelArtifactContext,
lebae8a99922022-05-05 02:20:29 -070075 boolean explicitlyRequested,
Marc Zych136a1ee2023-03-27 00:06:13 -070076 boolean skipIncompatibleExplicitTargets,
Googlerc031fab2024-03-18 07:34:32 -070077 boolean extraActionTopLevelOnly,
78 boolean keepGoing) {
lebac7b44912022-03-29 05:16:33 -070079 return new BuildDriverKey(
80 actionLookupKey,
81 topLevelArtifactContext,
lebae8a99922022-05-05 02:20:29 -070082 explicitlyRequested,
Marc Zych136a1ee2023-03-27 00:06:13 -070083 skipIncompatibleExplicitTargets,
Googler4e414d72023-05-08 02:36:48 -070084 extraActionTopLevelOnly,
Googlerc031fab2024-03-18 07:34:32 -070085 keepGoing,
Googler9f8bfb42023-05-17 06:33:59 -070086 /* isTopLevelAspectDriver= */ false);
leba68bc63d2021-09-07 02:51:25 -070087 }
88
89 public TopLevelArtifactContext getTopLevelArtifactContext() {
90 return topLevelArtifactContext;
91 }
92
Googler3c7d5712023-07-14 06:33:31 -070093 public ActionLookupKey getActionLookupKey() {
leba68bc63d2021-09-07 02:51:25 -070094 return actionLookupKey;
95 }
96
lebae8a99922022-05-05 02:20:29 -070097 public boolean isExplicitlyRequested() {
98 return explicitlyRequested;
99 }
100
Marc Zych136a1ee2023-03-27 00:06:13 -0700101 public boolean shouldSkipIncompatibleExplicitTargets() {
102 return skipIncompatibleExplicitTargets;
103 }
104
leba121a8572022-05-19 06:11:47 -0700105 public boolean isTopLevelAspectDriver() {
106 return isTopLevelAspectDriver;
107 }
108
Googler4e414d72023-05-08 02:36:48 -0700109 public boolean isExtraActionTopLevelOnly() {
110 return extraActionTopLevelOnly;
111 }
112
Googlerc031fab2024-03-18 07:34:32 -0700113 public boolean keepGoing() {
114 return keepGoing;
115 }
116
leba68bc63d2021-09-07 02:51:25 -0700117 @Override
118 public SkyFunctionName functionName() {
119 return SkyFunctions.BUILD_DRIVER;
120 }
leba94b810f2021-09-29 01:47:53 -0700121
122 @Override
123 public boolean equals(Object other) {
Googler6f48f1c2024-04-16 14:29:09 -0700124 if (other instanceof BuildDriverKey otherBuildDriverKey) {
leba94b810f2021-09-29 01:47:53 -0700125 return actionLookupKey.equals(otherBuildDriverKey.actionLookupKey)
leba1fdf1e12022-05-18 04:46:14 -0700126 && topLevelArtifactContext.equals(otherBuildDriverKey.topLevelArtifactContext)
leba1fdf1e12022-05-18 04:46:14 -0700127 && explicitlyRequested == otherBuildDriverKey.explicitlyRequested;
leba94b810f2021-09-29 01:47:53 -0700128 }
129 return false;
130 }
131
132 @Override
133 public int hashCode() {
Googlera70ba0e2023-11-01 13:59:09 -0700134 return Objects.hash(actionLookupKey, topLevelArtifactContext, explicitlyRequested);
leba94b810f2021-09-29 01:47:53 -0700135 }
leba5c9c8aa2022-03-15 05:26:30 -0700136
137 @Override
Googler9f8bfb42023-05-17 06:33:59 -0700138 public String toString() {
Googler06866912023-06-23 07:45:00 -0700139 return String.format("BuildDriverKey of ActionLookupKey: %s", actionLookupKey);
leba5c9c8aa2022-03-15 05:26:30 -0700140 }
141
Googlerda972f62022-10-05 06:39:27 -0700142 @Override
143 public boolean valueIsShareable() {
144 // BuildDriverValue is just a wrapper value that signals that the building of a top level target
145 // was concluded. It's meant to be created anew each build, since BuildDriverFunction must be
146 // run every build.
147 return false;
148 }
149
leba5c9c8aa2022-03-15 05:26:30 -0700150 enum TestType {
Googler942e0952023-01-27 01:31:20 -0800151 NOT_TEST("not-test"),
152 PARALLEL("parallel"),
153 EXCLUSIVE("exclusive"),
154 EXCLUSIVE_IF_LOCAL("exclusive-if-local");
155
156 private final String msg;
157
158 TestType(String msg) {
159 this.msg = msg;
160 }
161
162 public String getMsg() {
163 return msg;
164 }
leba5c9c8aa2022-03-15 05:26:30 -0700165 }
leba68bc63d2021-09-07 02:51:25 -0700166}