Skip to content

Commit c591d4d

Browse files
committed
Fully redirecting stdout/err from Compile command
1 parent f895ae5 commit c591d4d

File tree

10 files changed

+107
-66
lines changed

10 files changed

+107
-66
lines changed

Gopkg.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/compile/compile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func run(cmd *cobra.Command, args []string) {
111111
Quiet: flags.quiet,
112112
VidPid: flags.vidPid,
113113
ExportFile: flags.exportFile,
114-
}, os.Stdout, output.NewTaskProgressCB(), output.DownloadProgressBar())
114+
}, os.Stdout, os.Stderr, output.NewTaskProgressCB(), output.DownloadProgressBar())
115115
if err == nil {
116116
outputCompileResp(compRes)
117117
} else {

commands/compile/compile.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
)
2525

2626
func Compile(ctx context.Context, req *rpc.CompileReq,
27-
outStream io.Writer,
27+
outStream io.Writer, errStream io.Writer,
2828
taskCB commands.TaskProgressCB, downloadCB commands.DownloadProgressCB) (*rpc.CompileResp, error) {
2929

3030
pm := commands.GetPackageManager(req)
@@ -158,7 +158,9 @@ func Compile(ctx context.Context, req *rpc.CompileReq,
158158
builderCtx.BuiltInLibrariesDirs = paths.NewPathList(ideLibrariesPath)
159159
}
160160

161-
builderCtx.SetLogger(i18n.LoggerToIoWriter{Writer: outStream})
161+
builderCtx.ExecStdout = outStream
162+
builderCtx.ExecStderr = errStream
163+
builderCtx.SetLogger(i18n.LoggerToCustomStreams{Stdout: outStream, Stderr: errStream})
162164
if req.GetShowProperties() {
163165
err = builder.RunParseHardwareAndDumpBuildProperties(builderCtx)
164166
} else if req.GetPreprocess() {

daemon/client/client.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,11 @@ func main() {
124124
fmt.Printf("Compile error: %s\n", err)
125125
os.Exit(1)
126126
}
127-
if compResp.GetOutput() != nil {
128-
fmt.Printf("%s", compResp.GetOutput())
127+
if resp := compResp.GetOutStream(); resp != nil {
128+
fmt.Printf(">> STDOUT: %s", resp)
129+
}
130+
if resperr := compResp.GetErrStream(); resperr != nil {
131+
fmt.Printf(">> STDERR: %s", resperr)
129132
}
130133
if compResp.GetDownloadProgress() != nil {
131134
fmt.Printf(">> DOWNLOAD: %s\n", compResp.GetDownloadProgress())
@@ -156,10 +159,10 @@ func main() {
156159
os.Exit(1)
157160
}
158161
if resp := uplResp.GetOutStream(); resp != nil {
159-
fmt.Printf("output %s", resp)
162+
fmt.Printf(">> STDOUT: %s", resp)
160163
}
161164
if resperr := uplResp.GetErrStream(); resperr != nil {
162-
fmt.Printf("error %s", resperr)
165+
fmt.Printf(">> STDERR: %s", resperr)
163166
}
164167
}
165168

daemon/daemon.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ func (s *ArduinoCoreServerImpl) Init(ctx context.Context, req *rpc.InitReq) (*rp
5959
func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileReq, stream rpc.ArduinoCore_CompileServer) error {
6060
resp, err := compile.Compile(
6161
stream.Context(), req,
62-
feedStream(func(data []byte) { stream.Send(&rpc.CompileResp{Output: data}) }),
62+
feedStream(func(data []byte) { stream.Send(&rpc.CompileResp{OutStream: data}) }),
63+
feedStream(func(data []byte) { stream.Send(&rpc.CompileResp{ErrStream: data}) }),
6364
func(p *rpc.TaskProgress) { stream.Send(&rpc.CompileResp{TaskProgress: p}) },
6465
func(p *rpc.DownloadProgress) { stream.Send(&rpc.CompileResp{DownloadProgress: p}) },
6566
)

rpc/compile.pb.go

Lines changed: 45 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/compile.proto

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ message CompileReq {
2323
}
2424

2525
message CompileResp {
26-
bytes output = 1;
27-
DownloadProgress download_progress = 2;
28-
TaskProgress task_progress = 3;
26+
bytes out_stream = 1;
27+
bytes err_stream = 2;
28+
DownloadProgress download_progress = 3;
29+
TaskProgress task_progress = 4;
2930
}

vendor/github.com/arduino/arduino-builder/i18n/i18n.go

Lines changed: 25 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/arduino/arduino-builder/types/context.go

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/arduino/arduino-builder/utils/utils.go

Lines changed: 10 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)