diff options
author | lberki <lberki@google.com> | 2018-02-05 07:59:13 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-02-05 08:01:17 -0800 |
commit | 4741aa83145fd2d3ab0599314f7732c5b80977bd (patch) | |
tree | b33310e226d9733ae0e538e433a54e337d6a67ed /src/main/java/com/google/devtools/build/lib/server | |
parent | 03ad9155f765fcdc0ccf4aae30a4def9914ea0b4 (diff) |
Add a "direct" mode to "blaze run" that makes the process being run a direct
child of the process where the Blaze client itself was run.
Limitations:
- Untested on Windows; it should work because ExecuteProgram() is implemented there, too, but since Windows doesn't support exec(), there is at least one process in between
Progress towards #2815.
RELNOTES[NEW]: The new "--direct_run" flag on "blaze run" lets one run interactive binaries.
PiperOrigin-RevId: 184528845
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 | 32 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/server/ServerCommand.java | 3 |
2 files changed, 21 insertions, 14 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 c412131ead..aa575da2b5 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 @@ -26,6 +26,7 @@ import com.google.devtools.build.lib.clock.BlazeClock; import com.google.devtools.build.lib.clock.Clock; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.LockingMode; +import com.google.devtools.build.lib.runtime.BlazeCommandResult; 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; @@ -814,7 +815,7 @@ public class GrpcServerImpl implements RPCServer { } String commandId; - int exitCode; + BlazeCommandResult result; // TODO(b/63925394): This information needs to be passed to the GotOptionsEvent, which does not // currently have the explicit startup options. See Improved Command Line Reporting design doc @@ -847,7 +848,7 @@ public class GrpcServerImpl implements RPCServer { try { InvocationPolicy policy = InvocationPolicyParser.parsePolicy(request.getInvocationPolicy()); - exitCode = + result = commandExecutor.exec( policy, args.build(), @@ -858,10 +859,10 @@ public class GrpcServerImpl implements RPCServer { Optional.of(startupOptions.build())); } catch (OptionsParsingException e) { rpcOutErr.printErrLn(e.getMessage()); - exitCode = ExitCode.COMMAND_LINE_ERROR.getNumericExitCode(); + result = BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } } catch (InterruptedException e) { - exitCode = ExitCode.INTERRUPTED.getNumericExitCode(); + result = BlazeCommandResult.exitCode(ExitCode.INTERRUPTED); commandId = ""; // The default value, the client will ignore it } @@ -883,17 +884,22 @@ public class GrpcServerImpl implements RPCServer { if (shutdown) { server.shutdown(); } - RunResponse response = - RunResponse.newBuilder() - .setCookie(responseCookie) - .setCommandId(commandId) - .setFinished(true) - .setExitCode(exitCode) - .setTerminationExpected(shutdown) - .build(); + + RunResponse.Builder response = RunResponse.newBuilder() + .setCookie(responseCookie) + .setCommandId(commandId) + .setFinished(true) + .setTerminationExpected(shutdown); + + if (result.getExecRequest() != null) { + response.setExitCode(0); + response.setExecRequest(result.getExecRequest()); + } else { + response.setExitCode(result.getExitCode().getNumericExitCode()); + } try { - observer.onNext(response); + observer.onNext(response.build()); observer.onCompleted(); } catch (StatusRuntimeException e) { // The client cancelled the call. Log an error and go on. 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 f0574cdbaa..aed9d73b98 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.BlazeCommandResult; import com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy; import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.util.io.OutErr; @@ -35,7 +36,7 @@ public interface ServerCommand { * --[no]flag or --flag=value form. If we don't have access to this information (--batch), * leave this parameter as Optional.empty(). */ - int exec( + BlazeCommandResult exec( InvocationPolicy policy, List<String> args, OutErr outErr, |