diff options
author | ulfjack <ulfjack@google.com> | 2017-08-09 15:27:49 +0200 |
---|---|---|
committer | Marcel Hlopko <hlopko@google.com> | 2017-08-10 13:39:00 +0200 |
commit | f2d459502f5fb422d6000db782795cffc6efa3e4 (patch) | |
tree | 35fc4d0cfb5cd22a179107fd90068366ffa85768 /src/main/java/com/google/devtools/build/lib/windows | |
parent | 6b2dce6710ed7d2429e0e3dc113c9bad622b8c4b (diff) |
Rewrite the Command API
Important: the simplified API now defaults to forwarding interrupts to
subprocesses. I did audit all the call sites, and I think this is a safe change
to make.
- Properly support timeouts with all implementations
- Simplify the API
- only provide two flavours of blocking calls, which require no input and
forward interrupts; this is the most common usage
- provide a number of async calls, which optionally takes input, and a flag
whether to forward interrupts
- only support input streams, no byte arrays or other 'convenience features'
that are rarely needed and unnecessarily increase the surface area
- use java.time.Duration to specify timeout; for consistency, interpret a
timeout of <= 0 as no timeout (i.e., including rather than excluding 0)
- KillableObserver and subclasses are no longer part of the public API, but
still used to implement timeouts if the Subprocess.Factory does not support
them
- Update the documentation for Command
- Update all callers; most callers now use the simplified API
PiperOrigin-RevId: 164716782
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/windows')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocess.java | 3 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocessFactory.java | 5 |
2 files changed, 7 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocess.java b/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocess.java index 59d9792696..d99cafe6a7 100644 --- a/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocess.java +++ b/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocess.java @@ -133,7 +133,8 @@ public class WindowsSubprocess implements Subprocess { boolean stderrRedirected, long timeoutMillis) { this.commandLine = commandLine; this.nativeProcess = nativeProcess; - this.timeoutMillis = timeoutMillis; + // As per the spec of Command, we should only apply timeouts that are > 0. + this.timeoutMillis = timeoutMillis <= 0 ? -1 : timeoutMillis; stdoutStream = stdoutRedirected ? null : new ProcessInputStream(WindowsProcesses.getStdout(nativeProcess)); stderrStream = diff --git a/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocessFactory.java b/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocessFactory.java index e398a3b195..d033bacf13 100644 --- a/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocessFactory.java +++ b/src/main/java/com/google/devtools/build/lib/windows/WindowsSubprocessFactory.java @@ -37,6 +37,11 @@ public class WindowsSubprocessFactory implements Subprocess.Factory { } @Override + public boolean supportsTimeout() { + return true; + } + + @Override public Subprocess create(SubprocessBuilder builder) throws IOException { List<String> argv = builder.getArgv(); |