Skip to content

Commit

Permalink
[breaking] gRPC API: Removed 'debug' service in favor of 'commands' s…
Browse files Browse the repository at this point in the history
…ervice (#2349)
  • Loading branch information
cmaglie authored Oct 2, 2023
1 parent dc5c56e commit c506f6a
Show file tree
Hide file tree
Showing 17 changed files with 1,316 additions and 1,404 deletions.
2 changes: 0 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,12 @@ tasks:
cmds:
- '{{ default "protoc" .PROTOC_BINARY }} --proto_path=rpc --go_out=./rpc --go_opt=paths=source_relative --go-grpc_out=./rpc --go-grpc_opt=paths=source_relative ./rpc/cc/arduino/cli/commands/v1/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --proto_path=rpc --go_out=./rpc --go_opt=paths=source_relative --go-grpc_out=./rpc --go-grpc_opt=paths=source_relative ./rpc/cc/arduino/cli/settings/v1/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --proto_path=rpc --go_out=./rpc --go_opt=paths=source_relative --go-grpc_out=./rpc --go-grpc_opt=paths=source_relative ./rpc/cc/arduino/cli/debug/v1/*.proto'

protoc:docs:
desc: Generate docs for protobuf definitions
cmds:
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,commands.md --proto_path=rpc ./rpc/cc/arduino/cli/commands/v1/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,settings.md --proto_path=rpc ./rpc/cc/arduino/cli/settings/v1/*.proto'
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,debug.md --proto_path=rpc ./rpc/cc/arduino/cli/debug/v1/*.proto'

docs:include-configuration-json-schema:
desc: Copy configuration JSON schema to make it available in documentation
Expand Down
13 changes: 6 additions & 7 deletions client_example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"time"

rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
dbg "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/debug/v1"
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/settings/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
Expand Down Expand Up @@ -955,11 +954,11 @@ func callLibUninstall(client rpc.ArduinoCoreServiceClient, instance *rpc.Instanc
}
}

func callDebugger(debugStreamingOpenClient dbg.DebugService_DebugClient, instance *rpc.Instance) {
func callDebugger(debugStreamingOpenClient rpc.ArduinoCoreService_DebugClient, instance *rpc.Instance) {
currDir, _ := os.Getwd()
log.Printf("Send debug request")
err := debugStreamingOpenClient.Send(&dbg.DebugRequest{
DebugRequest: &dbg.DebugConfigRequest{
err := debugStreamingOpenClient.Send(&rpc.DebugRequest{
DebugRequest: &rpc.GetDebugConfigRequest{
Instance: &rpc.Instance{Id: instance.GetId()},
Fqbn: "arduino:samd:mkr1000",
SketchPath: filepath.Join(currDir, "hello"),
Expand All @@ -974,7 +973,7 @@ func callDebugger(debugStreamingOpenClient dbg.DebugService_DebugClient, instanc
waitForPrompt(debugStreamingOpenClient, "(gdb)")
// Wait for gdb to init and show the prompt
log.Printf("Send 'info registers' rcommand")
err = debugStreamingOpenClient.Send(&dbg.DebugRequest{Data: []byte("info registers\n")})
err = debugStreamingOpenClient.Send(&rpc.DebugRequest{Data: []byte("info registers\n")})
if err != nil {
log.Fatalf("Send error: %s\n", err)
}
Expand All @@ -984,7 +983,7 @@ func callDebugger(debugStreamingOpenClient dbg.DebugService_DebugClient, instanc

// Send quit command to gdb
log.Printf("Send 'quit' command")
err = debugStreamingOpenClient.Send(&dbg.DebugRequest{Data: []byte("quit\n")})
err = debugStreamingOpenClient.Send(&rpc.DebugRequest{Data: []byte("quit\n")})
if err != nil {
log.Fatalf("Send error: %s\n", err)
}
Expand All @@ -997,7 +996,7 @@ func callDebugger(debugStreamingOpenClient dbg.DebugService_DebugClient, instanc
}
}

func waitForPrompt(debugStreamingOpenClient dbg.DebugService_DebugClient, prompt string) {
func waitForPrompt(debugStreamingOpenClient rpc.ArduinoCoreService_DebugClient, prompt string) {
var buffer bytes.Buffer
for {
compResp, err := debugStreamingOpenClient.Recv()
Expand Down
14 changes: 4 additions & 10 deletions commands/daemon/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,14 @@ import (
"os"

cmd "github.com/arduino/arduino-cli/commands/debug"
dbg "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/debug/v1"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/pkg/errors"
)

// DebugService implements the `Debug` service
type DebugService struct {
dbg.UnimplementedDebugServiceServer
}

// Debug returns a stream response that can be used to fetch data from the
// target. The first message passed through the `Debug` request must
// contain DebugRequest configuration params, not data.
func (s *DebugService) Debug(stream dbg.DebugService_DebugServer) error {

func (s *ArduinoCoreServerImpl) Debug(stream rpc.ArduinoCoreService_DebugServer) error {
// Grab the first message
msg, err := stream.Recv()
if err != nil {
Expand All @@ -49,7 +43,7 @@ func (s *DebugService) Debug(stream dbg.DebugService_DebugServer) error {
// Launch debug recipe attaching stdin and out to grpc streaming
signalChan := make(chan os.Signal)
defer close(signalChan)
outStream := feedStreamTo(func(data []byte) { stream.Send(&dbg.DebugResponse{Data: data}) })
outStream := feedStreamTo(func(data []byte) { stream.Send(&rpc.DebugResponse{Data: data}) })
resp, debugErr := cmd.Debug(stream.Context(), req,
consumeStreamFrom(func() ([]byte, error) {
command, err := stream.Recv()
Expand All @@ -68,6 +62,6 @@ func (s *DebugService) Debug(stream dbg.DebugService_DebugServer) error {
}

// GetDebugConfig return metadata about a debug session
func (s *DebugService) GetDebugConfig(ctx context.Context, req *dbg.DebugConfigRequest) (*dbg.GetDebugConfigResponse, error) {
func (s *ArduinoCoreServerImpl) GetDebugConfig(ctx context.Context, req *rpc.GetDebugConfigRequest) (*rpc.GetDebugConfigResponse, error) {
return cmd.GetDebugConfig(ctx, req)
}
14 changes: 7 additions & 7 deletions commands/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/executils"
"github.com/arduino/arduino-cli/i18n"
dbg "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/debug/v1"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
)
Expand All @@ -42,7 +42,7 @@ var tr = i18n.Tr
// grpc Out <- tool stdOut
// grpc Out <- tool stdErr
// It also implements tool process lifecycle management
func Debug(ctx context.Context, req *dbg.DebugConfigRequest, inStream io.Reader, out io.Writer, interrupt <-chan os.Signal) (*dbg.DebugResponse, error) {
func Debug(ctx context.Context, req *rpc.GetDebugConfigRequest, inStream io.Reader, out io.Writer, interrupt <-chan os.Signal) (*rpc.DebugResponse, error) {

// Get debugging command line to run debugger
pme, release := commands.GetPackageManagerExplorer(req)
Expand Down Expand Up @@ -75,7 +75,7 @@ func Debug(ctx context.Context, req *dbg.DebugConfigRequest, inStream io.Reader,
// Get stdIn pipe from tool
in, err := cmd.StdinPipe()
if err != nil {
return &dbg.DebugResponse{Error: err.Error()}, nil
return &rpc.DebugResponse{Error: err.Error()}, nil
}
defer in.Close()

Expand All @@ -85,7 +85,7 @@ func Debug(ctx context.Context, req *dbg.DebugConfigRequest, inStream io.Reader,

// Start the debug command
if err := cmd.Start(); err != nil {
return &dbg.DebugResponse{Error: err.Error()}, nil
return &rpc.DebugResponse{Error: err.Error()}, nil
}

if interrupt != nil {
Expand All @@ -111,13 +111,13 @@ func Debug(ctx context.Context, req *dbg.DebugConfigRequest, inStream io.Reader,

// Wait for process to finish
if err := cmd.Wait(); err != nil {
return &dbg.DebugResponse{Error: err.Error()}, nil
return &rpc.DebugResponse{Error: err.Error()}, nil
}
return &dbg.DebugResponse{}, nil
return &rpc.DebugResponse{}, nil
}

// getCommandLine compose a debug command represented by a core recipe
func getCommandLine(req *dbg.DebugConfigRequest, pme *packagemanager.Explorer) ([]string, error) {
func getCommandLine(req *rpc.GetDebugConfigRequest, pme *packagemanager.Explorer) ([]string, error) {
debugInfo, err := getDebugProperties(req, pme)
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions commands/debug/debug_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import (
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/arduino/sketch"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/debug/v1"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/go-paths-helper"
"github.com/arduino/go-properties-orderedmap"
"github.com/sirupsen/logrus"
)

// GetDebugConfig returns metadata to start debugging with the specified board
func GetDebugConfig(ctx context.Context, req *debug.DebugConfigRequest) (*debug.GetDebugConfigResponse, error) {
func GetDebugConfig(ctx context.Context, req *rpc.GetDebugConfigRequest) (*rpc.GetDebugConfigResponse, error) {
pme, release := commands.GetPackageManagerExplorer(req)
if pme == nil {
return nil, &arduino.InvalidInstanceError{}
Expand All @@ -40,7 +40,7 @@ func GetDebugConfig(ctx context.Context, req *debug.DebugConfigRequest) (*debug.
return getDebugProperties(req, pme)
}

func getDebugProperties(req *debug.DebugConfigRequest, pme *packagemanager.Explorer) (*debug.GetDebugConfigResponse, error) {
func getDebugProperties(req *rpc.GetDebugConfigRequest, pme *packagemanager.Explorer) (*rpc.GetDebugConfigResponse, error) {
// TODO: make a generic function to extract sketch from request
// and remove duplication in commands/compile.go
if req.GetSketchPath() == "" {
Expand Down Expand Up @@ -150,7 +150,7 @@ func getDebugProperties(req *debug.DebugConfigRequest, pme *packagemanager.Explo

server := debugProperties.Get("server")
toolchain := debugProperties.Get("toolchain")
return &debug.GetDebugConfigResponse{
return &rpc.GetDebugConfigResponse{
Executable: debugProperties.Get("executable"),
Server: server,
ServerPath: debugProperties.Get("server." + server + ".path"),
Expand Down
5 changes: 2 additions & 3 deletions commands/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
dbg "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/debug/v1"
"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -47,7 +46,7 @@ func TestGetCommandLine(t *testing.T) {
}

// Arduino Zero has an integrated debugger port, anc it could be debugged directly using USB
req := &dbg.DebugConfigRequest{
req := &rpc.GetDebugConfigRequest{
Instance: &rpc.Instance{Id: 1},
Fqbn: "arduino-test:samd:arduino_zero_edbg",
SketchPath: sketchPath.String(),
Expand All @@ -71,7 +70,7 @@ func TestGetCommandLine(t *testing.T) {

// Other samd boards such as mkr1000 can be debugged using an external tool such as Atmel ICE connected to
// the board debug port
req2 := &dbg.DebugConfigRequest{
req2 := &rpc.GetDebugConfigRequest{
Instance: &rpc.Instance{Id: 1},
Fqbn: "arduino-test:samd:mkr1000",
SketchPath: sketchPath.String(),
Expand Down
9 changes: 9 additions & 0 deletions docs/UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ Here you can find a list of migration guides to handle breaking changes between

## 0.35.0

### gRPC service `cc.arduino.cli.debug.v1` moved to `cc.arduino.cli.commands.v1`.

The gRPC service `cc.arduino.cli.debug.v1` has been removed and all gRPC messages and rpc calls have been moved to
`cc.arduino.cli.commands.v1`.

The gRPC message `DebugConfigRequest` has been renamed to the proper `GetDebugConfigRequest`.

All the generated API has been updated as well.

### The gRPC `cc.arduino.cli.commands.v1.BoardListWatchRequest` command request has been changed.

The gRPC message `BoardListWatchRequest` has been changed from:
Expand Down
4 changes: 0 additions & 4 deletions internal/cli/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/arduino/arduino-cli/i18n"
"github.com/arduino/arduino-cli/internal/cli/feedback"
srv_commands "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
srv_debug "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/debug/v1"
srv_settings "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/settings/v1"
"github.com/arduino/arduino-cli/version"
"github.com/arduino/go-paths-helper"
Expand Down Expand Up @@ -111,9 +110,6 @@ func runDaemonCommand(cmd *cobra.Command, args []string) {
// Register the settings service
srv_settings.RegisterSettingsServiceServer(s, &daemon.SettingsService{})

// Register the debug session service
srv_debug.RegisterDebugServiceServer(s, &daemon.DebugService{})

if !daemonize {
// When parent process ends terminate also the daemon
go feedback.ExitWhenParentProcessEnds()
Expand Down
5 changes: 2 additions & 3 deletions internal/cli/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/arduino/arduino-cli/internal/cli/feedback"
"github.com/arduino/arduino-cli/internal/cli/instance"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
dbg "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/debug/v1"
"github.com/arduino/arduino-cli/table"
"github.com/arduino/go-properties-orderedmap"
"github.com/fatih/color"
Expand Down Expand Up @@ -82,7 +81,7 @@ func runDebugCommand(command *cobra.Command, args []string) {
feedback.FatalError(err, feedback.ErrGeneric)
}
fqbn, port := arguments.CalculateFQBNAndPort(&portArgs, &fqbnArg, instance, sk.GetDefaultFqbn(), sk.GetDefaultPort(), sk.GetDefaultProtocol())
debugConfigRequested := &dbg.DebugConfigRequest{
debugConfigRequested := &rpc.GetDebugConfigRequest{
Instance: instance,
Fqbn: fqbn,
SketchPath: sketchPath.String(),
Expand Down Expand Up @@ -118,7 +117,7 @@ func runDebugCommand(command *cobra.Command, args []string) {
}

type debugInfoResult struct {
info *dbg.GetDebugConfigResponse
info *rpc.GetDebugConfigResponse
}

func (r *debugInfoResult) Data() interface{} {
Expand Down
1 change: 0 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ nav:
- gRPC reference:
- commands: rpc/commands.md
- settings: rpc/settings.md
- debug: rpc/debug.md
- configuration.md
- Integration options: integration-options.md
- sketch-build-process.md
Expand Down
Loading

0 comments on commit c506f6a

Please sign in to comment.