aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
diff options
context:
space:
mode:
authorGravatar ccalvarin <ccalvarin@google.com>2017-08-14 21:09:07 +0200
committerGravatar Irina Iancu <elenairina@google.com>2017-08-16 11:04:41 +0200
commit1cbe62a09b37f2db76e11ebb18fb46616076ef87 (patch)
treef02a66fc345507f3eb3ab3bbe404fdcb161cbabc /src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
parentfc6412ca67a9d98c1b6b0c8b237c119e543bc266 (diff)
Send Bazel startup options to server.
Send the startup options tagged with their origin so that the server has correct information about the command line as the client received it. Removes the unconditional stderr printing of all bazelrc startup options in the bazel client. Instead, the startup options are sent to the server and the same informational printing is gated on the --announce_rc option. This avoids unconditional log spam to stderr early in startup. If the server is unreachable or there are errors parsing startup options, the message is still printed to stderr. Fixes https://github.com/bazelbuild/bazel/issues/2530. RELNOTES: --announce_rc now controls whether bazelrc startup options are printed to stderr. PiperOrigin-RevId: 165211007
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java80
1 files changed, 66 insertions, 14 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
index 453cd7c24b..54803ea944 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
@@ -65,6 +65,7 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
@@ -261,9 +262,9 @@ public class BlazeCommandDispatcher {
}
/**
- * Executes a single command. Returns the Unix exit status for the Blaze
- * client process, or throws {@link ShutdownBlazeServerException} to
- * indicate that a command wants to shutdown the Blaze server.
+ * Executes a single command. Returns the Unix exit status for the Blaze client process, or throws
+ * {@link ShutdownBlazeServerException} to indicate that a command wants to shutdown the Blaze
+ * server.
*/
int exec(
InvocationPolicy invocationPolicy,
@@ -271,7 +272,9 @@ public class BlazeCommandDispatcher {
OutErr outErr,
LockingMode lockingMode,
String clientDescription,
- long firstContactTime) throws ShutdownBlazeServerException, InterruptedException {
+ long firstContactTime,
+ Optional<List<Pair<String, String>>> startupOptionsTaggedWithBazelRc)
+ throws ShutdownBlazeServerException, InterruptedException {
OriginalCommandLineEvent originalCommandLine = new OriginalCommandLineEvent(args);
Preconditions.checkNotNull(clientDescription);
if (args.isEmpty()) { // Default to help command if no arguments specified.
@@ -327,8 +330,16 @@ public class BlazeCommandDispatcher {
outErr.printErrLn("Server shut down " + shutdownReason);
return ExitCode.LOCAL_ENVIRONMENTAL_ERROR.getNumericExitCode();
}
- return execExclusively(originalCommandLine, invocationPolicy, args, outErr, firstContactTime,
- commandName, command, waitTimeInMs);
+ return execExclusively(
+ originalCommandLine,
+ invocationPolicy,
+ args,
+ outErr,
+ firstContactTime,
+ commandName,
+ command,
+ waitTimeInMs,
+ startupOptionsTaggedWithBazelRc);
} catch (ShutdownBlazeServerException e) {
shutdownReason = "explicitly by client " + currentClientDescription;
throw e;
@@ -348,7 +359,8 @@ public class BlazeCommandDispatcher {
long firstContactTime,
String commandName,
BlazeCommand command,
- long waitTimeInMs)
+ long waitTimeInMs,
+ Optional<List<Pair<String, String>>> startupOptionsTaggedWithBazelRc)
throws ShutdownBlazeServerException {
// Record the start time for the profiler. Do not put anything before this!
long execStartTimeNanos = runtime.getClock().nanoTime();
@@ -489,6 +501,39 @@ public class BlazeCommandDispatcher {
}
if (commonOptions.announceRcOptions) {
+ if (startupOptionsTaggedWithBazelRc.isPresent()) {
+ String lastBlazerc = "";
+ List<String> accumulatedStartupOptions = new ArrayList<>();
+ for (Pair<String, String> option : startupOptionsTaggedWithBazelRc.get()) {
+ // Do not include the command line options, marked by the empty string.
+ if (option.getFirst().isEmpty()) {
+ continue;
+ }
+
+ // If we've moved to a new blazerc in the list, print out the info from the last one,
+ // and clear the accumulated list.
+ if (!lastBlazerc.isEmpty() && !option.getFirst().equals(lastBlazerc)) {
+ String logMessage =
+ String.format(
+ "Reading 'startup' options from %s: %s",
+ lastBlazerc, String.join(", ", accumulatedStartupOptions));
+ reporter.handle(Event.info(logMessage));
+ accumulatedStartupOptions = new ArrayList<>();
+ }
+
+ lastBlazerc = option.getFirst();
+ accumulatedStartupOptions.add(option.getSecond());
+ }
+ // Print out the final blazerc-grouped list, if any startup options were provided by
+ // blazerc.
+ if (!lastBlazerc.isEmpty()) {
+ String logMessage =
+ String.format(
+ "Reading 'startup' options from %s: %s",
+ lastBlazerc, String.join(", ", accumulatedStartupOptions));
+ reporter.handle(Event.info(logMessage));
+ }
+ }
for (String note : rcfileNotes) {
reporter.handle(Event.info(note));
}
@@ -546,14 +591,21 @@ public class BlazeCommandDispatcher {
}
/**
- * For testing ONLY. Same as {@link #exec}, but automatically
- * uses the current time.
+ * For testing ONLY. Same as {@link #exec(InvocationPolicy, List, OutErr, LockingMode, String,
+ * long, Optional<List<Pair<String, String>>>)}, but automatically uses the current time.
*/
@VisibleForTesting
- public int exec(List<String> args, LockingMode lockingMode, String clientDescription,
- OutErr originalOutErr) throws ShutdownBlazeServerException, InterruptedException {
- return exec(InvocationPolicy.getDefaultInstance(), args, originalOutErr, LockingMode.ERROR_OUT,
- clientDescription, runtime.getClock().currentTimeMillis());
+ public int exec(
+ List<String> args, LockingMode lockingMode, String clientDescription, OutErr originalOutErr)
+ throws ShutdownBlazeServerException, InterruptedException {
+ return exec(
+ InvocationPolicy.getDefaultInstance(),
+ args,
+ originalOutErr,
+ LockingMode.ERROR_OUT,
+ clientDescription,
+ runtime.getClock().currentTimeMillis(),
+ Optional.empty() /* startupOptionBundles */);
}
/**
@@ -590,7 +642,7 @@ public class BlazeCommandDispatcher {
// handler, and later replayed.
ExitCode earlyExitCode =
checkCwdInWorkspace(workspace, commandAnnotation, commandName, eventHandler);
- if (earlyExitCode != ExitCode.SUCCESS) {
+ if (!earlyExitCode.equals(ExitCode.SUCCESS)) {
return earlyExitCode;
}