diff options
author | Tobias Bosch <tbosch@google.com> | 2019-07-17 03:23:59 -0700 |
---|---|---|
committer | Tobias Bosch <tbosch@google.com> | 2019-07-18 08:23:16 +0000 |
commit | 22c32b40be54a9e4062655f90908f98b11e73966 (patch) | |
tree | c9cba15f22bafea60a69a676936de944df81290f /compiler_wrapper/env.go | |
parent | 0fc0acdd69e58273ba8987cba9afac2304454561 (diff) | |
download | toolchain-utils-22c32b40be54a9e4062655f90908f98b11e73966.tar.gz |
Add json mapping for command and commandResult.
Also exports the fields on these structs so that json
can read/write them.
BUG=chromium:773875
TEST=unit test
Change-Id: I0efead41693dd35548738a0b3a3e5c71c97c319c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1706790
Reviewed-by: George Burgess <gbiv@chromium.org>
Tested-by: Tobias Bosch <tbosch@google.com>
Diffstat (limited to 'compiler_wrapper/env.go')
-rw-r--r-- | compiler_wrapper/env.go | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/compiler_wrapper/env.go b/compiler_wrapper/env.go index 600366c4..2bafaf3d 100644 --- a/compiler_wrapper/env.go +++ b/compiler_wrapper/env.go @@ -70,10 +70,10 @@ type commandRecordingEnv struct { cmdResults []*commandResult } type commandResult struct { - cmd *command - stdout string - stderr string - exitCode int + Cmd *command `json:"cmd"` + Stdout string `json:"stdout,omitempty"` + Stderr string `json:"stderr,omitempty"` + ExitCode int `json:"exitcode,omitempty"` } var _ env = (*commandRecordingEnv)(nil) @@ -90,10 +90,10 @@ func (env *commandRecordingEnv) run(cmd *command, stdout io.Writer, stderr io.Wr err := env.env.run(cmd, io.MultiWriter(stdout, stdoutBuffer), io.MultiWriter(stderr, stderrBuffer)) if exitCode, ok := getExitCode(err); ok { env.cmdResults = append(env.cmdResults, &commandResult{ - cmd: cmd, - stdout: stdoutBuffer.String(), - stderr: stderrBuffer.String(), - exitCode: exitCode, + Cmd: cmd, + Stdout: stdoutBuffer.String(), + Stderr: stderrBuffer.String(), + ExitCode: exitCode, }) } return err @@ -117,12 +117,12 @@ func (env *printingEnv) run(cmd *command, stdout io.Writer, stderr io.Writer) er func printCmd(env env, cmd *command) { fmt.Fprintf(env.stderr(), "cd '%s' &&", env.getwd()) - if len(cmd.envUpdates) > 0 { - fmt.Fprintf(env.stderr(), " env '%s'", strings.Join(cmd.envUpdates, "' '")) + if len(cmd.EnvUpdates) > 0 { + fmt.Fprintf(env.stderr(), " env '%s'", strings.Join(cmd.EnvUpdates, "' '")) } fmt.Fprintf(env.stderr(), " '%s'", getAbsCmdPath(env, cmd)) - if len(cmd.args) > 0 { - fmt.Fprintf(env.stderr(), " '%s'", strings.Join(cmd.args, "' '")) + if len(cmd.Args) > 0 { + fmt.Fprintf(env.stderr(), " '%s'", strings.Join(cmd.Args, "' '")) } io.WriteString(env.stderr(), "\n") } |