Skip to content

Structural search: Allow callers to access comby's stdin and stdout pipes

Warren Gifford requested to merge tl/enable-comby-streaming into main

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 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. There are now two separate entry points for interacting with the comby package:

  1. Calling one of Matches(), Replacements(), or Outputs() with a comby.Args. The comby package will take care of the rest -- writing to stdin (if applicable), reading from stdout, processing that output, and returning results to the caller.
  2. Calling SetupCmdWithPipes() to get handles to the command, its stdin, and its stdout. By doing so the caller is now responsible for handling writing to stdin, reading from stdout, and processing the output from stdout. The caller must also call StartAndWaitForCompletion() 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().

Merge request reports

Loading