Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added gRPC interface to collect every sketch file #926

Merged
merged 2 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions client_example/go.sum

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions client_example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ func main() {
log.Println("calling Version")
callVersion(client)

log.Println("calling LoadSketch")
callLoadSketch(client)

// Use SetValue to configure the arduino-cli directories.
log.Println("calling SetValue")
callSetValue(settingsClient)
Expand Down Expand Up @@ -878,3 +881,18 @@ func waitForPrompt(debugStreamingOpenClient dbg.Debug_DebugClient, prompt string
}
}
}

func callLoadSketch(client rpc.ArduinoCoreClient) {
currDir, _ := os.Getwd()
sketch, err := client.LoadSketch(context.Background(), &rpc.LoadSketchReq{
SketchPath: filepath.Join(currDir, "hello"),
})
if err != nil {
log.Fatalf("Error getting version: %s", err)
}

log.Printf("Sketch main file: %s", sketch.GetMainFile())
log.Printf("Sketch location: %s", sketch.GetLocationPath())
log.Printf("Other sketch files: %v", sketch.GetOtherSketchFiles())
log.Printf("Sketch additional files: %v", sketch.GetAdditionalFiles())
}
5 changes: 5 additions & 0 deletions commands/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ func (s *ArduinoCoreServerImpl) Version(ctx context.Context, req *rpc.VersionReq
return &rpc.VersionResp{Version: s.VersionString}, nil
}

// LoadSketch FIXMEDOC
func (s *ArduinoCoreServerImpl) LoadSketch(ctx context.Context, req *rpc.LoadSketchReq) (*rpc.LoadSketchResp, error) {
return commands.LoadSketch(ctx, req)
}

// Compile FIXMEDOC
func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileReq, stream rpc.ArduinoCore_CompileServer) error {
resp, err := compile.Compile(
Expand Down
26 changes: 26 additions & 0 deletions commands/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net/url"
"path"

"github.com/arduino/arduino-cli/arduino/builder"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/cores/packageindex"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
Expand Down Expand Up @@ -676,3 +677,28 @@ func createInstance(ctx context.Context, getLibOnly bool) (*createInstanceResult

return res, nil
}

// LoadSketch collects and returns all files composing a sketch
func LoadSketch(ctx context.Context, req *rpc.LoadSketchReq) (*rpc.LoadSketchResp, error) {
sketch, err := builder.SketchLoad(req.SketchPath, "")
if err != nil {
return nil, fmt.Errorf("Error loading sketch %v: %v", req.SketchPath, err)
}

otherSketchFiles := make([]string, len(sketch.OtherSketchFiles))
for i, file := range sketch.OtherSketchFiles {
otherSketchFiles[i] = file.Path
}

additionalFiles := make([]string, len(sketch.AdditionalFiles))
for i, file := range sketch.AdditionalFiles {
additionalFiles[i] = file.Path
}

return &rpc.LoadSketchResp{
MainFile: sketch.MainFile.Path,
LocationPath: sketch.LocationPath,
OtherSketchFiles: otherSketchFiles,
AdditionalFiles: additionalFiles,
}, nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/fluxio/iohelpers v0.0.0-20160419043813-3a4dd67a94d2 // indirect
github.com/fluxio/multierror v0.0.0-20160419044231-9c68d39025e5 // indirect
github.com/gofrs/uuid v3.2.0+incompatible
github.com/golang/protobuf v1.4.1
github.com/golang/protobuf v1.4.2
github.com/h2non/filetype v1.0.8 // indirect
github.com/imjasonmiller/godice v0.1.2
github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
Expand Down Expand Up @@ -311,6 +313,7 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
Expand Down
2 changes: 1 addition & 1 deletion rpc/commands/board.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading