Skip to content

Commit

Permalink
Report unsuccessful error code if bazel fetch fails in "keep going" m…
Browse files Browse the repository at this point in the history
…ode.

Fixes bazelbuild#3234.

Rollforward of commit dafe713 with a bugfix

PiperOrigin-RevId: 182903117
  • Loading branch information
dslomov authored and Copybara-Service committed Jan 23, 2018
1 parent 00036c0 commit fa54bfa
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.devtools.build.lib.pkgcache.PackageCacheOptions;
import com.google.devtools.build.lib.query2.AbstractBlazeQueryEnvironment;
import com.google.devtools.build.lib.query2.engine.QueryEnvironment.Setting;
import com.google.devtools.build.lib.query2.engine.QueryEvalResult;
import com.google.devtools.build.lib.query2.engine.QueryException;
import com.google.devtools.build.lib.query2.engine.QueryExpression;
import com.google.devtools.build.lib.query2.engine.ThreadSafeOutputFormatterCallback;
Expand Down Expand Up @@ -122,13 +123,17 @@ public ExitCode exec(CommandEnvironment env, OptionsProvider options) {
env.getCommandId().toString()));

// 2. Evaluate expression:
QueryEvalResult queryEvalResult = null;
try {
queryEnv.evaluateQuery(expr, new ThreadSafeOutputFormatterCallback<Target>() {
@Override
public void processOutput(Iterable<Target> partialResult) {
// Throw away the result.
}
});
queryEvalResult =
queryEnv.evaluateQuery(
expr,
new ThreadSafeOutputFormatterCallback<Target>() {
@Override
public void processOutput(Iterable<Target> partialResult) {
// Throw away the result.
}
});
} catch (InterruptedException e) {
env.getReporter()
.post(
Expand All @@ -148,12 +153,15 @@ public void processOutput(Iterable<Target> partialResult) {
throw new IllegalStateException(e);
}

env.getReporter().handle(
Event.progress("All external dependencies fetched successfully."));
if (queryEvalResult.getSuccess()) {
env.getReporter().handle(Event.progress("All external dependencies fetched successfully."));
}
ExitCode exitCode =
queryEvalResult.getSuccess() ? ExitCode.SUCCESS : ExitCode.COMMAND_LINE_ERROR;
env.getReporter()
.post(
new NoBuildRequestFinishedEvent(
ExitCode.SUCCESS, env.getRuntime().getClock().currentTimeMillis()));
return ExitCode.SUCCESS;
exitCode, env.getRuntime().getClock().currentTimeMillis()));
return exitCode;
}
}
17 changes: 17 additions & 0 deletions src/test/shell/bazel/external_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1031,4 +1031,21 @@ EOF
bazel build '@ext//:hello' || fail "expected success"
}

function test_failing_fetch_with_keep_going() {
touch WORKSPACE
cat > BUILD <<'EOF'
package(default_visibility = ["//visibility:public"])
cc_binary(
name = "hello-world",
srcs = ["hello-world.cc"],
deps = ["@fake//:fake"],
)
EOF
touch hello-world.cc

bazel fetch --keep_going //... >& $TEST_log && fail "Expected to fail" || true
}


run_suite "external tests"

0 comments on commit fa54bfa

Please sign in to comment.