leba | 68bc63d | 2021-09-07 02:51:25 -0700 | [diff] [blame] | 1 | // 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. |
| 14 | package com.google.devtools.build.lib.skyframe; |
| 15 | |
| 16 | import com.google.devtools.build.lib.actions.ActionLookupKey; |
| 17 | import com.google.devtools.build.lib.analysis.TopLevelArtifactContext; |
leba | 68bc63d | 2021-09-07 02:51:25 -0700 | [diff] [blame] | 18 | import com.google.devtools.build.skyframe.SkyFunctionName; |
Googler | f1131dd | 2023-08-31 07:30:34 -0700 | [diff] [blame] | 19 | import com.google.devtools.build.skyframe.SkyKey; |
leba | 94b810f | 2021-09-29 01:47:53 -0700 | [diff] [blame] | 20 | import java.util.Objects; |
leba | 68bc63d | 2021-09-07 02:51:25 -0700 | [diff] [blame] | 21 | |
| 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 | */ |
Googler | f1131dd | 2023-08-31 07:30:34 -0700 | [diff] [blame] | 26 | public final class BuildDriverKey implements SkyKey { |
Googler | 3c7d571 | 2023-07-14 06:33:31 -0700 | [diff] [blame] | 27 | private final ActionLookupKey actionLookupKey; |
leba | 68bc63d | 2021-09-07 02:51:25 -0700 | [diff] [blame] | 28 | private final TopLevelArtifactContext topLevelArtifactContext; |
leba | e8a9992 | 2022-05-05 02:20:29 -0700 | [diff] [blame] | 29 | private final boolean explicitlyRequested; |
Marc Zych | 136a1ee | 2023-03-27 00:06:13 -0700 | [diff] [blame] | 30 | private final boolean skipIncompatibleExplicitTargets; |
leba | 121a857 | 2022-05-19 06:11:47 -0700 | [diff] [blame] | 31 | private final boolean isTopLevelAspectDriver; |
leba | c7b4491 | 2022-03-29 05:16:33 -0700 | [diff] [blame] | 32 | |
Googler | 4e414d7 | 2023-05-08 02:36:48 -0700 | [diff] [blame] | 33 | private final boolean extraActionTopLevelOnly; |
| 34 | |
Googler | c031fab | 2024-03-18 07:34:32 -0700 | [diff] [blame] | 35 | // This key is created anew each build, so it's fine to carry this information here. |
| 36 | private final boolean keepGoing; |
| 37 | |
leba | c7b4491 | 2022-03-29 05:16:33 -0700 | [diff] [blame] | 38 | private BuildDriverKey( |
Googler | 3c7d571 | 2023-07-14 06:33:31 -0700 | [diff] [blame] | 39 | ActionLookupKey actionLookupKey, |
leba | 5c9c8aa | 2022-03-15 05:26:30 -0700 | [diff] [blame] | 40 | TopLevelArtifactContext topLevelArtifactContext, |
leba | e8a9992 | 2022-05-05 02:20:29 -0700 | [diff] [blame] | 41 | boolean explicitlyRequested, |
Marc Zych | 136a1ee | 2023-03-27 00:06:13 -0700 | [diff] [blame] | 42 | boolean skipIncompatibleExplicitTargets, |
Googler | 4e414d7 | 2023-05-08 02:36:48 -0700 | [diff] [blame] | 43 | boolean extraActionTopLevelOnly, |
Googler | c031fab | 2024-03-18 07:34:32 -0700 | [diff] [blame] | 44 | boolean keepGoing, |
Googler | 9f8bfb4 | 2023-05-17 06:33:59 -0700 | [diff] [blame] | 45 | boolean isTopLevelAspectDriver) { |
leba | 68bc63d | 2021-09-07 02:51:25 -0700 | [diff] [blame] | 46 | this.actionLookupKey = actionLookupKey; |
| 47 | this.topLevelArtifactContext = topLevelArtifactContext; |
leba | e8a9992 | 2022-05-05 02:20:29 -0700 | [diff] [blame] | 48 | this.explicitlyRequested = explicitlyRequested; |
Marc Zych | 136a1ee | 2023-03-27 00:06:13 -0700 | [diff] [blame] | 49 | this.skipIncompatibleExplicitTargets = skipIncompatibleExplicitTargets; |
leba | 121a857 | 2022-05-19 06:11:47 -0700 | [diff] [blame] | 50 | this.isTopLevelAspectDriver = isTopLevelAspectDriver; |
Googler | 4e414d7 | 2023-05-08 02:36:48 -0700 | [diff] [blame] | 51 | this.extraActionTopLevelOnly = extraActionTopLevelOnly; |
Googler | c031fab | 2024-03-18 07:34:32 -0700 | [diff] [blame] | 52 | this.keepGoing = keepGoing; |
leba | c7b4491 | 2022-03-29 05:16:33 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | public static BuildDriverKey ofTopLevelAspect( |
| 56 | ActionLookupKey actionLookupKey, |
| 57 | TopLevelArtifactContext topLevelArtifactContext, |
Marc Zych | 136a1ee | 2023-03-27 00:06:13 -0700 | [diff] [blame] | 58 | boolean explicitlyRequested, |
Googler | 4e414d7 | 2023-05-08 02:36:48 -0700 | [diff] [blame] | 59 | boolean skipIncompatibleExplicitTargets, |
Googler | c031fab | 2024-03-18 07:34:32 -0700 | [diff] [blame] | 60 | boolean extraActionTopLevelOnly, |
| 61 | boolean keepGoing) { |
leba | c7b4491 | 2022-03-29 05:16:33 -0700 | [diff] [blame] | 62 | return new BuildDriverKey( |
| 63 | actionLookupKey, |
| 64 | topLevelArtifactContext, |
leba | e8a9992 | 2022-05-05 02:20:29 -0700 | [diff] [blame] | 65 | explicitlyRequested, |
Marc Zych | 136a1ee | 2023-03-27 00:06:13 -0700 | [diff] [blame] | 66 | skipIncompatibleExplicitTargets, |
Googler | 4e414d7 | 2023-05-08 02:36:48 -0700 | [diff] [blame] | 67 | extraActionTopLevelOnly, |
Googler | c031fab | 2024-03-18 07:34:32 -0700 | [diff] [blame] | 68 | keepGoing, |
Googler | 9f8bfb4 | 2023-05-17 06:33:59 -0700 | [diff] [blame] | 69 | /* isTopLevelAspectDriver= */ true); |
leba | c7b4491 | 2022-03-29 05:16:33 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | public static BuildDriverKey ofConfiguredTarget( |
Googler | 3c7d571 | 2023-07-14 06:33:31 -0700 | [diff] [blame] | 73 | ActionLookupKey actionLookupKey, |
leba | c7b4491 | 2022-03-29 05:16:33 -0700 | [diff] [blame] | 74 | TopLevelArtifactContext topLevelArtifactContext, |
leba | e8a9992 | 2022-05-05 02:20:29 -0700 | [diff] [blame] | 75 | boolean explicitlyRequested, |
Marc Zych | 136a1ee | 2023-03-27 00:06:13 -0700 | [diff] [blame] | 76 | boolean skipIncompatibleExplicitTargets, |
Googler | c031fab | 2024-03-18 07:34:32 -0700 | [diff] [blame] | 77 | boolean extraActionTopLevelOnly, |
| 78 | boolean keepGoing) { |
leba | c7b4491 | 2022-03-29 05:16:33 -0700 | [diff] [blame] | 79 | return new BuildDriverKey( |
| 80 | actionLookupKey, |
| 81 | topLevelArtifactContext, |
leba | e8a9992 | 2022-05-05 02:20:29 -0700 | [diff] [blame] | 82 | explicitlyRequested, |
Marc Zych | 136a1ee | 2023-03-27 00:06:13 -0700 | [diff] [blame] | 83 | skipIncompatibleExplicitTargets, |
Googler | 4e414d7 | 2023-05-08 02:36:48 -0700 | [diff] [blame] | 84 | extraActionTopLevelOnly, |
Googler | c031fab | 2024-03-18 07:34:32 -0700 | [diff] [blame] | 85 | keepGoing, |
Googler | 9f8bfb4 | 2023-05-17 06:33:59 -0700 | [diff] [blame] | 86 | /* isTopLevelAspectDriver= */ false); |
leba | 68bc63d | 2021-09-07 02:51:25 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | public TopLevelArtifactContext getTopLevelArtifactContext() { |
| 90 | return topLevelArtifactContext; |
| 91 | } |
| 92 | |
Googler | 3c7d571 | 2023-07-14 06:33:31 -0700 | [diff] [blame] | 93 | public ActionLookupKey getActionLookupKey() { |
leba | 68bc63d | 2021-09-07 02:51:25 -0700 | [diff] [blame] | 94 | return actionLookupKey; |
| 95 | } |
| 96 | |
leba | e8a9992 | 2022-05-05 02:20:29 -0700 | [diff] [blame] | 97 | public boolean isExplicitlyRequested() { |
| 98 | return explicitlyRequested; |
| 99 | } |
| 100 | |
Marc Zych | 136a1ee | 2023-03-27 00:06:13 -0700 | [diff] [blame] | 101 | public boolean shouldSkipIncompatibleExplicitTargets() { |
| 102 | return skipIncompatibleExplicitTargets; |
| 103 | } |
| 104 | |
leba | 121a857 | 2022-05-19 06:11:47 -0700 | [diff] [blame] | 105 | public boolean isTopLevelAspectDriver() { |
| 106 | return isTopLevelAspectDriver; |
| 107 | } |
| 108 | |
Googler | 4e414d7 | 2023-05-08 02:36:48 -0700 | [diff] [blame] | 109 | public boolean isExtraActionTopLevelOnly() { |
| 110 | return extraActionTopLevelOnly; |
| 111 | } |
| 112 | |
Googler | c031fab | 2024-03-18 07:34:32 -0700 | [diff] [blame] | 113 | public boolean keepGoing() { |
| 114 | return keepGoing; |
| 115 | } |
| 116 | |
leba | 68bc63d | 2021-09-07 02:51:25 -0700 | [diff] [blame] | 117 | @Override |
| 118 | public SkyFunctionName functionName() { |
| 119 | return SkyFunctions.BUILD_DRIVER; |
| 120 | } |
leba | 94b810f | 2021-09-29 01:47:53 -0700 | [diff] [blame] | 121 | |
| 122 | @Override |
| 123 | public boolean equals(Object other) { |
Googler | 6f48f1c | 2024-04-16 14:29:09 -0700 | [diff] [blame] | 124 | if (other instanceof BuildDriverKey otherBuildDriverKey) { |
leba | 94b810f | 2021-09-29 01:47:53 -0700 | [diff] [blame] | 125 | return actionLookupKey.equals(otherBuildDriverKey.actionLookupKey) |
leba | 1fdf1e1 | 2022-05-18 04:46:14 -0700 | [diff] [blame] | 126 | && topLevelArtifactContext.equals(otherBuildDriverKey.topLevelArtifactContext) |
leba | 1fdf1e1 | 2022-05-18 04:46:14 -0700 | [diff] [blame] | 127 | && explicitlyRequested == otherBuildDriverKey.explicitlyRequested; |
leba | 94b810f | 2021-09-29 01:47:53 -0700 | [diff] [blame] | 128 | } |
| 129 | return false; |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public int hashCode() { |
Googler | a70ba0e | 2023-11-01 13:59:09 -0700 | [diff] [blame] | 134 | return Objects.hash(actionLookupKey, topLevelArtifactContext, explicitlyRequested); |
leba | 94b810f | 2021-09-29 01:47:53 -0700 | [diff] [blame] | 135 | } |
leba | 5c9c8aa | 2022-03-15 05:26:30 -0700 | [diff] [blame] | 136 | |
| 137 | @Override |
Googler | 9f8bfb4 | 2023-05-17 06:33:59 -0700 | [diff] [blame] | 138 | public String toString() { |
Googler | 0686691 | 2023-06-23 07:45:00 -0700 | [diff] [blame] | 139 | return String.format("BuildDriverKey of ActionLookupKey: %s", actionLookupKey); |
leba | 5c9c8aa | 2022-03-15 05:26:30 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Googler | da972f6 | 2022-10-05 06:39:27 -0700 | [diff] [blame] | 142 | @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 | |
leba | 5c9c8aa | 2022-03-15 05:26:30 -0700 | [diff] [blame] | 150 | enum TestType { |
Googler | 942e095 | 2023-01-27 01:31:20 -0800 | [diff] [blame] | 151 | 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 | } |
leba | 5c9c8aa | 2022-03-15 05:26:30 -0700 | [diff] [blame] | 165 | } |
leba | 68bc63d | 2021-09-07 02:51:25 -0700 | [diff] [blame] | 166 | } |