-
-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added gRPC command
SetSketchDefaults
to change sketch attached boar…
…d/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: Alessio Perugini <alessioper.98@gmail.com> --------- Co-authored-by: Alessio Perugini <alessioper.98@gmail.com>
- Loading branch information
1 parent
82e6f5d
commit 223d3fa
Showing
20 changed files
with
1,001 additions
and
550 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// 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 contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.