Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 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.analysis; |
| 15 | |
| 16 | import com.google.common.base.Joiner; |
tomlu | a155b53 | 2017-11-08 20:12:47 +0100 | [diff] [blame] | 17 | import com.google.common.base.Preconditions; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
| 19 | import com.google.common.collect.ImmutableSet; |
| 20 | import com.google.common.collect.Lists; |
Rumou Duan | 33bab46 | 2016-04-25 17:55:12 +0000 | [diff] [blame] | 21 | import com.google.devtools.build.lib.actions.ActionAnalysisMetadata; |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 22 | import com.google.devtools.build.lib.actions.ActionKeyContext; |
janakr | 658d47f | 2019-05-29 11:11:30 -0700 | [diff] [blame] | 23 | import com.google.devtools.build.lib.actions.ActionLookupValue; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 24 | import com.google.devtools.build.lib.actions.Artifact; |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 25 | import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 26 | import com.google.devtools.build.lib.actions.ArtifactFactory; |
tomlu | 1cdcdf9 | 2018-01-16 11:07:51 -0800 | [diff] [blame] | 27 | import com.google.devtools.build.lib.actions.ArtifactRoot; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 28 | import com.google.devtools.build.lib.actions.MiddlemanFactory; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 29 | import com.google.devtools.build.lib.analysis.buildinfo.BuildInfoCollection; |
Janak Ramakrishnan | f27f438 | 2015-06-04 19:50:15 +0000 | [diff] [blame] | 30 | import com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 31 | import com.google.devtools.build.lib.analysis.buildinfo.BuildInfoFactory.BuildInfoKey; |
Janak Ramakrishnan | f27f438 | 2015-06-04 19:50:15 +0000 | [diff] [blame] | 32 | import com.google.devtools.build.lib.analysis.config.BuildConfiguration; |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 33 | import com.google.devtools.build.lib.events.ExtendedEventHandler; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 34 | import com.google.devtools.build.lib.events.StoredEventHandler; |
| 35 | import com.google.devtools.build.lib.packages.Target; |
| 36 | import com.google.devtools.build.lib.skyframe.BuildInfoCollectionValue; |
Janak Ramakrishnan | f27f438 | 2015-06-04 19:50:15 +0000 | [diff] [blame] | 37 | import com.google.devtools.build.lib.skyframe.PrecomputedValue; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 38 | import com.google.devtools.build.lib.skyframe.WorkspaceStatusValue; |
laurentlb | 6659b4c | 2019-02-18 07:23:36 -0800 | [diff] [blame] | 39 | import com.google.devtools.build.lib.syntax.StarlarkSemantics; |
janakr | 9dd7e8e | 2019-05-29 13:57:16 -0700 | [diff] [blame^] | 40 | import com.google.devtools.build.lib.util.Pair; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 41 | import com.google.devtools.build.lib.vfs.PathFragment; |
| 42 | import com.google.devtools.build.skyframe.SkyFunction; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 43 | import java.io.PrintWriter; |
| 44 | import java.io.StringWriter; |
| 45 | import java.util.ArrayList; |
| 46 | import java.util.Collection; |
rosica | 246c2aa | 2019-01-15 09:55:34 -0800 | [diff] [blame] | 47 | import java.util.Collections; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 48 | import java.util.HashMap; |
| 49 | import java.util.HashSet; |
| 50 | import java.util.List; |
| 51 | import java.util.Map; |
| 52 | import java.util.Set; |
| 53 | import java.util.TreeMap; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 54 | import javax.annotation.Nullable; |
| 55 | |
| 56 | /** |
| 57 | * The implementation of AnalysisEnvironment used for analysis. It tracks metadata for each |
| 58 | * configured target, such as the errors and warnings emitted by that target. It is intended that |
| 59 | * a separate instance is used for each configured target, so that these don't mix up. |
| 60 | */ |
| 61 | public class CachingAnalysisEnvironment implements AnalysisEnvironment { |
| 62 | private final ArtifactFactory artifactFactory; |
| 63 | |
janakr | 658d47f | 2019-05-29 11:11:30 -0700 | [diff] [blame] | 64 | private final ActionLookupValue.ActionLookupKey owner; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 65 | /** |
| 66 | * If this is the system analysis environment, then errors and warnings are directly reported |
| 67 | * to the global reporter, rather than stored, i.e., we don't track here whether there are any |
| 68 | * errors. |
| 69 | */ |
| 70 | private final boolean isSystemEnv; |
| 71 | private final boolean extendedSanityChecks; |
cparsons | 9b8c500 | 2019-03-21 14:31:16 -0700 | [diff] [blame] | 72 | private final boolean allowAnalysisFailures; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 73 | |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 74 | private final ActionKeyContext actionKeyContext; |
| 75 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 76 | private boolean enabled = true; |
| 77 | private MiddlemanFactory middlemanFactory; |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 78 | private ExtendedEventHandler errorEventListener; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 79 | private SkyFunction.Environment skyframeEnv; |
janakr | 9dd7e8e | 2019-05-29 13:57:16 -0700 | [diff] [blame^] | 80 | /** |
| 81 | * Map of artifacts to either themselves or to {@code Pair<Artifact, String>} if |
| 82 | * --experimental_extended_sanity_checks is enabled. In the latter case, the string will contain |
| 83 | * the stack trace of where the artifact was created. In the former case, we'll construct a |
| 84 | * generic message in case of error. |
| 85 | * |
| 86 | * <p>The artifact is stored so that we can deduplicate artifacts created multiple times. |
| 87 | */ |
| 88 | private Map<Artifact, Object> artifacts; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * The list of actions registered by the configured target this analysis environment is |
| 92 | * responsible for. May get cleared out at the end of the analysis of said target. |
| 93 | */ |
Rumou Duan | 33bab46 | 2016-04-25 17:55:12 +0000 | [diff] [blame] | 94 | final List<ActionAnalysisMetadata> actions = new ArrayList<>(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 95 | |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 96 | public CachingAnalysisEnvironment( |
| 97 | ArtifactFactory artifactFactory, |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 98 | ActionKeyContext actionKeyContext, |
janakr | 658d47f | 2019-05-29 11:11:30 -0700 | [diff] [blame] | 99 | ActionLookupValue.ActionLookupKey owner, |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 100 | boolean isSystemEnv, |
| 101 | boolean extendedSanityChecks, |
cparsons | 9b8c500 | 2019-03-21 14:31:16 -0700 | [diff] [blame] | 102 | boolean allowAnalysisFailures, |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 103 | ExtendedEventHandler errorEventListener, |
shahan | 52bb22a | 2018-09-02 08:39:50 -0700 | [diff] [blame] | 104 | SkyFunction.Environment env) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 105 | this.artifactFactory = artifactFactory; |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 106 | this.actionKeyContext = actionKeyContext; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 107 | this.owner = Preconditions.checkNotNull(owner); |
| 108 | this.isSystemEnv = isSystemEnv; |
| 109 | this.extendedSanityChecks = extendedSanityChecks; |
cparsons | 9b8c500 | 2019-03-21 14:31:16 -0700 | [diff] [blame] | 110 | this.allowAnalysisFailures = allowAnalysisFailures; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 111 | this.errorEventListener = errorEventListener; |
| 112 | this.skyframeEnv = env; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 113 | middlemanFactory = new MiddlemanFactory(artifactFactory, this); |
| 114 | artifacts = new HashMap<>(); |
| 115 | } |
| 116 | |
| 117 | public void disable(Target target) { |
cparsons | 9b8c500 | 2019-03-21 14:31:16 -0700 | [diff] [blame] | 118 | if (!hasErrors() && !allowAnalysisFailures) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 119 | verifyGeneratedArtifactHaveActions(target); |
| 120 | } |
| 121 | artifacts = null; |
| 122 | middlemanFactory = null; |
| 123 | enabled = false; |
| 124 | errorEventListener = null; |
| 125 | skyframeEnv = null; |
| 126 | } |
| 127 | |
Rumou Duan | 33bab46 | 2016-04-25 17:55:12 +0000 | [diff] [blame] | 128 | private static StringBuilder shortDescription(ActionAnalysisMetadata action) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 129 | if (action == null) { |
| 130 | return new StringBuilder("null Action"); |
| 131 | } |
| 132 | return new StringBuilder() |
| 133 | .append(action.getClass().getName()) |
| 134 | .append(' ') |
| 135 | .append(action.getMnemonic()); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Sanity checks that all generated artifacts have a generating action. |
| 140 | * @param target for error reporting |
| 141 | */ |
| 142 | public void verifyGeneratedArtifactHaveActions(Target target) { |
| 143 | Collection<String> orphanArtifacts = getOrphanArtifactMap().values(); |
| 144 | List<String> checkedActions = null; |
| 145 | if (!orphanArtifacts.isEmpty()) { |
| 146 | checkedActions = Lists.newArrayListWithCapacity(actions.size()); |
Rumou Duan | 33bab46 | 2016-04-25 17:55:12 +0000 | [diff] [blame] | 147 | for (ActionAnalysisMetadata action : actions) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 148 | StringBuilder sb = shortDescription(action); |
| 149 | for (Artifact o : action.getOutputs()) { |
| 150 | sb.append("\n "); |
| 151 | sb.append(o.getExecPathString()); |
| 152 | } |
| 153 | checkedActions.add(sb.toString()); |
| 154 | } |
| 155 | throw new IllegalStateException( |
| 156 | String.format( |
Alex Humesky | 14f79d5 | 2015-07-08 18:39:15 +0000 | [diff] [blame] | 157 | "%s %s : These artifacts do not have a generating action:\n%s\n" |
| 158 | + "These actions were checked:\n%s\n", |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 159 | target.getTargetKind(), target.getLabel(), |
| 160 | Joiner.on('\n').join(orphanArtifacts), Joiner.on('\n').join(checkedActions))); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public ImmutableSet<Artifact> getOrphanArtifacts() { |
| 166 | return ImmutableSet.copyOf(getOrphanArtifactMap().keySet()); |
| 167 | } |
| 168 | |
Dmitry Lomov | 5b1ce4d | 2018-05-30 04:34:08 -0700 | [diff] [blame] | 169 | @Override |
| 170 | public ImmutableSet<Artifact> getTreeArtifactsConflictingWithFiles() { |
Dmitry Lomov | 5b1ce4d | 2018-05-30 04:34:08 -0700 | [diff] [blame] | 171 | boolean hasTreeArtifacts = false; |
| 172 | for (Artifact artifact : artifacts.keySet()) { |
| 173 | if (artifact.isTreeArtifact()) { |
| 174 | hasTreeArtifacts = true; |
| 175 | break; |
| 176 | } |
| 177 | } |
| 178 | if (!hasTreeArtifacts) { |
| 179 | return ImmutableSet.of(); |
| 180 | } |
| 181 | |
| 182 | HashSet<PathFragment> collect = new HashSet<>(); |
| 183 | for (Artifact artifact : artifacts.keySet()) { |
| 184 | if (!artifact.isSourceArtifact() && !artifact.isTreeArtifact()) { |
| 185 | collect.add(artifact.getExecPath()); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | ImmutableSet.Builder<Artifact> sameExecPathTreeArtifacts = ImmutableSet.builder(); |
| 190 | for (Artifact artifact : artifacts.keySet()) { |
| 191 | if (artifact.isTreeArtifact() && collect.contains(artifact.getExecPath())) { |
| 192 | sameExecPathTreeArtifacts.add(artifact); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | return sameExecPathTreeArtifacts.build(); |
| 197 | } |
| 198 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 199 | private Map<Artifact, String> getOrphanArtifactMap() { |
| 200 | // Construct this set to avoid poor performance under large --runs_per_test. |
| 201 | Set<Artifact> artifactsWithActions = new HashSet<>(); |
Rumou Duan | 33bab46 | 2016-04-25 17:55:12 +0000 | [diff] [blame] | 202 | for (ActionAnalysisMetadata action : actions) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 203 | // Don't bother checking that every Artifact only appears once; that test is performed |
| 204 | // elsewhere (see #testNonUniqueOutputs in ActionListenerIntegrationTest). |
| 205 | artifactsWithActions.addAll(action.getOutputs()); |
| 206 | } |
| 207 | // The order of the artifacts.entrySet iteration is unspecified - we use a TreeMap here to |
| 208 | // guarantee that the return value of this method is deterministic. |
Lukacs Berki | 8ae34f1 | 2015-04-10 14:54:19 +0000 | [diff] [blame] | 209 | Map<Artifact, String> orphanArtifacts = new TreeMap<>(Artifact.EXEC_PATH_COMPARATOR); |
janakr | 9dd7e8e | 2019-05-29 13:57:16 -0700 | [diff] [blame^] | 210 | for (Map.Entry<Artifact, Object> entry : artifacts.entrySet()) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 211 | Artifact a = entry.getKey(); |
| 212 | if (!a.isSourceArtifact() && !artifactsWithActions.contains(a)) { |
janakr | 9dd7e8e | 2019-05-29 13:57:16 -0700 | [diff] [blame^] | 213 | Object value = entry.getValue(); |
| 214 | if (value instanceof Artifact) { |
| 215 | value = "No origin, run with --experimental_extended_sanity_checks"; |
| 216 | } else { |
| 217 | value = ((Pair<?, ?>) value).second; |
| 218 | } |
| 219 | orphanArtifacts.put( |
| 220 | a, |
| 221 | String.format( |
| 222 | "%s\n%s", |
| 223 | a.getExecPathString(), // uncovered artifact |
| 224 | value)); // origin of creation |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | return orphanArtifacts; |
| 228 | } |
| 229 | |
| 230 | @Override |
Klaus Aehlig | 777b30d | 2017-02-24 16:30:15 +0000 | [diff] [blame] | 231 | public ExtendedEventHandler getEventHandler() { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 232 | return errorEventListener; |
| 233 | } |
| 234 | |
| 235 | @Override |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 236 | public ActionKeyContext getActionKeyContext() { |
| 237 | return actionKeyContext; |
| 238 | } |
| 239 | |
| 240 | @Override |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 241 | public boolean hasErrors() { |
| 242 | // The system analysis environment never has errors. |
| 243 | if (isSystemEnv) { |
| 244 | return false; |
| 245 | } |
| 246 | Preconditions.checkState(enabled); |
| 247 | return ((StoredEventHandler) errorEventListener).hasErrors(); |
| 248 | } |
| 249 | |
| 250 | @Override |
| 251 | public MiddlemanFactory getMiddlemanFactory() { |
| 252 | Preconditions.checkState(enabled); |
| 253 | return middlemanFactory; |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * Keeps track of artifacts. We check that all of them have an owner when the environment is |
| 258 | * sealed (disable()). For performance reasons we only track the originating stacktrace when |
| 259 | * running with --experimental_extended_sanity_checks. |
| 260 | */ |
janakr | 9dd7e8e | 2019-05-29 13:57:16 -0700 | [diff] [blame^] | 261 | @SuppressWarnings("unchecked") // Cast of artifacts map's value to Pair. |
| 262 | private Artifact.DerivedArtifact dedupAndTrackArtifactAndOrigin( |
janakr | 658d47f | 2019-05-29 11:11:30 -0700 | [diff] [blame] | 263 | Artifact.DerivedArtifact a, @Nullable Throwable e) { |
janakr | 9dd7e8e | 2019-05-29 13:57:16 -0700 | [diff] [blame^] | 264 | if (artifacts.containsKey(a)) { |
| 265 | Object value = artifacts.get(a); |
| 266 | if (e == null) { |
| 267 | return (Artifact.DerivedArtifact) value; |
| 268 | } else { |
| 269 | return ((Pair<Artifact.DerivedArtifact, String>) value).first; |
| 270 | } |
| 271 | } |
| 272 | if ((e != null)) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 273 | StringWriter sw = new StringWriter(); |
| 274 | e.printStackTrace(new PrintWriter(sw)); |
janakr | 9dd7e8e | 2019-05-29 13:57:16 -0700 | [diff] [blame^] | 275 | artifacts.put(a, Pair.of(a, sw.toString())); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 276 | } else { |
janakr | 9dd7e8e | 2019-05-29 13:57:16 -0700 | [diff] [blame^] | 277 | artifacts.put(a, a); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 278 | } |
| 279 | return a; |
| 280 | } |
| 281 | |
| 282 | @Override |
janakr | 658d47f | 2019-05-29 11:11:30 -0700 | [diff] [blame] | 283 | public Artifact.DerivedArtifact getDerivedArtifact( |
| 284 | PathFragment rootRelativePath, ArtifactRoot root) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 285 | Preconditions.checkState(enabled); |
janakr | 9dd7e8e | 2019-05-29 13:57:16 -0700 | [diff] [blame^] | 286 | return dedupAndTrackArtifactAndOrigin( |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 287 | artifactFactory.getDerivedArtifact(rootRelativePath, root, getOwner()), |
| 288 | extendedSanityChecks ? new Throwable() : null); |
| 289 | } |
| 290 | |
| 291 | @Override |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 292 | public SpecialArtifact getTreeArtifact(PathFragment rootRelativePath, ArtifactRoot root) { |
Michael Thvedt | e3b1cb7 | 2016-02-08 23:32:27 +0000 | [diff] [blame] | 293 | Preconditions.checkState(enabled); |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 294 | return (SpecialArtifact) |
janakr | 9dd7e8e | 2019-05-29 13:57:16 -0700 | [diff] [blame^] | 295 | dedupAndTrackArtifactAndOrigin( |
cpeyser | ac09f0a | 2018-02-05 09:33:15 -0800 | [diff] [blame] | 296 | artifactFactory.getTreeArtifact(rootRelativePath, root, getOwner()), |
| 297 | extendedSanityChecks ? new Throwable() : null); |
Michael Thvedt | e3b1cb7 | 2016-02-08 23:32:27 +0000 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | @Override |
janakr | 658d47f | 2019-05-29 11:11:30 -0700 | [diff] [blame] | 301 | public Artifact.DerivedArtifact getFilesetArtifact( |
| 302 | PathFragment rootRelativePath, ArtifactRoot root) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 303 | Preconditions.checkState(enabled); |
janakr | 9dd7e8e | 2019-05-29 13:57:16 -0700 | [diff] [blame^] | 304 | return dedupAndTrackArtifactAndOrigin( |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 305 | artifactFactory.getFilesetArtifact(rootRelativePath, root, getOwner()), |
| 306 | extendedSanityChecks ? new Throwable() : null); |
| 307 | } |
| 308 | |
| 309 | @Override |
tomlu | 1cdcdf9 | 2018-01-16 11:07:51 -0800 | [diff] [blame] | 310 | public Artifact getConstantMetadataArtifact(PathFragment rootRelativePath, ArtifactRoot root) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 311 | return artifactFactory.getConstantMetadataArtifact(rootRelativePath, root, getOwner()); |
| 312 | } |
| 313 | |
| 314 | @Override |
Rumou Duan | 33bab46 | 2016-04-25 17:55:12 +0000 | [diff] [blame] | 315 | public void registerAction(ActionAnalysisMetadata... actions) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 316 | Preconditions.checkState(enabled); |
rosica | 246c2aa | 2019-01-15 09:55:34 -0800 | [diff] [blame] | 317 | Collections.addAll(this.actions, actions); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | @Override |
Rumou Duan | 33bab46 | 2016-04-25 17:55:12 +0000 | [diff] [blame] | 321 | public ActionAnalysisMetadata getLocalGeneratingAction(Artifact artifact) { |
Rumou Duan | 33bab46 | 2016-04-25 17:55:12 +0000 | [diff] [blame] | 322 | for (ActionAnalysisMetadata action : actions) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 323 | if (action.getOutputs().contains(artifact)) { |
| 324 | return action; |
| 325 | } |
| 326 | } |
| 327 | return null; |
| 328 | } |
| 329 | |
| 330 | @Override |
tomlu | 9e91f20 | 2018-06-18 16:16:36 -0700 | [diff] [blame] | 331 | public ImmutableList<ActionAnalysisMetadata> getRegisteredActions() { |
| 332 | return ImmutableList.copyOf(actions); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | @Override |
| 336 | public SkyFunction.Environment getSkyframeEnv() { |
| 337 | return skyframeEnv; |
| 338 | } |
| 339 | |
| 340 | @Override |
laurentlb | 6659b4c | 2019-02-18 07:23:36 -0800 | [diff] [blame] | 341 | public StarlarkSemantics getSkylarkSemantics() throws InterruptedException { |
laurentlb | 8c02aff | 2019-02-18 10:53:34 -0800 | [diff] [blame] | 342 | return PrecomputedValue.STARLARK_SEMANTICS.get(skyframeEnv); |
brandjon | b712f33 | 2017-04-29 16:03:32 +0200 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | @Override |
Janak Ramakrishnan | 3c0adb2 | 2016-08-15 21:54:55 +0000 | [diff] [blame] | 346 | public Artifact getStableWorkspaceStatusArtifact() throws InterruptedException { |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 347 | return ((WorkspaceStatusValue) skyframeEnv.getValue(WorkspaceStatusValue.BUILD_INFO_KEY)) |
| 348 | .getStableArtifact(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | @Override |
Janak Ramakrishnan | 3c0adb2 | 2016-08-15 21:54:55 +0000 | [diff] [blame] | 352 | public Artifact getVolatileWorkspaceStatusArtifact() throws InterruptedException { |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 353 | return ((WorkspaceStatusValue) skyframeEnv.getValue(WorkspaceStatusValue.BUILD_INFO_KEY)) |
| 354 | .getVolatileArtifact(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 355 | } |
| 356 | |
Janak Ramakrishnan | f27f438 | 2015-06-04 19:50:15 +0000 | [diff] [blame] | 357 | // See SkyframeBuildView#getWorkspaceStatusValues for the code that this method is attempting to |
| 358 | // verify. |
Janak Ramakrishnan | 3c0adb2 | 2016-08-15 21:54:55 +0000 | [diff] [blame] | 359 | private NullPointerException collectDebugInfoAndCrash(BuildInfoKey key, BuildConfiguration config) |
| 360 | throws InterruptedException { |
Janak Ramakrishnan | f27f438 | 2015-06-04 19:50:15 +0000 | [diff] [blame] | 361 | String debugInfo = key + " " + config; |
| 362 | Preconditions.checkState(skyframeEnv.valuesMissing(), debugInfo); |
| 363 | Map<BuildInfoKey, BuildInfoFactory> buildInfoFactories = Preconditions.checkNotNull( |
| 364 | PrecomputedValue.BUILD_INFO_FACTORIES.get(skyframeEnv), debugInfo); |
| 365 | BuildInfoFactory buildInfoFactory = |
| 366 | Preconditions.checkNotNull(buildInfoFactories.get(key), debugInfo); |
| 367 | Preconditions.checkState(buildInfoFactory.isEnabled(config), debugInfo); |
| 368 | throw new NullPointerException("BuildInfoCollectionValue shouldn't have been null"); |
| 369 | } |
| 370 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 371 | @Override |
Googler | 38ad0bf | 2016-07-01 05:00:14 +0000 | [diff] [blame] | 372 | public ImmutableList<Artifact> getBuildInfo( |
plf | 1f341a6 | 2019-04-01 14:02:14 -0700 | [diff] [blame] | 373 | boolean stamp, BuildInfoKey key, BuildConfiguration config) throws InterruptedException { |
Janak Ramakrishnan | f27f438 | 2015-06-04 19:50:15 +0000 | [diff] [blame] | 374 | BuildInfoCollectionValue collectionValue = |
janakr | 573807d | 2018-01-11 14:02:35 -0800 | [diff] [blame] | 375 | (BuildInfoCollectionValue) skyframeEnv.getValue(BuildInfoCollectionValue.key(key, config)); |
Janak Ramakrishnan | f27f438 | 2015-06-04 19:50:15 +0000 | [diff] [blame] | 376 | if (collectionValue == null) { |
Googler | 38ad0bf | 2016-07-01 05:00:14 +0000 | [diff] [blame] | 377 | throw collectDebugInfoAndCrash(key, config); |
Janak Ramakrishnan | f27f438 | 2015-06-04 19:50:15 +0000 | [diff] [blame] | 378 | } |
| 379 | BuildInfoCollection collection = collectionValue.getCollection(); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 380 | return stamp ? collection.getStampedBuildInfo() : collection.getRedactedBuildInfo(); |
| 381 | } |
| 382 | |
| 383 | @Override |
janakr | 658d47f | 2019-05-29 11:11:30 -0700 | [diff] [blame] | 384 | public ActionLookupValue.ActionLookupKey getOwner() { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 385 | return owner; |
| 386 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 387 | } |