diff options
author | 2017-09-01 10:33:22 +0200 | |
---|---|---|
committer | 2017-09-01 12:29:18 +0200 | |
commit | c27b4dac3daf36577b2d7944b730dbe346e130dc (patch) | |
tree | 484d98fa21ab798f445186ddada3d515bcff3db6 /src/main/java/com/google/devtools | |
parent | afed47daac8812154196403a30f89aaf0ccca2b2 (diff) |
BEP: Add TargetConfigured events also for aspects
Adding an event about which completed aspects to expect allows for earlier
feedback of what the aspect is doing. It also allows consumers of the build
event stream to prepare for the TargetCompleted events of the aspect.
Change-Id: I29ef15472867a7169222e0394c7fe061fd1d2994
PiperOrigin-RevId: 167248206
Diffstat (limited to 'src/main/java/com/google/devtools')
4 files changed, 105 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/AspectConfiguredEvent.java b/src/main/java/com/google/devtools/build/lib/analysis/AspectConfiguredEvent.java new file mode 100644 index 0000000000..19e0b58f01 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/analysis/AspectConfiguredEvent.java @@ -0,0 +1,79 @@ +// Copyright 2017 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.analysis; + +import com.google.common.collect.ImmutableList; +import com.google.devtools.build.lib.analysis.config.BuildConfiguration; +import com.google.devtools.build.lib.buildeventstream.BuildEvent; +import com.google.devtools.build.lib.buildeventstream.BuildEventConverters; +import com.google.devtools.build.lib.buildeventstream.BuildEventId; +import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos; +import com.google.devtools.build.lib.buildeventstream.BuildEventWithConfiguration; +import com.google.devtools.build.lib.buildeventstream.GenericBuildEvent; +import com.google.devtools.build.lib.buildeventstream.NullConfiguration; +import com.google.devtools.build.lib.cmdline.Label; +import java.util.Collection; + +/** Event reporting about the configurations associated with a given apect for a target */ +public class AspectConfiguredEvent implements BuildEventWithConfiguration { + private final Label target; + private final String aspect; + private final Collection<BuildConfiguration> configurations; + + AspectConfiguredEvent( + Label target, String aspect, Collection<BuildConfiguration> configurations) { + this.configurations = configurations; + this.target = target; + this.aspect = aspect; + } + + @Override + public Collection<BuildEvent> getConfigurations() { + ImmutableList.Builder<BuildEvent> builder = new ImmutableList.Builder<>(); + for (BuildConfiguration config : configurations) { + if (config != null) { + builder.add(config); + } else { + builder.add(new NullConfiguration()); + } + } + return builder.build(); + } + + @Override + public BuildEventId getEventId() { + return BuildEventId.aspectConfigured(target, aspect); + } + + @Override + public Collection<BuildEventId> getChildrenEvents() { + ImmutableList.Builder childrenBuilder = ImmutableList.builder(); + for (BuildConfiguration config : configurations) { + if (config != null) { + childrenBuilder.add(BuildEventId.targetCompleted(target, config.getEventId())); + } else { + childrenBuilder.add( + BuildEventId.targetCompleted(target, BuildEventId.nullConfigurationId())); + } + } + return childrenBuilder.build(); + } + + @Override + public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventConverters converters) { + BuildEventStreamProtos.TargetConfigured.Builder builder = + BuildEventStreamProtos.TargetConfigured.newBuilder(); + return GenericBuildEvent.protoChaining(this).setConfigured(builder.build()).build(); + } +} 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 cb4f086fcd..0ef3f8565e 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 @@ -91,6 +91,7 @@ import com.google.devtools.build.lib.syntax.SkylarkImport; import com.google.devtools.build.lib.syntax.SkylarkImports; import com.google.devtools.build.lib.syntax.SkylarkImports.SkylarkImportSyntaxException; import com.google.devtools.build.lib.util.OrderedSetMultimap; +import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.util.Preconditions; import com.google.devtools.build.lib.util.RegexFilter; import com.google.devtools.build.lib.vfs.Path; @@ -519,6 +520,8 @@ public class BuildView { } }); + Multimap<Pair<Label, String>, BuildConfiguration> aspectConfigurations = + ArrayListMultimap.create(); List<AspectValueKey> aspectKeys = new ArrayList<>(); for (String aspect : aspects) { @@ -547,6 +550,8 @@ public class BuildView { String skylarkFunctionName = aspect.substring(delimiterPosition + 1); for (TargetAndConfiguration targetSpec : topLevelTargetsWithConfigs) { + aspectConfigurations.put( + Pair.of(targetSpec.getLabel(), aspect), targetSpec.getConfiguration()); aspectKeys.add( AspectValue.createSkylarkAspectKey( targetSpec.getLabel(), @@ -566,6 +571,7 @@ public class BuildView { // For invoking top-level aspects, use the top-level configuration for both the // aspect and the base target while the top-level configuration is untrimmed. BuildConfiguration configuration = targetSpec.getConfiguration(); + aspectConfigurations.put(Pair.of(targetSpec.getLabel(), aspect), configuration); aspectKeys.add( AspectValue.createAspectKey( targetSpec.getLabel(), @@ -580,6 +586,12 @@ public class BuildView { } } + for (Pair<Label, String> target : aspectConfigurations.keys()) { + eventBus.post( + new AspectConfiguredEvent( + target.getFirst(), target.getSecond(), aspectConfigurations.get(target))); + } + skyframeExecutor.injectWorkspaceStatusData(loadingResult.getWorkspaceName()); SkyframeAnalysisResult skyframeAnalysisResult; try { diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java index 2acc069c7c..1e73efc3db 100644 --- a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java +++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventId.java @@ -160,6 +160,16 @@ public final class BuildEventId implements Serializable { BuildEventStreamProtos.BuildEventId.newBuilder().setTargetConfigured(configuredId).build()); } + public static BuildEventId aspectConfigured(Label label, String aspect) { + BuildEventStreamProtos.BuildEventId.TargetConfiguredId configuredId = + BuildEventStreamProtos.BuildEventId.TargetConfiguredId.newBuilder() + .setLabel(label.toString()) + .setAspect(aspect) + .build(); + return new BuildEventId( + BuildEventStreamProtos.BuildEventId.newBuilder().setTargetConfigured(configuredId).build()); + } + public static BuildEventId targetCompleted(Label target, BuildEventId configuration) { BuildEventStreamProtos.BuildEventId.ConfigurationId configId = configuration.protoid.getConfiguration(); diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto b/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto index a9c61f105c..0fa0b4a15c 100644 --- a/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto +++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto @@ -86,6 +86,10 @@ message BuildEventId { // identifying for which configurations it should be build. message TargetConfiguredId { string label = 1; + + // If not empty, the id refers to the expansion of the target for a given + // aspect. + string aspect = 2; } // Identifier of an event introducing a named set of files (usually artifacts) |