Skip to content

Commit 21d2533

Browse files
authored
AddgRPC interface to collect every sketch file (#926)
* Add gRPC interface to collect every sketch file * Rename SketchLoad to LoadSketch and fix some gRPC messages
1 parent 3c16c05 commit 21d2533

17 files changed

+544
-200
lines changed

Diff for: client_example/go.sum

+48
Large diffs are not rendered by default.

Diff for: client_example/main.go

+18
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ func main() {
7070
log.Println("calling Version")
7171
callVersion(client)
7272

73+
log.Println("calling LoadSketch")
74+
callLoadSketch(client)
75+
7376
// Use SetValue to configure the arduino-cli directories.
7477
log.Println("calling SetValue")
7578
callSetValue(settingsClient)
@@ -878,3 +881,18 @@ func waitForPrompt(debugStreamingOpenClient dbg.Debug_DebugClient, prompt string
878881
}
879882
}
880883
}
884+
885+
func callLoadSketch(client rpc.ArduinoCoreClient) {
886+
currDir, _ := os.Getwd()
887+
sketch, err := client.LoadSketch(context.Background(), &rpc.LoadSketchReq{
888+
SketchPath: filepath.Join(currDir, "hello"),
889+
})
890+
if err != nil {
891+
log.Fatalf("Error getting version: %s", err)
892+
}
893+
894+
log.Printf("Sketch main file: %s", sketch.GetMainFile())
895+
log.Printf("Sketch location: %s", sketch.GetLocationPath())
896+
log.Printf("Other sketch files: %v", sketch.GetOtherSketchFiles())
897+
log.Printf("Sketch additional files: %v", sketch.GetAdditionalFiles())
898+
}

Diff for: commands/daemon/daemon.go

+5
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ func (s *ArduinoCoreServerImpl) Version(ctx context.Context, req *rpc.VersionReq
154154
return &rpc.VersionResp{Version: s.VersionString}, nil
155155
}
156156

157+
// LoadSketch FIXMEDOC
158+
func (s *ArduinoCoreServerImpl) LoadSketch(ctx context.Context, req *rpc.LoadSketchReq) (*rpc.LoadSketchResp, error) {
159+
return commands.LoadSketch(ctx, req)
160+
}
161+
157162
// Compile FIXMEDOC
158163
func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileReq, stream rpc.ArduinoCore_CompileServer) error {
159164
resp, err := compile.Compile(

Diff for: commands/instances.go

+26
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"net/url"
2424
"path"
2525

26+
"github.com/arduino/arduino-cli/arduino/builder"
2627
"github.com/arduino/arduino-cli/arduino/cores"
2728
"github.com/arduino/arduino-cli/arduino/cores/packageindex"
2829
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
@@ -676,3 +677,28 @@ func createInstance(ctx context.Context, getLibOnly bool) (*createInstanceResult
676677

677678
return res, nil
678679
}
680+
681+
// LoadSketch collects and returns all files composing a sketch
682+
func LoadSketch(ctx context.Context, req *rpc.LoadSketchReq) (*rpc.LoadSketchResp, error) {
683+
sketch, err := builder.SketchLoad(req.SketchPath, "")
684+
if err != nil {
685+
return nil, fmt.Errorf("Error loading sketch %v: %v", req.SketchPath, err)
686+
}
687+
688+
otherSketchFiles := make([]string, len(sketch.OtherSketchFiles))
689+
for i, file := range sketch.OtherSketchFiles {
690+
otherSketchFiles[i] = file.Path
691+
}
692+
693+
additionalFiles := make([]string, len(sketch.AdditionalFiles))
694+
for i, file := range sketch.AdditionalFiles {
695+
additionalFiles[i] = file.Path
696+
}
697+
698+
return &rpc.LoadSketchResp{
699+
MainFile: sketch.MainFile.Path,
700+
LocationPath: sketch.LocationPath,
701+
OtherSketchFiles: otherSketchFiles,
702+
AdditionalFiles: additionalFiles,
703+
}, nil
704+
}

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
github.com/fluxio/iohelpers v0.0.0-20160419043813-3a4dd67a94d2 // indirect
2121
github.com/fluxio/multierror v0.0.0-20160419044231-9c68d39025e5 // indirect
2222
github.com/gofrs/uuid v3.2.0+incompatible
23-
github.com/golang/protobuf v1.4.1
23+
github.com/golang/protobuf v1.4.2
2424
github.com/h2non/filetype v1.0.8 // indirect
2525
github.com/imjasonmiller/godice v0.1.2
2626
github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8 // indirect

Diff for: go.sum

+3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W
8585
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
8686
github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0=
8787
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
88+
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
89+
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
8890
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
8991
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
9092
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
@@ -320,6 +322,7 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ
320322
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
321323
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
322324
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
325+
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
323326
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
324327
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
325328
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=

Diff for: rpc/commands/board.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)