Skip to content

Commit

Permalink
Also generate a build stream for fetch
Browse files Browse the repository at this point in the history
Bazel's fetch command is also related to building. So generate
a build-event stream for this as well. As a first step, generate
a minimal stream with only the console output by white listing
the command, setting the separateFinishedEvent flag on the
NoBuildEvent, and generating a NoBuildRequestFinishedEvent.

Change-Id: Iee0c4e84ee5a060565ac86692a2b1917691a84ab
PiperOrigin-RevId: 161782448
  • Loading branch information
aehlig authored and laszlocsomor committed Jul 14, 2017
1 parent 567419d commit 63f01a6
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ java_library(
":packages-internal",
":runtime",
":util",
"//src/main/java/com/google/devtools/build/lib:build-base",
"//src/main/java/com/google/devtools/build/lib/query2",
"//src/main/java/com/google/devtools/build/lib/query2:query-engine",
"//src/main/java/com/google/devtools/common/options",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.devtools.build.lib.analysis.NoBuildEvent;
import com.google.devtools.build.lib.analysis.NoBuildRequestFinishedEvent;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.pkgcache.PackageCacheOptions;
Expand Down Expand Up @@ -109,6 +111,7 @@ public ExitCode exec(CommandEnvironment env, OptionsProvider options) {
return ExitCode.COMMAND_LINE_ERROR;
}

env.getReporter().post(new NoBuildEvent(env.getCommandName(), env.getCommandStartTime(), true));
// 2. Evaluate expression:
try {
queryEnv.evaluateQuery(expr, new ThreadSafeOutputFormatterCallback<Target>() {
Expand All @@ -118,10 +121,18 @@ public void processOutput(Iterable<Target> partialResult) {
}
});
} catch (InterruptedException e) {
env.getReporter()
.post(
new NoBuildRequestFinishedEvent(
ExitCode.COMMAND_LINE_ERROR, env.getRuntime().getClock().currentTimeMillis()));
return ExitCode.COMMAND_LINE_ERROR;
} catch (QueryException e) {
// Keep consistent with reportBuildFileError()
env.getReporter().handle(Event.error(e.getMessage()));
env.getReporter()
.post(
new NoBuildRequestFinishedEvent(
ExitCode.COMMAND_LINE_ERROR, env.getRuntime().getClock().currentTimeMillis()));
return ExitCode.COMMAND_LINE_ERROR;
} catch (IOException e) {
// Should be impossible since our OutputFormatterCallback doesn't throw IOException.
Expand All @@ -130,6 +141,10 @@ public void processOutput(Iterable<Target> partialResult) {

env.getReporter().handle(
Event.progress("All external dependencies fetched successfully."));
env.getReporter()
.post(
new NoBuildRequestFinishedEvent(
ExitCode.SUCCESS, env.getRuntime().getClock().currentTimeMillis()));
return ExitCode.SUCCESS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ protected BuildEventServiceClient createBesClient(BuildEventServiceOptions besOp

@Override
protected Set<String> whitelistedCommands() {
return ImmutableSet.of("build", "test", "run", "query", "coverage", "mobile-install");
return ImmutableSet.of("fetch", "build", "test", "run", "query", "coverage", "mobile-install");
}
}
7 changes: 7 additions & 0 deletions src/test/shell/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ sh_test(
data = [":test-deps"],
)

sh_test(
name = "bazel_build_event_stream_test",
size = "medium",
srcs = ["bazel_build_event_stream_test.sh"],
data = [":test-deps"],
)

sh_test(
name = "bazel_rules_test",
size = "large",
Expand Down
50 changes: 50 additions & 0 deletions src/test/shell/bazel/bazel_build_event_stream_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
#
# Copyright 2016 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.
#
# An end-to-end test for bazel-specific parts of the build-event stream.

# Load the test setup defined in the parent directory
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${CURRENT_DIR}/../integration_test_setup.sh" \
|| { echo "integration_test_setup.sh not found!" >&2; exit 1; }

#### SETUP #############################################################

set -e

function set_up() {
mkdir -p pkg
touch pkg/BUILD
}

#### TESTS #############################################################


function test_fetch_test() {
# We expect the "fetch" command to generate at least a minimally useful
# build-event stream.
bazel shutdown
rm -f "${TEST_log}"
bazel fetch --build_event_text_file="${TEST_log}" //pkg/... \
|| fail "bazel fetch failed"
[ -f "${TEST_log}" ] \
|| fail "fetch did not generate requested build-event file"
expect_log '^started'
expect_log '^finished'
expect_log 'name: "SUCCESS"'
}

run_suite "Bazel-specific integration tests for the build-event stream"

0 comments on commit 63f01a6

Please sign in to comment.