Skip to content
This repository was archived by the owner on Dec 20, 2021. It is now read-only.

Commit 3ba5f72

Browse files
committed
Stream builder output in Compile command
1 parent 034a193 commit 3ba5f72

File tree

9 files changed

+157
-90
lines changed

9 files changed

+157
-90
lines changed

arduino/resources/install.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,8 @@ func findPackageRoot(parent *paths.Path) (*paths.Path, error) {
123123
return nil, fmt.Errorf("no unique root dir in archive, found '%s' and '%s'", root, file)
124124
}
125125
}
126+
if root == nil {
127+
return nil, fmt.Errorf("package does not contains any subfolder")
128+
}
126129
return root, nil
127130
}

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-
})
114+
}, os.Stdout)
115115
if err == nil {
116116
outputCompileResp(compRes)
117117
} else {

commands/compile/compile.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package compile
33
import (
44
"context"
55
"fmt"
6+
"io"
67
"path/filepath"
78
"sort"
89
"strings"
@@ -20,7 +21,7 @@ import (
2021
"github.com/sirupsen/logrus"
2122
)
2223

23-
func Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error) {
24+
func Compile(ctx context.Context, req *rpc.CompileReq, output io.Writer) (*rpc.CompileResp, error) {
2425
logrus.Info("Executing `arduino compile`")
2526
var sketchPath *paths.Path
2627
if req.GetSketchPath() != "" {

daemon/client/client.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"fmt"
6+
"io"
67
"os"
78

89
"github.com/arduino/arduino-cli/rpc"
@@ -44,16 +45,27 @@ func main() {
4445
fmt.Printf("Board name: %s\n", details.GetName())
4546
}
4647

47-
compResp, err := client.Compile(context.Background(), &rpc.CompileReq{
48+
compRespStream, err := client.Compile(context.Background(), &rpc.CompileReq{
4849
Instance: instance,
4950
Fqbn: "arduino:samd:mkr1000",
5051
SketchPath: os.Args[2],
52+
Verbose: true,
5153
})
5254
if err != nil {
5355
fmt.Printf("Compile error: %s\n", err)
5456
os.Exit(1)
5557
}
56-
fmt.Printf("Compile response: %+v\n", compResp)
58+
for {
59+
compResp, err := compRespStream.Recv()
60+
if err == io.EOF {
61+
break
62+
}
63+
if err != nil {
64+
fmt.Printf("Compile error: %s\n", err)
65+
os.Exit(1)
66+
}
67+
fmt.Printf("%s", compResp.GetOutput())
68+
}
5769
/*
5870
compile, err := client.Compile(context.Background(), &pb.CompileReq{})
5971
if err != nil {

daemon/daemon.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package daemon
77
import (
88
"context"
99
"fmt"
10+
"io"
1011
"log"
1112
"net"
1213

@@ -49,6 +50,19 @@ func (s *ArduinoCoreServerImpl) Init(ctx context.Context, req *rpc.InitReq) (*rp
4950
return commands.Init(ctx, req)
5051
}
5152

52-
func (s *ArduinoCoreServerImpl) Compile(ctx context.Context, req *rpc.CompileReq) (*rpc.CompileResp, error) {
53-
return compile.Compile(ctx, req)
53+
func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileReq, stream rpc.ArduinoCore_CompileServer) error {
54+
r, w := io.Pipe()
55+
go func() {
56+
data := make([]byte, 1024)
57+
for {
58+
if n, err := r.Read(data); err != nil {
59+
return
60+
} else {
61+
stream.Send(&rpc.CompileResp{Output: data[:n]})
62+
}
63+
}
64+
}()
65+
resp, err := compile.Compile(stream.Context(), req, w)
66+
stream.Send(resp)
67+
return err
5468
}

rpc/commands.pb.go

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

rpc/commands.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ service ArduinoCore {
2525
// Requests details about a board
2626
rpc BoardDetails(BoardDetailsReq) returns (BoardDetailsResp);
2727

28-
rpc Compile(CompileReq) returns (CompileResp);
28+
rpc Compile(CompileReq) returns (stream CompileResp);
2929
}
3030

3131
// Configuration contains information to instantiate an Arduino Platform Service

0 commit comments

Comments
 (0)