Unverified Commit 223d3fab authored by Cristian Maglie's avatar Cristian Maglie Committed by GitHub

Added gRPC command `SetSketchDefaults` to change sketch attached board/port (#2217)

* Remove some direct access to sketch.Sketch

* Moved `LoadSketch` command in the proper place

* Removed some accesses to sketch.Sketch

The required information are returned from LoadSketch.

* Added SetSketchDefaults gRPC call

This allows to finally remove wrong access to `sketch.Sketch` from `cli`
package.

* Updated docs

* Fixed integration tests

* Update rpc/cc/arduino/cli/commands/v1/commands.proto
Co-authored-by: default avatarAlessio Perugini <alessioper.98@gmail.com>

---------
Co-authored-by: default avatarAlessio Perugini <alessioper.98@gmail.com>
parent 82e6f5d7
......@@ -516,6 +516,19 @@ func (e *CantCreateSketchError) Unwrap() error {
return e.Cause
}
// CantUpdateSketchError is returned when the sketch cannot be updated
type CantUpdateSketchError struct {
Cause error
}
func (e *CantUpdateSketchError) Error() string {
return composeErrorMsg(tr("Can't update sketch"), e.Cause)
}
func (e *CantUpdateSketchError) Unwrap() error {
return e.Cause
}
// CantOpenSketchError is returned when the sketch is not found or cannot be opened
type CantOpenSketchError struct {
Cause error
......
......@@ -198,7 +198,13 @@ func (s *ArduinoCoreServerImpl) NewSketch(ctx context.Context, req *rpc.NewSketc
// LoadSketch FIXMEDOC
func (s *ArduinoCoreServerImpl) LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketchResponse, error) {
resp, err := commands.LoadSketch(ctx, req)
resp, err := sketch.LoadSketch(ctx, req)
return resp, convertErrorToRPCStatus(err)
}
// SetSketchDefaults FIXMEDOC
func (s *ArduinoCoreServerImpl) SetSketchDefaults(ctx context.Context, req *rpc.SetSketchDefaultsRequest) (*rpc.SetSketchDefaultsResponse, error) {
resp, err := sketch.SetSketchDefaults(ctx, req)
return resp, convertErrorToRPCStatus(err)
}
......
......@@ -569,38 +569,6 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rp
return nil
}
// LoadSketch collects and returns all files composing a sketch
func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketchResponse, error) {
// TODO: This should be a ToRpc function for the Sketch struct
sk, err := sketch.New(paths.New(req.SketchPath))
if err != nil {
return nil, &arduino.CantOpenSketchError{Cause: err}
}
otherSketchFiles := make([]string, sk.OtherSketchFiles.Len())
for i, file := range sk.OtherSketchFiles {
otherSketchFiles[i] = file.String()
}
additionalFiles := make([]string, sk.AdditionalFiles.Len())
for i, file := range sk.AdditionalFiles {
additionalFiles[i] = file.String()
}
rootFolderFiles := make([]string, sk.RootFolderFiles.Len())
for i, file := range sk.RootFolderFiles {
rootFolderFiles[i] = file.String()
}
return &rpc.LoadSketchResponse{
MainFile: sk.MainFile.String(),
LocationPath: sk.FullPath.String(),
OtherSketchFiles: otherSketchFiles,
AdditionalFiles: additionalFiles,
RootFolderFiles: rootFolderFiles,
}, nil
}
// firstUpdate downloads libraries and packages indexes if they don't exist.
// This ideally is only executed the first time the CLI is run.
func firstUpdate(ctx context.Context, instance *rpc.Instance, downloadCb func(msg *rpc.DownloadProgress), externalPackageIndexes []*url.URL) error {
......
// This file is part of arduino-cli.
//
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.
package sketch
import (
"context"
"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/arduino/sketch"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
paths "github.com/arduino/go-paths-helper"
)
// LoadSketch collects and returns all files composing a sketch
func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketchResponse, error) {
// TODO: This should be a ToRpc function for the Sketch struct
sk, err := sketch.New(paths.New(req.SketchPath))
if err != nil {
return nil, &arduino.CantOpenSketchError{Cause: err}
}
otherSketchFiles := make([]string, sk.OtherSketchFiles.Len())
for i, file := range sk.OtherSketchFiles {
otherSketchFiles[i] = file.String()
}
additionalFiles := make([]string, sk.AdditionalFiles.Len())
for i, file := range sk.AdditionalFiles {
additionalFiles[i] = file.String()
}
rootFolderFiles := make([]string, sk.RootFolderFiles.Len())
for i, file := range sk.RootFolderFiles {
rootFolderFiles[i] = file.String()
}
defaultPort, defaultProtocol := sk.GetDefaultPortAddressAndProtocol()
return &rpc.LoadSketchResponse{
MainFile: sk.MainFile.String(),
LocationPath: sk.FullPath.String(),
OtherSketchFiles: otherSketchFiles,
AdditionalFiles: additionalFiles,
RootFolderFiles: rootFolderFiles,
DefaultFqbn: sk.GetDefaultFQBN(),
DefaultPort: defaultPort,
DefaultProtocol: defaultProtocol,
}, nil
}
// This file is part of arduino-cli.
//
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.
package sketch
import (
"context"
"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/arduino/sketch"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
paths "github.com/arduino/go-paths-helper"
)
// SetSketchDefaults updates the sketch project file (sketch.yaml) with the given defaults
// for the values `default_fqbn`, `default_port`, and `default_protocol`.
func SetSketchDefaults(ctx context.Context, req *rpc.SetSketchDefaultsRequest) (*rpc.SetSketchDefaultsResponse, error) {
sk, err := sketch.New(paths.New(req.SketchPath))
if err != nil {
return nil, &arduino.CantOpenSketchError{Cause: err}
}
oldAddress, oldProtocol := sk.GetDefaultPortAddressAndProtocol()
res := &rpc.SetSketchDefaultsResponse{
DefaultFqbn: sk.GetDefaultFQBN(),
DefaultPortAddress: oldAddress,
DefaultPortProtocol: oldProtocol,
}
if fqbn := req.GetDefaultFqbn(); fqbn != "" {
if err := sk.SetDefaultFQBN(fqbn); err != nil {
return nil, &arduino.CantUpdateSketchError{Cause: err}
}
res.DefaultFqbn = fqbn
}
if newAddress, newProtocol := req.GetDefaultPortAddress(), req.GetDefaultPortProtocol(); newAddress != "" {
if err := sk.SetDefaultPort(newAddress, newProtocol); err != nil {
return nil, &arduino.CantUpdateSketchError{Cause: err}
}
res.DefaultPortAddress = newAddress
res.DefaultPortProtocol = newProtocol
}
return res, nil
}
......@@ -2,6 +2,13 @@
Here you can find a list of migration guides to handle breaking changes between releases of the CLI.
## 0.34.0
### golang API: `LoadSketch` function has been moved
The function `github.com/arduino/arduino-cli/commands.LoadSketch` has been moved to package
`github.com/arduino/arduino-cli/commands/sketch.LoadSketch`. You must change the import accordingly.
## 0.33.0
### gRPC `cc.arduino.cli.commands.v1.Compile` command now return expanded build_properties by default.
......
......@@ -19,7 +19,6 @@ import (
"strings"
"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/arduino/sketch"
"github.com/arduino/arduino-cli/internal/cli/feedback"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/spf13/cobra"
......@@ -70,12 +69,10 @@ func (f *Fqbn) Set(fqbn string) {
// - the port is not found, in this case nil is returned
// - the FQBN autodetection fail, in this case the function prints an error and
// terminates the execution
func CalculateFQBNAndPort(portArgs *Port, fqbnArg *Fqbn, instance *rpc.Instance, sk *sketch.Sketch) (string, *rpc.Port) {
// TODO: REMOVE sketch.Sketch from here
func CalculateFQBNAndPort(portArgs *Port, fqbnArg *Fqbn, instance *rpc.Instance, defaultFQBN, defaultAddress, defaultProtocol string) (string, *rpc.Port) {
fqbn := fqbnArg.String()
if fqbn == "" && sk != nil {
fqbn = sk.GetDefaultFQBN()
if fqbn == "" {
fqbn = defaultFQBN
}
if fqbn == "" {
if portArgs == nil || portArgs.address == "" {
......@@ -88,7 +85,7 @@ func CalculateFQBNAndPort(portArgs *Port, fqbnArg *Fqbn, instance *rpc.Instance,
return fqbn, port
}
port, err := portArgs.GetPort(instance, sk)
port, err := portArgs.GetPort(instance, defaultAddress, defaultProtocol)
if err != nil {
feedback.Fatal(tr("Error getting port metadata: %v", err), feedback.ErrGeneric)
}
......
......@@ -21,7 +21,6 @@ import (
"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/arduino/discovery"
"github.com/arduino/arduino-cli/arduino/sketch"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/board"
"github.com/arduino/arduino-cli/internal/cli/feedback"
......@@ -57,11 +56,12 @@ func (p *Port) AddToCommand(cmd *cobra.Command) {
// This method allows will bypass the discoveries if:
// - a nil instance is passed: in this case the plain port and protocol arguments are returned (even if empty)
// - a protocol is specified: in this case the discoveries are not needed to autodetect the protocol.
func (p *Port) GetPortAddressAndProtocol(instance *rpc.Instance, sk *sketch.Sketch) (string, string, error) {
func (p *Port) GetPortAddressAndProtocol(instance *rpc.Instance, defaultAddress, defaultProtocol string) (string, string, error) {
if p.protocol != "" || instance == nil {
return p.address, p.protocol, nil
}
port, err := p.GetPort(instance, sk)
port, err := p.GetPort(instance, defaultAddress, defaultProtocol)
if err != nil {
return "", "", err
}
......@@ -70,15 +70,13 @@ func (p *Port) GetPortAddressAndProtocol(instance *rpc.Instance, sk *sketch.Sket
// GetPort returns the Port obtained by parsing command line arguments.
// The extra metadata for the ports is obtained using the pluggable discoveries.
func (p *Port) GetPort(instance *rpc.Instance, sk *sketch.Sketch) (*discovery.Port, error) {
// TODO: REMOVE sketch.Sketch from here
func (p *Port) GetPort(instance *rpc.Instance, defaultAddress, defaultProtocol string) (*discovery.Port, error) {
// TODO: REMOVE discovery from here (use board.List instead)
address := p.address
protocol := p.protocol
if address == "" && sk != nil {
address, protocol = sk.GetDefaultPortAddressAndProtocol()
if address == "" && (defaultAddress != "" || defaultProtocol != "") {
address, protocol = defaultAddress, defaultProtocol
}
if address == "" {
// If no address is provided we assume the user is trying to upload
......
......@@ -42,15 +42,6 @@ func InitSketchPath(path string) (sketchPath *paths.Path) {
return sketchPath
}
// NewSketch is a helper function useful to create a sketch instance
func NewSketch(sketchPath *paths.Path) *sketch.Sketch {
sketch, err := sketch.New(sketchPath)
if err != nil {
feedback.Fatal(tr("Error opening sketch: %v", err), feedback.ErrGeneric)
}
return sketch
}
// WarnDeprecatedFiles warns the user that a type of sketch files are deprecated
func WarnDeprecatedFiles(sketchPath *paths.Path) {
// .pde files are still supported but deprecated, this warning urges the user to rename them
......
......@@ -16,11 +16,14 @@
package board
import (
"context"
"fmt"
"os"
"github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/internal/cli/arguments"
"github.com/arduino/arduino-cli/internal/cli/feedback"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/spf13/cobra"
)
......@@ -51,37 +54,28 @@ func initAttachCommand() *cobra.Command {
func runAttachCommand(path string, port *arguments.Port, fqbn string) {
sketchPath := arguments.InitSketchPath(path)
sk := arguments.NewSketch(sketchPath)
var currentPort *boardAttachPortResult
if currentAddress, currentProtocol := sk.GetDefaultPortAddressAndProtocol(); currentAddress != "" {
currentPort = &boardAttachPortResult{
Address: currentAddress,
Protocol: currentProtocol,
}
}
current := &boardAttachResult{
Port: currentPort,
Fqbn: sk.GetDefaultFQBN(),
portAddress, portProtocol, _ := port.GetPortAddressAndProtocol(nil, "", "")
newDefaults, err := sketch.SetSketchDefaults(context.Background(), &rpc.SetSketchDefaultsRequest{
SketchPath: sketchPath.String(),
DefaultFqbn: fqbn,
DefaultPortAddress: portAddress,
DefaultPortProtocol: portProtocol,
})
if err != nil {
feedback.FatalError(err, feedback.ErrGeneric)
}
address, protocol, _ := port.GetPortAddressAndProtocol(nil, sk)
if address != "" {
if err := sk.SetDefaultPort(address, protocol); err != nil {
feedback.Fatal(fmt.Sprintf("%s: %s", tr("Error saving sketch metadata"), err), feedback.ErrGeneric)
}
current.Port = &boardAttachPortResult{
Address: address,
Protocol: protocol,
}
res := &boardAttachResult{
Fqbn: newDefaults.GetDefaultFqbn(),
}
if fqbn != "" {
if err := sk.SetDefaultFQBN(fqbn); err != nil {
feedback.Fatal(fmt.Sprintf("%s: %s", tr("Error saving sketch metadata"), err), feedback.ErrGeneric)
if newDefaults.GetDefaultPortAddress() != "" {
res.Port = &boardAttachPortResult{
Address: newDefaults.GetDefaultPortAddress(),
Protocol: newDefaults.GetDefaultPortProtocol(),
}
current.Fqbn = fqbn
}
feedback.PrintResult(current)
feedback.PrintResult(res)
}
type boardAttachPortResult struct {
......
......@@ -67,7 +67,7 @@ func runBootloaderCommand(command *cobra.Command, args []string) {
logrus.Info("Executing `arduino-cli burn-bootloader`")
// We don't need a Sketch to upload a board's bootloader
discoveryPort, err := port.GetPort(instance, nil)
discoveryPort, err := port.GetPort(instance, "", "")
if err != nil {
feedback.Fatal(tr("Error during Upload: %v", err), feedback.ErrGeneric)
}
......
......@@ -28,6 +28,7 @@ import (
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/compile"
"github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/commands/upload"
"github.com/arduino/arduino-cli/configuration"
"github.com/arduino/arduino-cli/i18n"
......@@ -158,14 +159,16 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
}
sketchPath := arguments.InitSketchPath(path)
sk := arguments.NewSketch(sketchPath)
inst, profile := instance.CreateAndInitWithProfile(profileArg.Get(), sketchPath)
if fqbnArg.String() == "" {
fqbnArg.Set(profile.GetFqbn())
}
fqbn, port := arguments.CalculateFQBNAndPort(&portArgs, &fqbnArg, inst, sk)
sk, err := sketch.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
if err != nil {
feedback.FatalError(err, feedback.ErrGeneric)
}
fqbn, port := arguments.CalculateFQBNAndPort(&portArgs, &fqbnArg, inst, sk.GetDefaultFqbn(), sk.GetDefaultPort(), sk.GetDefaultProtocol())
if keysKeychain != "" || signKey != "" || encryptKey != "" {
arguments.CheckFlagsMandatory(cmd, "keys-keychain", "sign-key", "encrypt-key")
......
......@@ -22,10 +22,12 @@ import (
"sort"
"github.com/arduino/arduino-cli/commands/debug"
"github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/i18n"
"github.com/arduino/arduino-cli/internal/cli/arguments"
"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"
......@@ -75,8 +77,11 @@ func runDebugCommand(command *cobra.Command, args []string) {
}
sketchPath := arguments.InitSketchPath(path)
sk := arguments.NewSketch(sketchPath)
fqbn, port := arguments.CalculateFQBNAndPort(&portArgs, &fqbnArg, instance, sk)
sk, err := sketch.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
if err != nil {
feedback.FatalError(err, feedback.ErrGeneric)
}
fqbn, port := arguments.CalculateFQBNAndPort(&portArgs, &fqbnArg, instance, sk.GetDefaultFqbn(), sk.GetDefaultPort(), sk.GetDefaultProtocol())
debugConfigRequested := &dbg.DebugConfigRequest{
Instance: instance,
Fqbn: fqbn,
......
......@@ -74,7 +74,8 @@ func runMonitorCmd(cmd *cobra.Command, args []string) {
quiet = true
}
portAddress, portProtocol, err := portArgs.GetPortAddressAndProtocol(instance, nil)
// TODO: Should use sketch default_port/protocol?
portAddress, portProtocol, err := portArgs.GetPortAddressAndProtocol(instance, "", "")
if err != nil {
feedback.FatalError(err, feedback.ErrGeneric)
}
......
......@@ -100,7 +100,9 @@ func runUploadCommand(command *cobra.Command, args []string) {
fqbnArg.Set(profile.GetFqbn())
}
fqbn, port := arguments.CalculateFQBNAndPort(&portArgs, &fqbnArg, instance, sk)
defaultFQBN := sk.GetDefaultFQBN()
defaultAddress, defaultProtocol := sk.GetDefaultPortAddressAndProtocol()
fqbn, port := arguments.CalculateFQBNAndPort(&portArgs, &fqbnArg, instance, defaultFQBN, defaultAddress, defaultProtocol)
userFieldRes, err := upload.SupportedUserFields(context.Background(), &rpc.SupportedUserFieldsRequest{
Instance: instance,
......
......@@ -510,23 +510,55 @@ func TestBoardSearch(t *testing.T) {
]`)
}
func TestBoardAttachWithoutSketchJson(t *testing.T) {
func TestBoardAttach(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()
_, _, err := cli.Run("update")
require.NoError(t, err)
sketchName := "BoardAttachWithoutSketchJson"
sketchName := "BoardAttach"
sketchPath := cli.SketchbookDir().Join(sketchName)
fqbn := "arduino:avr:uno"
sketchProjectFlie := sketchPath.Join("sketch.yaml")
// Create a test sketch
_, _, err = cli.Run("sketch", "new", sketchPath.String())
_, _, err := cli.Run("sketch", "new", sketchPath.String())
require.NoError(t, err)
_, _, err = cli.Run("board", "attach", "-b", fqbn, sketchPath.String())
require.NoError(t, err)
{
stdout, _, err := cli.Run("board", "attach", "-b", "arduino:avr:uno", sketchPath.String(), "--format", "json")
require.NoError(t, err)
requirejson.Query(t, stdout, ".fqbn", `"arduino:avr:uno"`)
yamlData, err := sketchProjectFlie.ReadFile()
require.NoError(t, err)
require.Contains(t, string(yamlData), "default_fqbn: arduino:avr:uno")
require.NotContains(t, string(yamlData), "default_port:")
require.NotContains(t, string(yamlData), "default_protocol:")
}
{
stdout, _, err := cli.Run("board", "attach", "-p", "/dev/ttyACM0", "-l", "serial", sketchPath.String(), "--format", "json")
require.NoError(t, err)
requirejson.Query(t, stdout, ".fqbn", `"arduino:avr:uno"`)
requirejson.Query(t, stdout, ".port.address", `"/dev/ttyACM0"`)
requirejson.Query(t, stdout, ".port.protocol", `"serial"`)
yamlData, err := sketchProjectFlie.ReadFile()
require.NoError(t, err)
require.Contains(t, string(yamlData), "default_fqbn: arduino:avr:uno")
require.Contains(t, string(yamlData), "default_port: /dev/ttyACM0")
require.Contains(t, string(yamlData), "default_protocol: serial")
}
{
stdout, _, err := cli.Run("board", "attach", "-p", "/dev/ttyACM0", sketchPath.String(), "--format", "json")
require.NoError(t, err)
requirejson.Query(t, stdout, ".fqbn", `"arduino:avr:uno"`)
requirejson.Query(t, stdout, ".port.address", `"/dev/ttyACM0"`)
requirejson.Query(t, stdout, ".port.protocol", `null`)
yamlData, err := sketchProjectFlie.ReadFile()
require.NoError(t, err)
require.Contains(t, string(yamlData), "default_fqbn: arduino:avr:uno")
require.Contains(t, string(yamlData), "default_port: /dev/ttyACM0")
require.NotContains(t, string(yamlData), "default_protocol:")
}
}
func TestBoardSearchWithOutdatedCore(t *testing.T) {
......
......@@ -226,7 +226,7 @@ func compileWithSketchWithSymlinkSelfloop(t *testing.T, env *integrationtest.Env
_, stderr, err := cli.Run("compile", "-b", fqbn, sketchPath.String())
// The assertion is a bit relaxed in this case because win behaves differently from macOs and linux
// returning a different error detailed message
require.Contains(t, string(stderr), "Error opening sketch:")
require.Contains(t, string(stderr), "Can't open sketch:")
require.Error(t, err)
}
{
......@@ -252,7 +252,7 @@ func compileWithSketchWithSymlinkSelfloop(t *testing.T, env *integrationtest.Env
_, stderr, err := cli.Run("compile", "-b", fqbn, sketchPath.String())
// The assertion is a bit relaxed in this case because win behaves differently from macOs and linux
// returning a different error detailed message
require.Contains(t, string(stderr), "Error opening sketch:")
require.Contains(t, string(stderr), "Can't open sketch:")
require.Error(t, err)
}
}
......@@ -620,17 +620,17 @@ func compileWithMultipleMainFiles(t *testing.T, env *integrationtest.Environment
// Build sketch from folder
_, stderr, err := cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String())
require.Error(t, err)
require.Contains(t, string(stderr), "Error opening sketch: multiple main sketch files found")
require.Contains(t, string(stderr), "Can't open sketch: multiple main sketch files found")
// Build sketch from .ino file
_, stderr, err = cli.Run("compile", "--clean", "-b", fqbn, sketchFileIno.String())
require.Error(t, err)
require.Contains(t, string(stderr), "Error opening sketch: multiple main sketch files found")
require.Contains(t, string(stderr), "Can't open sketch: multiple main sketch files found")
// Build sketch from .pde file
_, stderr, err = cli.Run("compile", "--clean", "-b", fqbn, sketchFilePde.String())
require.Error(t, err)
require.Contains(t, string(stderr), "Error opening sketch: multiple main sketch files found")
require.Contains(t, string(stderr), "Can't open sketch: multiple main sketch files found")
}
func compileCaseMismatchFails(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
......@@ -652,17 +652,17 @@ func compileCaseMismatchFails(t *testing.T, env *integrationtest.Environment, cl
// * Compiling with sketch path
_, stderr, err := cli.Run("compile", "--clean", "-b", fqbn, sketchPath.String())
require.Error(t, err)
require.Contains(t, string(stderr), "Error opening sketch:")
require.Contains(t, string(stderr), "Can't open sketch:")
// * Compiling with sketch main file
_, stderr, err = cli.Run("compile", "--clean", "-b", fqbn, sketchMainFile.String())
require.Error(t, err)
require.Contains(t, string(stderr), "Error opening sketch:")
require.Contains(t, string(stderr), "Can't open sketch:")
// * Compiling in sketch path
cli.SetWorkingDir(sketchPath)
defer cli.SetWorkingDir(env.RootDir())
_, stderr, err = cli.Run("compile", "--clean", "-b", fqbn)
require.Error(t, err)
require.Contains(t, string(stderr), "Error opening sketch:")
require.Contains(t, string(stderr), "Can't open sketch:")
}
func compileOnlyCompilationDatabaseFlag(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -60,6 +60,12 @@ service ArduinoCoreService {
// Creates a zip file containing all files of specified Sketch
rpc ArchiveSketch(ArchiveSketchRequest) returns (ArchiveSketchResponse) {}
// Sets the sketch default FQBN and Port Address/Protocol in
// the sketch project file (sketch.yaml). These metadata can be retrieved
// using LoadSketch.
rpc SetSketchDefaults(SetSketchDefaultsRequest)
returns (SetSketchDefaultsResponse) {}
// BOARD COMMANDS
// --------------
......@@ -300,6 +306,12 @@ message LoadSketchResponse {
// List of absolute paths to supported files in the sketch root folder, main
// file excluded
repeated string root_folder_files = 5;
// Default FQBN set in project file (sketch.yaml)
string default_fqbn = 6;
// Default Port set in project file (sketch.yaml)
string default_port = 7;
// Default Protocol set in project file (sketch.yaml)
string default_protocol = 8;
}
message ArchiveSketchRequest {
......@@ -315,3 +327,26 @@ message ArchiveSketchRequest {
}
message ArchiveSketchResponse {}
message SetSketchDefaultsRequest {
// Absolute path to Sketch file or folder containing Sketch file
string sketch_path = 1;
// The desired value for default_fqbn in project file (sketch.yaml)
string default_fqbn = 2;
// The desired value for default_port in project file (sketch.yaml)
string default_port_address = 3;
// The desired value for default_protocol in project file (sketch.yaml)
string default_port_protocol = 4;
}
message SetSketchDefaultsResponse {
// The value of default_fqnn that has been written in project file
// (sketch.yaml)
string default_fqbn = 1;
// The value of default_port that has been written in project file
// (sketch.yaml)
string default_port_address = 2;
// The value of default_protocol that has been written in project file
// (sketch.yaml)
string default_port_protocol = 3;
}
......@@ -43,6 +43,7 @@ const (
ArduinoCoreService_NewSketch_FullMethodName = "/cc.arduino.cli.commands.v1.ArduinoCoreService/NewSketch"
ArduinoCoreService_LoadSketch_FullMethodName = "/cc.arduino.cli.commands.v1.ArduinoCoreService/LoadSketch"
ArduinoCoreService_ArchiveSketch_FullMethodName = "/cc.arduino.cli.commands.v1.ArduinoCoreService/ArchiveSketch"
ArduinoCoreService_SetSketchDefaults_FullMethodName = "/cc.arduino.cli.commands.v1.ArduinoCoreService/SetSketchDefaults"
ArduinoCoreService_BoardDetails_FullMethodName = "/cc.arduino.cli.commands.v1.ArduinoCoreService/BoardDetails"
ArduinoCoreService_BoardList_FullMethodName = "/cc.arduino.cli.commands.v1.ArduinoCoreService/BoardList"
ArduinoCoreService_BoardListAll_FullMethodName = "/cc.arduino.cli.commands.v1.ArduinoCoreService/BoardListAll"
......@@ -97,6 +98,10 @@ type ArduinoCoreServiceClient interface {
LoadSketch(ctx context.Context, in *LoadSketchRequest, opts ...grpc.CallOption) (*LoadSketchResponse, error)
// Creates a zip file containing all files of specified Sketch
ArchiveSketch(ctx context.Context, in *ArchiveSketchRequest, opts ...grpc.CallOption) (*ArchiveSketchResponse, error)
// Sets the sketch default FQBN and Port Address/Protocol in
// the sketch project file (sketch.yaml). These metadata can be retrieved
// using LoadSketch.
SetSketchDefaults(ctx context.Context, in *SetSketchDefaultsRequest, opts ...grpc.CallOption) (*SetSketchDefaultsResponse, error)
// Requests details about a board
BoardDetails(ctx context.Context, in *BoardDetailsRequest, opts ...grpc.CallOption) (*BoardDetailsResponse, error)
// List the boards currently connected to the computer.
......@@ -320,6 +325,15 @@ func (c *arduinoCoreServiceClient) ArchiveSketch(ctx context.Context, in *Archiv
return out, nil
}
func (c *arduinoCoreServiceClient) SetSketchDefaults(ctx context.Context, in *SetSketchDefaultsRequest, opts ...grpc.CallOption) (*SetSketchDefaultsResponse, error) {
out := new(SetSketchDefaultsResponse)
err := c.cc.Invoke(ctx, ArduinoCoreService_SetSketchDefaults_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *arduinoCoreServiceClient) BoardDetails(ctx context.Context, in *BoardDetailsRequest, opts ...grpc.CallOption) (*BoardDetailsResponse, error) {
out := new(BoardDetailsResponse)
err := c.cc.Invoke(ctx, ArduinoCoreService_BoardDetails_FullMethodName, in, out, opts...)
......@@ -993,6 +1007,10 @@ type ArduinoCoreServiceServer interface {
LoadSketch(context.Context, *LoadSketchRequest) (*LoadSketchResponse, error)
// Creates a zip file containing all files of specified Sketch
ArchiveSketch(context.Context, *ArchiveSketchRequest) (*ArchiveSketchResponse, error)
// Sets the sketch default FQBN and Port Address/Protocol in
// the sketch project file (sketch.yaml). These metadata can be retrieved
// using LoadSketch.
SetSketchDefaults(context.Context, *SetSketchDefaultsRequest) (*SetSketchDefaultsResponse, error)
// Requests details about a board
BoardDetails(context.Context, *BoardDetailsRequest) (*BoardDetailsResponse, error)
// List the boards currently connected to the computer.
......@@ -1090,6 +1108,9 @@ func (UnimplementedArduinoCoreServiceServer) LoadSketch(context.Context, *LoadSk
func (UnimplementedArduinoCoreServiceServer) ArchiveSketch(context.Context, *ArchiveSketchRequest) (*ArchiveSketchResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ArchiveSketch not implemented")
}
func (UnimplementedArduinoCoreServiceServer) SetSketchDefaults(context.Context, *SetSketchDefaultsRequest) (*SetSketchDefaultsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method SetSketchDefaults not implemented")
}
func (UnimplementedArduinoCoreServiceServer) BoardDetails(context.Context, *BoardDetailsRequest) (*BoardDetailsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method BoardDetails not implemented")
}
......@@ -1361,6 +1382,24 @@ func _ArduinoCoreService_ArchiveSketch_Handler(srv interface{}, ctx context.Cont
return interceptor(ctx, in, info, handler)
}
func _ArduinoCoreService_SetSketchDefaults_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SetSketchDefaultsRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ArduinoCoreServiceServer).SetSketchDefaults(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: ArduinoCoreService_SetSketchDefaults_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ArduinoCoreServiceServer).SetSketchDefaults(ctx, req.(*SetSketchDefaultsRequest))
}
return interceptor(ctx, in, info, handler)
}
func _ArduinoCoreService_BoardDetails_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(BoardDetailsRequest)
if err := dec(in); err != nil {
......@@ -1975,6 +2014,10 @@ var ArduinoCoreService_ServiceDesc = grpc.ServiceDesc{
MethodName: "ArchiveSketch",
Handler: _ArduinoCoreService_ArchiveSketch_Handler,
},
{
MethodName: "SetSketchDefaults",
Handler: _ArduinoCoreService_SetSketchDefaults_Handler,
},
{
MethodName: "BoardDetails",
Handler: _ArduinoCoreService_BoardDetails_Handler,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment