diff options
author | 2018-08-02 11:49:08 -0700 | |
---|---|---|
committer | 2018-08-02 11:50:28 -0700 | |
commit | 04e9281ad2353ffa75f05c3e67c55d6fa2130a1c (patch) | |
tree | a0d1a11b9e3b5cdfb776029fa9795cdb0f22c643 | |
parent | d1a203bbdd2033ec8049b39242189e1cc76a9e8e (diff) |
Thread a path resolver through target/aspect complete event.
At the moment, an identity path resolver is passed. This will later be replaced by a contextual path resolver.
RELNOTES: None
PiperOrigin-RevId: 207138772
9 files changed, 95 insertions, 44 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ArtifactPathResolver.java b/src/main/java/com/google/devtools/build/lib/actions/ArtifactPathResolver.java index 3aabfcab77..d9f5e3d43d 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ArtifactPathResolver.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ArtifactPathResolver.java @@ -22,7 +22,7 @@ import javax.annotation.Nullable; /** * An indirection layer on Path resolution of {@link Artifact} and {@link Root}. * - * Serves as converter interface primarily for switching the {@link FileSystem} underyling the + * <p>Serves as converter interface primarily for switching the {@link FileSystem} underlying the * values. */ public interface ArtifactPathResolver { diff --git a/src/main/java/com/google/devtools/build/lib/actions/EventReportingArtifacts.java b/src/main/java/com/google/devtools/build/lib/actions/EventReportingArtifacts.java index a81fc00f50..1df2987043 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/EventReportingArtifacts.java +++ b/src/main/java/com/google/devtools/build/lib/actions/EventReportingArtifacts.java @@ -20,6 +20,19 @@ import java.util.Collection; /** Interface for {@link BuildEvent}s reporting artifacts as named sets */ public interface EventReportingArtifacts extends BuildEvent { - /** The sets of artifacts this build event asumes already known in the build event stream. */ - Collection<NestedSet<Artifact>> reportedArtifacts(); + + /** Pair of artifacts and a path resolver. */ + class ReportedArtifacts { + public final Collection<NestedSet<Artifact>> artifacts; + public final ArtifactPathResolver pathResolver; + + public ReportedArtifacts( + Collection<NestedSet<Artifact>> artifacts, ArtifactPathResolver pathResolver) { + this.artifacts = artifacts; + this.pathResolver = pathResolver; + } + } + + /** The sets of artifacts this build event assumes already known in the build event stream. */ + ReportedArtifacts reportedArtifacts(); } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/AspectCompleteEvent.java b/src/main/java/com/google/devtools/build/lib/analysis/AspectCompleteEvent.java index 6cd519fd3a..f7d0b70733 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/AspectCompleteEvent.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/AspectCompleteEvent.java @@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.actions.ArtifactPathResolver; import com.google.devtools.build.lib.actions.EventReportingArtifacts; import com.google.devtools.build.lib.analysis.TopLevelArtifactHelper.ArtifactsInOutputGroup; import com.google.devtools.build.lib.analysis.TopLevelArtifactHelper.ArtifactsToBuild; @@ -43,10 +44,14 @@ public class AspectCompleteEvent private final AspectValue aspectValue; private final NestedSet<Cause> rootCauses; private final Collection<BuildEventId> postedAfter; + private final ArtifactPathResolver pathResolver; private final ArtifactsToBuild artifacts; private AspectCompleteEvent( - AspectValue aspectValue, NestedSet<Cause> rootCauses, ArtifactsToBuild artifacts) { + AspectValue aspectValue, + NestedSet<Cause> rootCauses, + ArtifactPathResolver pathResolver, + ArtifactsToBuild artifacts) { this.aspectValue = aspectValue; this.rootCauses = (rootCauses == null) ? NestedSetBuilder.<Cause>emptySet(Order.STABLE_ORDER) : rootCauses; @@ -55,13 +60,14 @@ public class AspectCompleteEvent postedAfterBuilder.add(BuildEventId.fromCause(cause)); } this.postedAfter = postedAfterBuilder.build(); + this.pathResolver = pathResolver; this.artifacts = artifacts; } /** Construct a successful target completion event. */ public static AspectCompleteEvent createSuccessful( - AspectValue value, ArtifactsToBuild artifacts) { - return new AspectCompleteEvent(value, null, artifacts); + AspectValue value, ArtifactPathResolver pathResolver, ArtifactsToBuild artifacts) { + return new AspectCompleteEvent(value, null, pathResolver, artifacts); } /** @@ -69,7 +75,7 @@ public class AspectCompleteEvent */ public static AspectCompleteEvent createFailed(AspectValue value, NestedSet<Cause> rootCauses) { Preconditions.checkArgument(!Iterables.isEmpty(rootCauses)); - return new AspectCompleteEvent(value, rootCauses, null); + return new AspectCompleteEvent(value, rootCauses, ArtifactPathResolver.IDENTITY, null); } /** @@ -108,15 +114,14 @@ public class AspectCompleteEvent } @Override - public Collection<NestedSet<Artifact>> reportedArtifacts() { - ImmutableSet.Builder<NestedSet<Artifact>> builder = - new ImmutableSet.Builder<NestedSet<Artifact>>(); + public ReportedArtifacts reportedArtifacts() { + ImmutableSet.Builder<NestedSet<Artifact>> builder = ImmutableSet.builder(); if (artifacts != null) { for (ArtifactsInOutputGroup artifactsInGroup : artifacts.getAllArtifactsByOutputGroup()) { builder.add(artifactsInGroup.getArtifacts()); } } - return builder.build(); + return new ReportedArtifacts(builder.build(), pathResolver); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java b/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java index 53a3f16e7e..e1dfa5e5f7 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/TargetCompleteEvent.java @@ -21,6 +21,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.actions.ArtifactPathResolver; import com.google.devtools.build.lib.actions.EventReportingArtifacts; import com.google.devtools.build.lib.analysis.TopLevelArtifactHelper.ArtifactsInOutputGroup; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; @@ -101,6 +102,7 @@ public final class TargetCompleteEvent private final ConfiguredTargetKey configuredTargetKey; private final NestedSet<Cause> rootCauses; private final ImmutableList<BuildEventId> postedAfter; + private final ArtifactPathResolver pathResolver; private final NestedSet<ArtifactsInOutputGroup> outputs; private final NestedSet<Artifact> baselineCoverageArtifacts; private final Label aliasLabel; @@ -115,6 +117,7 @@ public final class TargetCompleteEvent private TargetCompleteEvent( ConfiguredTargetAndData targetAndData, NestedSet<Cause> rootCauses, + ArtifactPathResolver pathResolver, NestedSet<ArtifactsInOutputGroup> outputs, boolean isTest) { this.rootCauses = @@ -136,6 +139,7 @@ public final class TargetCompleteEvent postedAfterBuilder.add(BuildEventId.fromCause(cause)); } this.postedAfter = postedAfterBuilder.build(); + this.pathResolver = pathResolver; this.outputs = outputs; this.isTest = isTest; this.testTimeoutSeconds = isTest ? getTestTimeoutSeconds(targetAndData) : null; @@ -175,14 +179,18 @@ public final class TargetCompleteEvent /** Construct a successful target completion event. */ public static TargetCompleteEvent successfulBuild( - ConfiguredTargetAndData ct, NestedSet<ArtifactsInOutputGroup> outputs) { - return new TargetCompleteEvent(ct, null, outputs, false); + ConfiguredTargetAndData ct, + ArtifactPathResolver pathResolver, + NestedSet<ArtifactsInOutputGroup> outputs) { + return new TargetCompleteEvent(ct, null, pathResolver, outputs, false); } /** Construct a successful target completion event for a target that will be tested. */ public static TargetCompleteEvent successfulBuildSchedulingTest( - ConfiguredTargetAndData ct, NestedSet<ArtifactsInOutputGroup> outputs) { - return new TargetCompleteEvent(ct, null, outputs, true); + ConfiguredTargetAndData ct, + ArtifactPathResolver pathResolver, + NestedSet<ArtifactsInOutputGroup> outputs) { + return new TargetCompleteEvent(ct, null, pathResolver, outputs, true); } /** @@ -192,7 +200,11 @@ public final class TargetCompleteEvent ConfiguredTargetAndData ct, NestedSet<Cause> rootCauses) { Preconditions.checkArgument(!Iterables.isEmpty(rootCauses)); return new TargetCompleteEvent( - ct, rootCauses, NestedSetBuilder.emptySet(Order.STABLE_ORDER), false); + ct, + rootCauses, + ArtifactPathResolver.IDENTITY, + NestedSetBuilder.emptySet(Order.STABLE_ORDER), + false); } /** Returns the label of the target associated with the event. */ @@ -260,20 +272,23 @@ public final class TargetCompleteEvent // TODO(aehlig): remove as soon as we managed to get rid of the deprecated "important_output" // field. private static void addImportantOutputs( + ArtifactPathResolver pathResolver, BuildEventStreamProtos.TargetComplete.Builder builder, BuildEventContext converters, Iterable<Artifact> artifacts) { - addImportantOutputs(builder, Artifact::getRootRelativePathString, converters, artifacts); + addImportantOutputs( + pathResolver, builder, Artifact::getRootRelativePathString, converters, artifacts); } private static void addImportantOutputs( + ArtifactPathResolver pathResolver, BuildEventStreamProtos.TargetComplete.Builder builder, Function<Artifact, String> artifactNameFunction, BuildEventContext converters, Iterable<Artifact> artifacts) { for (Artifact artifact : artifacts) { String name = artifactNameFunction.apply(artifact); - String uri = converters.pathConverter().apply(artifact.getPath()); + String uri = converters.pathConverter().apply(pathResolver.toPath(artifact)); if (uri != null) { builder.addImportantOutput(File.newBuilder().setName(name).setUri(uri).build()); } @@ -288,7 +303,7 @@ public final class TargetCompleteEvent for (Artifact artifact : group.getArtifacts()) { builder.add( new LocalFile( - artifact.getPath(), + pathResolver.toPath(artifact), artifact.isSourceArtifact() ? LocalFileType.SOURCE : LocalFileType.OUTPUT)); } } @@ -297,7 +312,7 @@ public final class TargetCompleteEvent for (Artifact artifact : baselineCoverageArtifacts) { builder.add( new LocalFile( - artifact.getPath(), + pathResolver.toPath(artifact), artifact.isSourceArtifact() ? LocalFileType.SOURCE : LocalFileType.OUTPUT)); } } @@ -320,10 +335,14 @@ public final class TargetCompleteEvent // TODO(aehlig): remove direct reporting of artifacts as soon as clients no longer // need it. if (converters.getOptions().legacyImportantOutputs) { - addImportantOutputs(builder, converters, getLegacyFilteredImportantArtifacts()); + addImportantOutputs(pathResolver, builder, converters, getLegacyFilteredImportantArtifacts()); if (baselineCoverageArtifacts != null) { addImportantOutputs( - builder, (artifact -> BASELINE_COVERAGE), converters, baselineCoverageArtifacts); + pathResolver, + builder, + (artifact -> BASELINE_COVERAGE), + converters, + baselineCoverageArtifacts); } } @@ -337,16 +356,15 @@ public final class TargetCompleteEvent } @Override - public Collection<NestedSet<Artifact>> reportedArtifacts() { - ImmutableSet.Builder<NestedSet<Artifact>> builder = - new ImmutableSet.Builder<NestedSet<Artifact>>(); + public ReportedArtifacts reportedArtifacts() { + ImmutableSet.Builder<NestedSet<Artifact>> builder = ImmutableSet.builder(); for (ArtifactsInOutputGroup artifactsInGroup : outputs) { builder.add(artifactsInGroup.getArtifacts()); } if (baselineCoverageArtifacts != null) { builder.add(baselineCoverageArtifacts); } - return builder.build(); + return new ReportedArtifacts(builder.build(), pathResolver); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java b/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java index 6af82547ca..529297633a 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java @@ -30,7 +30,9 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.devtools.build.lib.actions.ActionExecutedEvent; import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.actions.ArtifactPathResolver; import com.google.devtools.build.lib.actions.EventReportingArtifacts; +import com.google.devtools.build.lib.actions.EventReportingArtifacts.ReportedArtifacts; import com.google.devtools.build.lib.analysis.BuildInfoEvent; import com.google.devtools.build.lib.analysis.NoBuildEvent; import com.google.devtools.build.lib.analysis.extra.ExtraAction; @@ -397,7 +399,8 @@ public class BuildEventStreamer implements EventHandler { } } - private void maybeReportArtifactSet(NestedSetView<Artifact> view) { + private void maybeReportArtifactSet( + ArtifactPathResolver pathResolver, NestedSetView<Artifact> view) { String name = artifactGroupNamer.maybeName(view); if (name == null) { return; @@ -411,13 +414,13 @@ public class BuildEventStreamer implements EventHandler { view = view.splitIfExceedsMaximumSize(options.maxNamedSetEntries); } for (NestedSetView<Artifact> transitive : view.transitives()) { - maybeReportArtifactSet(transitive); + maybeReportArtifactSet(pathResolver, transitive); } - post(new NamedArtifactGroup(name, view)); + post(new NamedArtifactGroup(name, pathResolver, view)); } - private void maybeReportArtifactSet(NestedSet<Artifact> set) { - maybeReportArtifactSet(new NestedSetView<Artifact>(set)); + private void maybeReportArtifactSet(ArtifactPathResolver pathResolver, NestedSet<Artifact> set) { + maybeReportArtifactSet(pathResolver, new NestedSetView<Artifact>(set)); } private void maybeReportConfiguration(BuildEvent configuration) { @@ -483,9 +486,9 @@ public class BuildEventStreamer implements EventHandler { } if (event instanceof EventReportingArtifacts) { - for (NestedSet<Artifact> artifactSet : - ((EventReportingArtifacts) event).reportedArtifacts()) { - maybeReportArtifactSet(artifactSet); + ReportedArtifacts reportedArtifacts = ((EventReportingArtifacts) event).reportedArtifacts(); + for (NestedSet<Artifact> artifactSet : reportedArtifacts.artifacts) { + maybeReportArtifactSet(reportedArtifacts.pathResolver, artifactSet); } } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/NamedArtifactGroup.java b/src/main/java/com/google/devtools/build/lib/runtime/NamedArtifactGroup.java index 8624658c7d..9bf0f23dd2 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/NamedArtifactGroup.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/NamedArtifactGroup.java @@ -17,6 +17,7 @@ package com.google.devtools.build.lib.runtime; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.actions.ArtifactPathResolver; import com.google.devtools.build.lib.actions.EventReportingArtifacts; import com.google.devtools.build.lib.buildeventstream.ArtifactGroupNamer; import com.google.devtools.build.lib.buildeventstream.BuildEvent; @@ -36,10 +37,12 @@ import java.util.Collection; */ class NamedArtifactGroup implements BuildEvent { private final String name; + private final ArtifactPathResolver pathResolver; private final NestedSetView<Artifact> view; - NamedArtifactGroup(String name, NestedSetView<Artifact> view) { + NamedArtifactGroup(String name, ArtifactPathResolver pathResolver, NestedSetView<Artifact> view) { this.name = name; + this.pathResolver = pathResolver; this.view = view; } @@ -63,7 +66,7 @@ class NamedArtifactGroup implements BuildEvent { } artifacts.add( new LocalFile( - artifact.getPath(), + pathResolver.toPath(artifact), artifact.isSourceArtifact() ? LocalFileType.SOURCE : LocalFileType.OUTPUT)); } return artifacts.build(); @@ -82,7 +85,7 @@ class NamedArtifactGroup implements BuildEvent { continue; } String name = artifact.getRootRelativePathString(); - String uri = pathConverter.apply(artifact.getPath()); + String uri = pathConverter.apply(pathResolver.toPath(artifact)); if (uri != null) { builder.addFiles(BuildEventStreamProtos.File.newBuilder().setName(name).setUri(uri)); } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java index 0f07d7ee79..5d1fa1c7a9 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/CompletionFunction.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.skyframe; import com.google.devtools.build.lib.actions.ActionExecutionException; import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.actions.ArtifactPathResolver; import com.google.devtools.build.lib.actions.ArtifactSkyKey; import com.google.devtools.build.lib.actions.MissingInputFileException; import com.google.devtools.build.lib.analysis.AspectCompleteEvent; @@ -91,6 +92,7 @@ public final class CompletionFunction<TValue extends SkyValue, TResult extends S ExtendedEventHandler.Postable createSucceeded( SkyKey skyKey, TValue value, + ArtifactPathResolver pathResolver, TopLevelArtifactContext topLevelArtifactContext, Environment env) throws InterruptedException; @@ -184,6 +186,7 @@ public final class CompletionFunction<TValue extends SkyValue, TResult extends S public ExtendedEventHandler.Postable createSucceeded( SkyKey skyKey, ConfiguredTargetValue value, + ArtifactPathResolver pathResolver, TopLevelArtifactContext topLevelArtifactContext, Environment env) throws InterruptedException { @@ -197,10 +200,10 @@ public final class CompletionFunction<TValue extends SkyValue, TResult extends S TopLevelArtifactHelper.getAllArtifactsToBuild(target, topLevelArtifactContext); if (((TargetCompletionKey) skyKey.argument()).willTest()) { return TargetCompleteEvent.successfulBuildSchedulingTest( - configuredTargetAndData, artifactsToBuild.getAllArtifactsByOutputGroup()); + configuredTargetAndData, pathResolver, artifactsToBuild.getAllArtifactsByOutputGroup()); } else { return TargetCompleteEvent.successfulBuild( - configuredTargetAndData, artifactsToBuild.getAllArtifactsByOutputGroup()); + configuredTargetAndData, pathResolver, artifactsToBuild.getAllArtifactsByOutputGroup()); } } } @@ -269,11 +272,12 @@ public final class CompletionFunction<TValue extends SkyValue, TResult extends S public ExtendedEventHandler.Postable createSucceeded( SkyKey skyKey, AspectValue value, + ArtifactPathResolver pathResolver, TopLevelArtifactContext topLevelArtifactContext, Environment env) { ArtifactsToBuild artifacts = TopLevelArtifactHelper.getAllArtifactsToBuild(value, topLevelArtifactContext); - return AspectCompleteEvent.createSuccessful(value, artifacts); + return AspectCompleteEvent.createSuccessful(value, pathResolver, artifacts); } } @@ -362,7 +366,8 @@ public final class CompletionFunction<TValue extends SkyValue, TResult extends S return null; } ExtendedEventHandler.Postable postable = - completor.createSucceeded(skyKey, value, topLevelContext, env); + completor.createSucceeded( + skyKey, value, ArtifactPathResolver.IDENTITY, topLevelContext, env); if (postable == null) { return null; } diff --git a/src/test/java/com/google/devtools/build/lib/analysis/TargetCompleteEventTest.java b/src/test/java/com/google/devtools/build/lib/analysis/TargetCompleteEventTest.java index 4d164143d2..ea48bb3524 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/TargetCompleteEventTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/TargetCompleteEventTest.java @@ -17,6 +17,7 @@ package com.google.devtools.build.lib.analysis; import static com.google.common.truth.Truth.assertThat; import com.google.common.collect.Iterables; +import com.google.devtools.build.lib.actions.ArtifactPathResolver; import com.google.devtools.build.lib.analysis.TopLevelArtifactHelper.ArtifactsToBuild; import com.google.devtools.build.lib.analysis.util.AnalysisTestCase; import com.google.devtools.build.lib.buildeventstream.BuildEvent; @@ -47,7 +48,9 @@ public class TargetCompleteEventTest extends AnalysisTestCase { TopLevelArtifactHelper.getAllArtifactsToBuild(ct, context); TargetCompleteEvent event = TargetCompleteEvent.successfulBuild( - ctAndData, artifactsToBuild.getAllArtifactsByOutputGroup()); + ctAndData, + ArtifactPathResolver.IDENTITY, + artifactsToBuild.getAllArtifactsByOutputGroup()); assertThat(event.referencedLocalFiles()) .contains( new BuildEvent.LocalFile( diff --git a/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java b/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java index 7d7bbc424a..53d4a74d9c 100644 --- a/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java +++ b/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java @@ -30,6 +30,7 @@ import com.google.devtools.build.lib.actions.ActionExecutedEvent; import com.google.devtools.build.lib.actions.ActionExecutedEvent.ErrorTiming; import com.google.devtools.build.lib.actions.ActionExecutionException; import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.actions.ArtifactPathResolver; import com.google.devtools.build.lib.actions.ArtifactRoot; import com.google.devtools.build.lib.actions.EventReportingArtifacts; import com.google.devtools.build.lib.actions.util.ActionsTestUtil; @@ -213,8 +214,8 @@ public class BuildEventStreamerTest extends FoundationTestCase { } @Override - public Collection<NestedSet<Artifact>> reportedArtifacts() { - return artifacts; + public ReportedArtifacts reportedArtifacts() { + return new ReportedArtifacts(artifacts, ArtifactPathResolver.IDENTITY); } @Override |