Structural search: Allow callers to access comby's stdin and stdout pipes
Created by: tbliu98
The main change in this PR is splitting the comby.PipeTo()
method into two separate methods, SetupCmdWithPipes()
and StartAndWaitForCompletion()
.
SetupCmdWithPipes()
returns an *exec.Cmd
pointing to combyPath
with the provided arguments. It also returns pipes to the command's stdin
and stdout
.
StartAndWaitForCompletion()
does what it sounds like, starts the command and waits for it to run to completion.
The motivation behind this change is to allow callers of the comby
package the ability to access the command's stdin
and stdout
pipes -- specifically, this enables callers to write to stdin
and read from stdout
in a streaming fashion which is needed for implementing streaming structural search (#35964 (closed)).
This does create a new entry point into the
There are now two separate entry points for interacting with the comby
package; it's probably worth revisiting this package in a later PR to see if we can trim some of these entry points and simplify things.comby
package:
- Calling one of
Matches()
,Replacements()
, orOutputs()
with acomby.Args
. Thecomby
package will take care of the rest -- writing tostdin
(if applicable), reading fromstdout
, processing that output, and returning results to the caller. - Calling
SetupCmdWithPipes()
to get handles to the command, itsstdin
, and itsstdout
. By doing so the caller is now responsible for handling writing tostdin
, reading fromstdout
, and processing the output fromstdout
. The caller must also callStartAndWaitForCompletion()
when it's ready to run the command.
Test plan
This shouldn't change behavior so relying on existing tests. Updated tests that called PipeTo()
to instead call SetupCmdWithPipes()
and then StartAndWaitForCompletion()
.