diff options
author | Klaus Aehlig <aehlig@google.com> | 2017-05-08 08:26:03 -0400 |
---|---|---|
committer | Kristina Chodorow <kchodorow@google.com> | 2017-05-08 09:49:57 -0400 |
commit | 0cce00c45cfe663caa20cd565d505e1bd43024e4 (patch) | |
tree | d55c4e73d08b289d9bcd19437bc02568aa3ab472 /src/main/java/com/google | |
parent | 5aaf52f5d0704b91245517f19f2fe4638b2a6a97 (diff) |
BEP: Provide infrastructure to report configurations
In preparation to support multi-configuration builds, provide infrastructure
allowing build events to reference BuildConfigurations. The streaming mechanism
will ensure that build configurations are introduced in the stream before being
referenced for the first time.
Change-Id: I6b96fbebc76a05eff4f75a07e8a9cfbcd57f9c22
PiperOrigin-RevId: 155368666
Diffstat (limited to 'src/main/java/com/google')
4 files changed, 83 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java index 8514cdd7cd..3ff7f470df 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java @@ -42,6 +42,11 @@ import com.google.devtools.build.lib.analysis.Dependency; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.actions.FileWriteAction; import com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection.Transitions; +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.GenericBuildEvent; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.LabelSyntaxException; import com.google.devtools.build.lib.cmdline.RepositoryName; @@ -119,7 +124,7 @@ import javax.annotation.Nullable; category = SkylarkModuleCategory.BUILTIN, doc = "Data required for the analysis of a target that comes from targets that " + "depend on it and not targets that it depends on.") -public final class BuildConfiguration { +public final class BuildConfiguration implements BuildEvent { /** * An interface for language-specific configurations. * @@ -2713,4 +2718,26 @@ public final class BuildConfiguration { } return currentTransition; } + + @Override + public BuildEventId getEventId() { + return BuildEventId.configurationId(checksum()); + } + + @Override + public Collection<BuildEventId> getChildrenEvents() { + return ImmutableList.of(); + } + + @Override + public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventConverters converters) { + return GenericBuildEvent.protoChaining(this) + .setConfiguration( + BuildEventStreamProtos.Configuration.newBuilder() + .setMnemonic(getMnemonic()) + .setPlatformName(getPlatformName()) + .setCpu(getCpu()) + .build()) + .build(); + } } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildEventWithConfiguration.java b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildEventWithConfiguration.java new file mode 100644 index 0000000000..a4742c0101 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildEventWithConfiguration.java @@ -0,0 +1,27 @@ +// 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.config; + +import com.google.devtools.build.lib.buildeventstream.BuildEvent; +import java.util.Collection; + +/** Interface for {@link BuildEvent}s that reference {@link BuildConfigration}s */ +public interface BuildEventWithConfiguration extends BuildEvent { + /** + * The {@link BuildConfiguration}s the event mentions, and hence should be introduced in the + * stream before this event. + */ + Collection<BuildConfiguration> getConfigurations(); +} 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 0e13b62b29..381358bfd4 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 @@ -107,6 +107,13 @@ public final class BuildEventId implements Serializable { .build()); } + public static BuildEventId configurationId(String id) { + BuildEventStreamProtos.BuildEventId.ConfigurationId configurationId = + BuildEventStreamProtos.BuildEventId.ConfigurationId.newBuilder().setId(id).build(); + return new BuildEventId( + BuildEventStreamProtos.BuildEventId.newBuilder().setConfiguration(configurationId).build()); + } + private static BuildEventId targetPatternExpanded(List<String> targetPattern, boolean skipped) { BuildEventStreamProtos.BuildEventId.PatternExpandedId patternId = BuildEventStreamProtos.BuildEventId.PatternExpandedId.newBuilder() 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 b81341f54e..e55ca36cb3 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 @@ -31,6 +31,8 @@ import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.EventReportingArtifacts; import com.google.devtools.build.lib.analysis.BuildInfoEvent; import com.google.devtools.build.lib.analysis.NoBuildEvent; +import com.google.devtools.build.lib.analysis.config.BuildConfiguration; +import com.google.devtools.build.lib.analysis.config.BuildEventWithConfiguration; import com.google.devtools.build.lib.buildeventstream.AbortedEvent; import com.google.devtools.build.lib.buildeventstream.AnnounceBuildEventTransportsEvent; import com.google.devtools.build.lib.buildeventstream.ArtifactGroupNamer; @@ -79,6 +81,7 @@ public class BuildEventStreamer implements EventHandler { private final Reporter reporter; private Set<BuildEventId> announcedEvents; private final Set<BuildEventId> postedEvents = new HashSet<>(); + private final Set<BuildEventId> configurationsPosted = new HashSet<>(); private final Multimap<BuildEventId, BuildEvent> pendingEvents = HashMultimap.create(); private int progressCount; private final CountingArtifactGroupNamer artifactGroupNamer = new CountingArtifactGroupNamer(); @@ -299,6 +302,17 @@ public class BuildEventStreamer implements EventHandler { maybeReportArtifactSet(new NestedSetView<Artifact>(set)); } + private void maybeReportConfiguration(BuildConfiguration configuration) { + BuildEventId id = configuration.getEventId(); + synchronized (this) { + if (configurationsPosted.contains(id)) { + return; + } + configurationsPosted.add(id); + } + post(configuration); + } + @Override public void handle(Event event) {} @@ -318,6 +332,13 @@ public class BuildEventStreamer implements EventHandler { return; } + if (event instanceof BuildEventWithConfiguration) { + for (BuildConfiguration configuration : + ((BuildEventWithConfiguration) event).getConfigurations()) { + maybeReportConfiguration(configuration); + } + } + if (event instanceof EventReportingArtifacts) { for (NestedSet<Artifact> artifactSet : ((EventReportingArtifacts) event).reportedArtifacts()) { |