diff options
Diffstat (limited to 'src')
4 files changed, 55 insertions, 43 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java index d6c3d413a0..ccccd91b7a 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/BuildView.java @@ -269,16 +269,6 @@ public class BuildView { this.skyframeBuildView = skyframeExecutor.getSkyframeBuildView(); } - /** Returns the action graph. */ - public ActionGraph getActionGraph() { - return new ActionGraph() { - @Override - public Action getGeneratingAction(Artifact artifact) { - return skyframeExecutor.getGeneratingAction(artifact); - } - }; - } - /** * Returns whether the given configured target has errors. */ diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java index 0ff269d2bd..bc3d0771e1 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java @@ -38,6 +38,7 @@ import com.google.devtools.build.lib.actions.Action; import com.google.devtools.build.lib.actions.ActionCacheChecker; import com.google.devtools.build.lib.actions.ActionExecutionContextFactory; import com.google.devtools.build.lib.actions.ActionExecutionStatusReporter; +import com.google.devtools.build.lib.actions.ActionGraph; import com.google.devtools.build.lib.actions.ActionInputFileCache; import com.google.devtools.build.lib.actions.ActionLogBufferPathGenerator; import com.google.devtools.build.lib.actions.Artifact; @@ -1451,44 +1452,55 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory { } /** - * Returns the generating {@link Action} of the given {@link Artifact}. - * - * <p>For use for legacy support from {@code BuildView} only. + * Returns the generating action of a given artifact ({@code null} if it's a source artifact). */ - @ThreadSafety.ThreadSafe - public Action getGeneratingAction(final Artifact artifact) { + private Action getGeneratingAction(Artifact artifact) throws InterruptedException { if (artifact.isSourceArtifact()) { return null; } - try { - return callUninterruptibly(new Callable<Action>() { - @Override - public Action call() throws InterruptedException { - ArtifactOwner artifactOwner = artifact.getArtifactOwner(); - Preconditions.checkState(artifactOwner instanceof ActionLookupValue.ActionLookupKey, - "%s %s", artifact, artifactOwner); - SkyKey actionLookupKey = - ActionLookupValue.key((ActionLookupValue.ActionLookupKey) artifactOwner); + ArtifactOwner artifactOwner = artifact.getArtifactOwner(); + Preconditions.checkState(artifactOwner instanceof ActionLookupValue.ActionLookupKey, + "%s %s", artifact, artifactOwner); + SkyKey actionLookupKey = + ActionLookupValue.key((ActionLookupValue.ActionLookupKey) artifactOwner); + + synchronized (valueLookupLock) { + // Note that this will crash (attempting to run a configured target value builder after + // analysis) after a failed --nokeep_going analysis in which the configured target that + // failed was a (transitive) dependency of the configured target that should generate + // this action. We don't expect callers to query generating actions in such cases. + EvaluationResult<ActionLookupValue> result = buildDriver.evaluate( + ImmutableList.of(actionLookupKey), false, ResourceUsage.getAvailableProcessors(), + errorEventListener); + return result.hasError() + ? null + : result.get(actionLookupKey).getGeneratingAction(artifact); + } + } - synchronized (valueLookupLock) { - // Note that this will crash (attempting to run a configured target value builder after - // analysis) after a failed --nokeep_going analysis in which the configured target that - // failed was a (transitive) dependency of the configured target that should generate - // this action. We don't expect callers to query generating actions in such cases. - EvaluationResult<ActionLookupValue> result = buildDriver.evaluate( - ImmutableList.of(actionLookupKey), false, ResourceUsage.getAvailableProcessors(), - errorEventListener); - return result.hasError() - ? null - : result.get(actionLookupKey).getGeneratingAction(artifact); - } + /** + * Returns an action graph. + * + * <p>For legacy compatibility only. + */ + public ActionGraph getActionGraph() { + return new ActionGraph() { + @Override + public Action getGeneratingAction(final Artifact artifact) { + try { + return callUninterruptibly(new Callable<Action>() { + @Override + public Action call() throws InterruptedException { + return SkyframeExecutor.this.getGeneratingAction(artifact); + } + }); + } catch (Exception e) { + throw new IllegalStateException("Error getting generating action: " + + artifact.prettyPrint(), e); } - }); - } catch (Exception e) { - throw new IllegalStateException("Error getting generating action: " + artifact.prettyPrint(), - e); - } + } + }; } public PackageManager getPackageManager() { diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java index 04687cf0bd..bbc9659a73 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java @@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Iterables; import com.google.common.eventbus.EventBus; import com.google.devtools.build.lib.actions.Action; +import com.google.devtools.build.lib.actions.ActionGraph; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.analysis.BuildView; @@ -364,6 +365,10 @@ public abstract class AnalysisTestCase extends FoundationTestCase { return buildView; } + protected ActionGraph getActionGraph() { + return skyframeExecutor.getActionGraph(); + } + protected AnalysisResult getAnalysisResult() { return analysisResult; } diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java index 8b99141cde..9eb6f89dd7 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java @@ -29,6 +29,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.google.common.eventbus.EventBus; import com.google.devtools.build.lib.actions.Action; +import com.google.devtools.build.lib.actions.ActionGraph; import com.google.devtools.build.lib.actions.ActionInput; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.ArtifactOwner; @@ -490,13 +491,17 @@ public abstract class BuildViewTestCase extends FoundationTestCase { return ImmutableList.copyOf(result); } + protected ActionGraph getActionGraph() { + return skyframeExecutor.getActionGraph(); + } + protected final Action getGeneratingAction(Artifact artifact) { Preconditions.checkNotNull(artifact); Action action = mutableActionGraph.getGeneratingAction(artifact); if (action != null) { return action; } - return view.getActionGraph().getGeneratingAction(artifact); + return getActionGraph().getGeneratingAction(artifact); } protected void simulateLoadingPhase() { @@ -508,7 +513,7 @@ public abstract class BuildViewTestCase extends FoundationTestCase { } protected ActionsTestUtil actionsTestUtil() { - return new ActionsTestUtil(view.getActionGraph()); + return new ActionsTestUtil(getActionGraph()); } private Set<Target> getTargets(Iterable<Label> labels) throws InterruptedException, |