Skip to content

Commit

Permalink
Removed gRPC 'debug' service in favor of 'commands' service
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Sep 29, 2023
1 parent 6aa1be0 commit c8c9e5f
Show file tree
Hide file tree
Showing 15 changed files with 1,310 additions and 1,396 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
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
Loading

0 comments on commit c8c9e5f

Please sign in to comment.