diff options
6 files changed, 75 insertions, 5 deletions
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 01a3ddf18d..fc1402573a 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 @@ -116,8 +116,10 @@ public final class TargetCompleteEvent @Override public BuildEventId getEventId() { - return BuildEventId.targetCompleted( - getTarget().getLabel(), getTarget().getConfiguration().getEventId()); + BuildConfiguration config = getTarget().getConfiguration(); + BuildEventId configId = + config == null ? BuildEventId.nullConfigurationId() : config.getEventId(); + return BuildEventId.targetCompleted(getTarget().getLabel(), configId); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/analysis/TargetConfiguredEvent.java b/src/main/java/com/google/devtools/build/lib/analysis/TargetConfiguredEvent.java index 8606afe708..2473991981 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/TargetConfiguredEvent.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/TargetConfiguredEvent.java @@ -47,7 +47,12 @@ public class TargetConfiguredEvent implements BuildEventWithConfiguration { public Collection<BuildEventId> getChildrenEvents() { ImmutableList.Builder childrenBuilder = ImmutableList.builder(); for (BuildConfiguration config : configurations) { - childrenBuilder.add(BuildEventId.targetCompleted(label, config.getEventId())); + if (config != null) { + childrenBuilder.add(BuildEventId.targetCompleted(label, config.getEventId())); + } else { + childrenBuilder.add( + BuildEventId.targetCompleted(label, BuildEventId.nullConfigurationId())); + } } return childrenBuilder.build(); } 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 c34cdf9fb5..3f4fa37ea5 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 @@ -114,6 +114,10 @@ public final class BuildEventId implements Serializable { BuildEventStreamProtos.BuildEventId.newBuilder().setConfiguration(configurationId).build()); } + public static BuildEventId nullConfigurationId() { + return configurationId("none"); + } + 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/buildeventstream/NullConfiguration.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/NullConfiguration.java new file mode 100644 index 0000000000..a95e5a3d72 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/NullConfiguration.java @@ -0,0 +1,42 @@ +// 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.buildeventstream; + +import com.google.common.collect.ImmutableList; +import java.util.Collection; + +/** + * {@link BuildEvent} presenting the configuration in the build event protocol + * that internally is just a null pointer. + */ +public class NullConfiguration implements BuildEvent { + + @Override + public BuildEventId getEventId() { + return BuildEventId.nullConfigurationId(); + } + + @Override + public Collection<BuildEventId> getChildrenEvents() { + return ImmutableList.of(); + } + + @Override + public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventConverters converters) { + return GenericBuildEvent.protoChaining(this) + .setConfiguration(BuildEventStreamProtos.Configuration.getDefaultInstance()) + .build(); + } +} 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 e10444b325..dc14a2b09e 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 @@ -44,6 +44,7 @@ import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.Bui import com.google.devtools.build.lib.buildeventstream.BuildEventTransport; import com.google.devtools.build.lib.buildeventstream.BuildEventTransportClosedEvent; import com.google.devtools.build.lib.buildeventstream.BuildEventWithOrderConstraint; +import com.google.devtools.build.lib.buildeventstream.NullConfiguration; import com.google.devtools.build.lib.buildeventstream.ProgressEvent; import com.google.devtools.build.lib.buildtool.BuildRequest; import com.google.devtools.build.lib.buildtool.buildevent.BuildCompleteEvent; @@ -332,14 +333,18 @@ public class BuildEventStreamer implements EventHandler { } private void maybeReportConfiguration(BuildConfiguration configuration) { - BuildEventId id = configuration.getEventId(); + BuildEvent event = configuration; + if (configuration == null) { + event = new NullConfiguration(); + } + BuildEventId id = event.getEventId(); synchronized (this) { if (configurationsPosted.contains(id)) { return; } configurationsPosted.add(id); } - post(configuration); + post(event); } @Override diff --git a/src/test/shell/integration/build_event_stream_test.sh b/src/test/shell/integration/build_event_stream_test.sh index 647393581e..d30ed62122 100755 --- a/src/test/shell/integration/build_event_stream_test.sh +++ b/src/test/shell/integration/build_event_stream_test.sh @@ -27,6 +27,7 @@ set -e function set_up() { mkdir -p pkg + touch pkg/somesourcefile cat > pkg/true.sh <<EOF #!/bin/sh exit 0 @@ -45,6 +46,7 @@ EOF chmod 755 pkg/slowtest.sh touch pkg/sourcefileA pkg/sourcefileB pkg/sourcefileC cat > pkg/BUILD <<EOF +exports_files(["somesourcefile"]) sh_test( name = "true", srcs = ["true.sh"], @@ -475,4 +477,14 @@ function test_stdout_stderr_reported() { expect_log "stderr.*$sample_line" } +function test_srcfiles() { + # Even if the build target is a source file, the stream should be correctly + # and bazel shouldn't crash. + bazel build --experimental_build_event_text_file=$TEST_log \ + pkg:somesourcefile || fail "build failed" + expect_log 'SUCCESS' + expect_log_once '^configuration' + expect_not_log 'aborted' +} + run_suite "Integration tests for the build event stream" |