diff options
author | ccalvarin <ccalvarin@google.com> | 2017-04-06 21:12:11 +0000 |
---|---|---|
committer | Marcel Hlopko <hlopko@google.com> | 2017-04-07 11:17:40 +0200 |
commit | 0ddda7899d8be0420130f5b963510434e35b7197 (patch) | |
tree | 0fa9f4e860ed982db2900851f5d0049a015b87a1 /src/main/java/com/google/devtools/build/lib/server | |
parent | ee4c2525f58253813290e3d00d6d4c58167c51cc (diff) |
Move InvocationPolicy from a startup argument to part of the RunRequest proto.
The user interface is not changing. The policy will still be accepted as a flag passed to the client, as a startup flag (before the command), it will just no longer trigger server restarts and will not be passed on to a bazel server as part of the startup arguments. In batch mode, however, it will still be a startup argument, because the RunRequest proto is not sent, and all invocations restart bazel in batch mode anyway.
Since invocation policy only affects command arguments, and changes in command arguments do not cause server restarts, this is consistent with other server restart behavior.
RELNOTES: Changing --invocation_policy will no longer force a server restart.
PiperOrigin-RevId: 152426207
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/server')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java | 25 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/server/ServerCommand.java | 10 |
2 files changed, 25 insertions, 10 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java b/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java index 19e038f552..676337e8c6 100644 --- a/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java +++ b/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java @@ -22,8 +22,10 @@ import com.google.common.net.InetAddresses; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.common.util.concurrent.Uninterruptibles; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; +import com.google.devtools.build.lib.flags.InvocationPolicyParser; import com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.LockingMode; import com.google.devtools.build.lib.runtime.CommandExecutor; +import com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy; import com.google.devtools.build.lib.server.CommandProtos.CancelRequest; import com.google.devtools.build.lib.server.CommandProtos.CancelResponse; import com.google.devtools.build.lib.server.CommandProtos.PingRequest; @@ -38,6 +40,7 @@ import com.google.devtools.build.lib.util.ThreadUtils; import com.google.devtools.build.lib.util.io.OutErr; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; +import com.google.devtools.common.options.OptionsParsingException; import com.google.protobuf.ByteString; import io.grpc.Server; import io.grpc.StatusRuntimeException; @@ -840,14 +843,20 @@ public class GrpcServerImpl implements RPCServer { new RpcOutputStream(command.id, responseCookie, StreamType.STDOUT, sink), new RpcOutputStream(command.id, responseCookie, StreamType.STDERR, sink)); - exitCode = - commandExecutor.exec( - args.build(), - rpcOutErr, - request.getBlockForLock() ? LockingMode.WAIT : LockingMode.ERROR_OUT, - request.getClientDescription(), - clock.currentTimeMillis()); - + try { + InvocationPolicy policy = InvocationPolicyParser.parsePolicy(request.getInvocationPolicy()); + exitCode = + commandExecutor.exec( + policy, + args.build(), + rpcOutErr, + request.getBlockForLock() ? LockingMode.WAIT : LockingMode.ERROR_OUT, + request.getClientDescription(), + clock.currentTimeMillis()); + } catch (OptionsParsingException e) { + rpcOutErr.printErrLn(e.getMessage()); + exitCode = ExitCode.COMMAND_LINE_ERROR.getNumericExitCode(); + } } catch (InterruptedException e) { exitCode = ExitCode.INTERRUPTED.getNumericExitCode(); commandId = ""; // The default value, the client will ignore it diff --git a/src/main/java/com/google/devtools/build/lib/server/ServerCommand.java b/src/main/java/com/google/devtools/build/lib/server/ServerCommand.java index 7b0a075f75..ef5f727bdb 100644 --- a/src/main/java/com/google/devtools/build/lib/server/ServerCommand.java +++ b/src/main/java/com/google/devtools/build/lib/server/ServerCommand.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.server; import com.google.devtools.build.lib.runtime.BlazeCommandDispatcher; +import com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy; import com.google.devtools.build.lib.util.io.OutErr; import java.util.List; @@ -27,8 +28,13 @@ public interface ServerCommand { * Executes the request, writing any output or error messages into err. * Returns 0 on success; any other value or exception indicates an error. */ - int exec(List<String> args, OutErr outErr, BlazeCommandDispatcher.LockingMode lockingMode, - String clientDescription, long firstContactTime) throws InterruptedException; + int exec( + InvocationPolicy policy, + List<String> args, + OutErr outErr, + BlazeCommandDispatcher.LockingMode lockingMode, + String clientDescription, + long firstContactTime) throws InterruptedException; /** * Whether the server needs to be shut down. |