Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
386740b
[skip changelog] Add DiscoveryManager to PackageManager
silvanocerza Aug 9, 2021
ebca55f
Add loading of PluggableDiscoveries when loading a platform release
silvanocerza Jun 23, 2021
7cf3215
Added compatibility layer for non-pluggable platforms
cmaglie Jun 29, 2021
f442b1a
Implemented board list with discoveries
silvanocerza Aug 9, 2021
dd6a8fc
Implemented discovery loading after initialization
cmaglie Jun 29, 2021
f07775a
Implemented board watch with discoveries
silvanocerza Aug 9, 2021
e80869b
Fix load discoveries tests
silvanocerza Jun 29, 2021
23bab36
Fix some issues with board list watcher
silvanocerza Jun 30, 2021
3b4bd38
Fix FindToolsRequiredFromPlatformRelease not returning discoveries
silvanocerza Jun 30, 2021
47b84f5
Enhanced handling of some discoveries states
silvanocerza Jul 2, 2021
b32749f
Fix PackageManager reset
silvanocerza Jul 6, 2021
0d2add4
Add function to convert discovery.Port to rpc.Port
silvanocerza Aug 9, 2021
8bb84b2
Moved reference argument parsing to new package
silvanocerza Jul 6, 2021
3ff8287
Fix functions docstrings
silvanocerza Jul 8, 2021
ec3dfbc
Remove duplicated code to initialize Sketch path
silvanocerza Aug 9, 2021
fb934e5
Add property conversion for platform not supporting pluggable discovery
silvanocerza Jul 15, 2021
38c4325
Fix board list watch not working
silvanocerza Jul 15, 2021
a3007fe
Fix crash when converting Port to rpc struct
silvanocerza Jul 20, 2021
2d69063
Add generic Port argument
silvanocerza Jul 15, 2021
7e6dfca
Change gRPC upload functions to use new Port message
silvanocerza Aug 9, 2021
e6c33ea
Add support for upload user fields
silvanocerza Aug 9, 2021
4a586d9
Fix upload unit tests
silvanocerza Jul 20, 2021
67ae164
Fix code naming issues
silvanocerza Jul 20, 2021
ddf1603
Added builtin:mdns-discovery
cmaglie Jul 21, 2021
ea61dca
Do not panic if discovery tool is not installed
cmaglie Jul 21, 2021
d255c3d
Implemented port/protocol detection at CLI startup time
silvanocerza Aug 9, 2021
18777b2
Perform 1200bps-touch only on serial ports
cmaglie Jul 21, 2021
709db6f
Added missing properties for pluggable upload
cmaglie Jul 21, 2021
322ce23
Correctly implemented 'board list' timeout option
silvanocerza Aug 9, 2021
4fc7857
Updated mdns-discovery to 0.9.2
cmaglie Jul 22, 2021
77a40fd
Add documentation
silvanocerza Aug 10, 2021
f8ac21d
Add board properties to board list command and gRPC function
silvanocerza Aug 9, 2021
5ecf4d8
Fix documentation and code comments
silvanocerza Aug 10, 2021
c8fb6e4
Fix crash when attempting upload without specifying port address
silvanocerza Jul 23, 2021
2a7d3d2
Fix unit tests
silvanocerza Jul 23, 2021
015aea3
Update go-properties-orderedmap to fix discovery properties issues
silvanocerza Aug 11, 2021
33f8848
Fix more documentation
silvanocerza Jul 26, 2021
bd68d5e
Clarify pluggable discovery specification
silvanocerza Jul 26, 2021
69c6812
More documentation fixes
silvanocerza Jul 27, 2021
aec9695
Add upload_port properties docs in platform specification
silvanocerza Jul 27, 2021
ed318af
Change links from pluggable discovery RFC to official docs
silvanocerza Jul 27, 2021
95b69fa
Add more upload mock integration tests
silvanocerza Jul 27, 2021
3e3fcd2
Fix integration tests
silvanocerza Jul 28, 2021
b7d594f
Change property to declare pluggable discoveries
silvanocerza Aug 10, 2021
763ce6f
Change property to declare pluggable discoveries
silvanocerza Jul 28, 2021
ae3a497
Fix documentation
silvanocerza Jul 28, 2021
3f484ed
Fix loading of platform not supporting pluggable discovery
silvanocerza Jul 28, 2021
be9e879
Fix more documentation
silvanocerza Jul 29, 2021
225c123
Add pluggable discovery states documentation
silvanocerza Aug 2, 2021
569429d
Enhanced handling of pluggable discoveries states
silvanocerza Aug 9, 2021
a0f2aee
Discoveries processes are now killed if the HELLO command fails
silvanocerza Aug 3, 2021
2624785
Add pluggable discovery logging
silvanocerza Aug 4, 2021
2a555ff
Enhanced handling of failing pluggable discoveries
silvanocerza Aug 4, 2021
71dcc0e
Fix pluggable discoveries parallelization
silvanocerza Aug 9, 2021
a0a6371
Discoveries event channels are now created when start sync is called
silvanocerza Aug 9, 2021
cfc7aa4
Cached ports are now reset on discovery stop
silvanocerza Aug 9, 2021
2a34f7d
Renamed ListSync methods to ListCachedPorts
silvanocerza Aug 9, 2021
85607d6
Pluggable discovery upload user fields are now limited to 50 chars
silvanocerza Aug 9, 2021
a5be354
Fix i18n strings
silvanocerza Aug 9, 2021
e68e4e0
Fix failing integration tests
silvanocerza Aug 10, 2021
eef60aa
Fix i18n data
silvanocerza Aug 10, 2021
f8814bc
Fix integration tests again
silvanocerza Aug 10, 2021
5aa1f1d
[skip changelog] Internationalize strings added for pluggable discove…
per1234 Aug 10, 2021
9941402
Update docs/pluggable-discovery-specification.md
silvanocerza Aug 10, 2021
53e1d25
Fix failing workflows
silvanocerza Aug 11, 2021
9a355b7
Updated upload-mock tests for generation
cmaglie Aug 12, 2021
41db8b5
Added a lot of mock upload test (also with programmer option)
cmaglie Aug 16, 2021
b322874
test_upload_mock: Handle '{' and '}' in recipes
cmaglie Aug 16, 2021
d7a576c
network ota: autoconvert network_patter from legacy
cmaglie Aug 17, 2021
3c10109
Automatically add port detection properties for network discovery
cmaglie Aug 19, 2021
e6ee163
Slightly improved 'board list' text output
cmaglie Aug 20, 2021
75c7fef
Default 'board list' timeout to 1s
cmaglie Aug 20, 2021
c100e14
Added some code review fixes
cmaglie Aug 23, 2021
40943b1
Added unit test for legacy-package conversion to pluggable discovery
cmaglie Aug 23, 2021
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
Prev Previous commit
Next Next commit
Change gRPC upload functions to use new Port message
  • Loading branch information
silvanocerza authored and cmaglie committed Aug 19, 2021
commit 7e6dfca26cfd5fc487c803e237d70404f109612c
20 changes: 20 additions & 0 deletions cli/arguments/arguments.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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 [email protected].

package arguments

import "github.com/arduino/arduino-cli/i18n"

var tr = i18n.Tr
4 changes: 2 additions & 2 deletions cli/arguments/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type Port struct {

// AddToCommand adds the flags used to set port and protocol to the specified Command
func (p *Port) AddToCommand(cmd *cobra.Command) {
cmd.Flags().StringVarP(&p.address, "port", "p", "", "Upload port address, e.g.: COM3 or /dev/ttyACM2")
cmd.Flags().StringVarP(&p.protocol, "protocol", "l", "", "Upload port protocol, e.g: serial")
cmd.Flags().StringVarP(&p.address, "port", "p", "", tr("Upload port address, e.g.: COM3 or /dev/ttyACM2"))
cmd.Flags().StringVarP(&p.protocol, "protocol", "l", "", tr("Upload port protocol, e.g: serial"))
}

// GetPort returns the Port obtained by parsing command line arguments.
Expand Down
3 changes: 0 additions & 3 deletions cli/arguments/sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ import (

"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/feedback"
"github.com/arduino/arduino-cli/i18n"
"github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
)

var tr = i18n.Tr

// InitSketchPath returns an instance of paths.Path pointing to sketchPath.
// If sketchPath is an empty string returns the current working directory.
func InitSketchPath(sketchPath string) *paths.Path {
Expand Down
14 changes: 11 additions & 3 deletions cli/burnbootloader/burnbootloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"os"

"github.com/arduino/arduino-cli/cli/arguments"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/feedback"
"github.com/arduino/arduino-cli/cli/instance"
Expand All @@ -30,7 +31,7 @@ import (

var (
fqbn string
port string
port arguments.Port
verbose bool
verify bool
programmer string
Expand All @@ -50,7 +51,7 @@ func NewCommand() *cobra.Command {
}

burnBootloaderCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
burnBootloaderCommand.Flags().StringVarP(&port, "port", "p", "", tr("Upload port, e.g.: COM10 or /dev/ttyACM0"))
port.AddToCommand(burnBootloaderCommand)
burnBootloaderCommand.Flags().BoolVarP(&verify, "verify", "t", false, tr("Verify uploaded binary after the upload."))
burnBootloaderCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, tr("Turns on verbose mode."))
burnBootloaderCommand.Flags().StringVarP(&programmer, "programmer", "P", "", tr("Use the specified programmer to upload."))
Expand All @@ -63,10 +64,17 @@ func NewCommand() *cobra.Command {
func run(command *cobra.Command, args []string) {
instance := instance.CreateAndInit()

// We don't need a Sketch to upload a board's bootloader
discoveryPort, err := port.GetPort(instance, nil)
if err != nil {
feedback.Errorf("Error during Upload: %v", err)
os.Exit(errorcodes.ErrGeneric)
}

if _, err := upload.BurnBootloader(context.Background(), &rpc.BurnBootloaderRequest{
Instance: instance,
Fqbn: fqbn,
Port: port,
Port: discoveryPort.ToRPC(),
Verbose: verbose,
Verify: verify,
Programmer: programmer,
Expand Down
55 changes: 34 additions & 21 deletions cli/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"os"

"github.com/arduino/arduino-cli/arduino/discovery"
"github.com/arduino/arduino-cli/arduino/sketch"
"github.com/arduino/arduino-cli/cli/arguments"
"github.com/arduino/arduino-cli/cli/feedback"
Expand All @@ -39,25 +40,25 @@ import (
)

var (
fqbn string // Fully Qualified Board Name, e.g.: arduino:avr:uno.
showProperties bool // Show all build preferences used instead of compiling.
preprocess bool // Print preprocessed code to stdout.
buildCachePath string // Builds of 'core.a' are saved into this path to be cached and reused.
buildPath string // Path where to save compiled files.
buildProperties []string // List of custom build properties separated by commas. Or can be used multiple times for multiple properties.
warnings string // Used to tell gcc which warning level to use.
verbose bool // Turns on verbose mode.
quiet bool // Suppresses almost every output.
vidPid string // VID/PID specific build properties.
uploadAfterCompile bool // Upload the binary after the compilation.
port string // Upload port, e.g.: COM10 or /dev/ttyACM0.
verify bool // Upload, verify uploaded binary after the upload.
exportDir string // The compiled binary is written to this file
optimizeForDebug bool // Optimize compile output for debug, not for release
programmer string // Use the specified programmer to upload
clean bool // Cleanup the build folder and do not use any cached build
compilationDatabaseOnly bool // Only create compilation database without actually compiling
sourceOverrides string // Path to a .json file that contains a set of replacements of the sketch source code.
fqbn string // Fully Qualified Board Name, e.g.: arduino:avr:uno.
showProperties bool // Show all build preferences used instead of compiling.
preprocess bool // Print preprocessed code to stdout.
buildCachePath string // Builds of 'core.a' are saved into this path to be cached and reused.
buildPath string // Path where to save compiled files.
buildProperties []string // List of custom build properties separated by commas. Or can be used multiple times for multiple properties.
warnings string // Used to tell gcc which warning level to use.
verbose bool // Turns on verbose mode.
quiet bool // Suppresses almost every output.
vidPid string // VID/PID specific build properties.
uploadAfterCompile bool // Upload the binary after the compilation.
port arguments.Port // Upload port, e.g.: COM10 or /dev/ttyACM0.
verify bool // Upload, verify uploaded binary after the upload.
exportDir string // The compiled binary is written to this file
optimizeForDebug bool // Optimize compile output for debug, not for release
programmer string // Use the specified programmer to upload
clean bool // Cleanup the build folder and do not use any cached build
compilationDatabaseOnly bool // Only create compilation database without actually compiling
sourceOverrides string // Path to a .json file that contains a set of replacements of the sketch source code.
// library and libraries sound similar but they're actually different.
// library expects a path to the root folder of one single library.
// libraries expects a path to a directory containing multiple libraries, similarly to the <directories.user>/libraries path.
Expand Down Expand Up @@ -97,7 +98,7 @@ func NewCommand() *cobra.Command {
command.Flags().BoolVarP(&verbose, "verbose", "v", false, tr("Optional, turns on verbose mode."))
command.Flags().BoolVar(&quiet, "quiet", false, tr("Optional, suppresses almost every output."))
command.Flags().BoolVarP(&uploadAfterCompile, "upload", "u", false, tr("Upload the binary after the compilation."))
command.Flags().StringVarP(&port, "port", "p", "", tr("Upload port, e.g.: COM10 or /dev/ttyACM0"))
port.AddToCommand(command)
command.Flags().BoolVarP(&verify, "verify", "t", false, tr("Verify uploaded binary after the upload."))
command.Flags().StringVar(&vidPid, "vid-pid", "", tr("When specified, VID/PID specific build properties are used, if board supports them."))
command.Flags().StringSliceVar(&library, "library", []string{},
Expand Down Expand Up @@ -189,11 +190,23 @@ func run(cmd *cobra.Command, args []string) {
}

if err == nil && uploadAfterCompile {

var sk *sketch.Sketch
sk, err = sketch.New(sketchPath)
if err != nil {

}
var discoveryPort *discovery.Port
discoveryPort, err = port.GetPort(inst, sk)
if err != nil {

}

uploadRequest := &rpc.UploadRequest{
Instance: inst,
Fqbn: fqbn,
SketchPath: sketchPath.String(),
Port: port,
Port: discoveryPort.ToRPC(),
Verbose: verbose,
Verify: verify,
ImportDir: buildPath,
Expand Down
17 changes: 14 additions & 3 deletions cli/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (

var (
fqbn string
port string
port arguments.Port
verbose bool
verify bool
importDir string
Expand All @@ -56,7 +56,7 @@ func NewCommand() *cobra.Command {
}

uploadCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
uploadCommand.Flags().StringVarP(&port, "port", "p", "", tr("Upload port, e.g.: COM10 or /dev/ttyACM0"))
port.AddToCommand(uploadCommand)
uploadCommand.Flags().StringVarP(&importDir, "input-dir", "", "", tr("Directory containing binaries to upload."))
uploadCommand.Flags().StringVarP(&importFile, "input-file", "i", "", tr("Binary file to upload."))
uploadCommand.Flags().BoolVarP(&verify, "verify", "t", false, tr("Verify uploaded binary after the upload."))
Expand Down Expand Up @@ -91,11 +91,22 @@ func run(command *cobra.Command, args []string) {
}
}

sk, err := sketch.New(sketchPath)
if err != nil {
feedback.Errorf("Error during Upload: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
discoveryPort, err := port.GetPort(instance, sk)
if err != nil {
feedback.Errorf("Error during Upload: %v", err)
os.Exit(errorcodes.ErrGeneric)
}

if _, err := upload.Upload(context.Background(), &rpc.UploadRequest{
Instance: instance,
Fqbn: fqbn,
SketchPath: sketchPath.String(),
Port: port,
Port: discoveryPort.ToRPC(),
Verbose: verbose,
Verify: verify,
ImportFile: importFile,
Expand Down
84 changes: 42 additions & 42 deletions commands/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"context"
"fmt"
"io"
"net/url"
"path/filepath"
"strings"

Expand All @@ -40,6 +39,22 @@ import (

var tr = i18n.Tr

// getToolId returns the ID of the tool that supports the action and protocol combination by searching in props.
// Returns error if tool cannot be found.
func getToolId(props *properties.Map, action, protocol string) (string, error) {
toolProperty := fmt.Sprintf("%s.tool.%s", action, protocol)
defaultToolProperty := fmt.Sprintf("%s.tool.default", action)

if t, ok := props.GetOk(toolProperty); ok {
return t, nil
} else if t, ok := props.GetOk(defaultToolProperty); ok {
// Fallback for platform that don't support the specified protocol for specified action:
// https://github.com/arduino/tooling-rfcs/blob/main/RFCs/0002-pluggable-discovery.md#support-for-default-fallback-allows-upload-without-a-port
return t, nil
}
return "", fmt.Errorf("cannot find tool: undefined '%s' property", toolProperty)
}

// Upload FIXMEDOC
func Upload(ctx context.Context, req *rpc.UploadRequest, outStream io.Writer, errStream io.Writer) (*rpc.UploadResponse, error) {
logrus.Tracef("Upload %s on %s started", req.GetSketchPath(), req.GetFqbn())
Expand Down Expand Up @@ -98,7 +113,7 @@ func UsingProgrammer(ctx context.Context, req *rpc.UploadUsingProgrammerRequest,

func runProgramAction(pm *packagemanager.PackageManager,
sk *sketch.Sketch,
importFile, importDir, fqbnIn, port string,
importFile, importDir, fqbnIn string, port *rpc.Port,
programmerID string,
verbose, verify, burnBootloader bool,
outStream, errStream io.Writer,
Expand All @@ -108,16 +123,6 @@ func runProgramAction(pm *packagemanager.PackageManager,
return fmt.Errorf(tr("no programmer specified for burning bootloader"))
}

// FIXME: make a specification on how a port is specified via command line
if port == "" && sk != nil && sk.Metadata != nil {
deviceURI, err := url.Parse(sk.Metadata.CPU.Port)
if err != nil {
return fmt.Errorf(tr("invalid Device URL format: %s"), err)
}
if deviceURI.Scheme == "serial" {
port = deviceURI.Host + deviceURI.Path
}
}
logrus.WithField("port", port).Tracef("Upload port")

if fqbnIn == "" && sk != nil && sk.Metadata != nil {
Expand Down Expand Up @@ -157,28 +162,23 @@ func runProgramAction(pm *packagemanager.PackageManager,
}

// Determine upload tool
var uploadToolID string
{
toolProperty := "upload.tool"
if burnBootloader {
toolProperty = "bootloader.tool"
} else if programmer != nil {
toolProperty = "program.tool"
}

// create a temporary configuration only for the selection of upload tool
props := properties.NewMap()
props.Merge(boardPlatform.Properties)
props.Merge(boardPlatform.RuntimeProperties())
props.Merge(boardProperties)
if programmer != nil {
props.Merge(programmer.Properties)
}
if t, ok := props.GetOk(toolProperty); ok {
uploadToolID = t
} else {
return fmt.Errorf(tr("cannot get programmer tool: undefined '%s' property"), toolProperty)
}
// create a temporary configuration only for the selection of upload tool
props := properties.NewMap()
props.Merge(boardPlatform.Properties)
props.Merge(boardPlatform.RuntimeProperties())
props.Merge(boardProperties)
if programmer != nil {
props.Merge(programmer.Properties)
}
action := "upload"
if burnBootloader {
action = "bootloader"
} else if programmer != nil {
action = "program"
}
uploadToolID, err := getToolId(props, action, port.Protocol)
if err != nil {
return err
}

var uploadToolPlatform *cores.PlatformRelease
Expand Down Expand Up @@ -302,7 +302,7 @@ func runProgramAction(pm *packagemanager.PackageManager,
wait := false
portToTouch := ""
if touch {
portToTouch = port
portToTouch = port.Address
// Waits for upload port only if a 1200bps touch is done
wait = uploadProperties.GetBoolean("upload.wait_for_upload_port")
}
Expand Down Expand Up @@ -352,18 +352,18 @@ func runProgramAction(pm *packagemanager.PackageManager,
outStream.Write([]byte(fmt.Sprintln()))
} else {
if newPort != "" {
actualPort = newPort
actualPort.Address = newPort
}
}
}

if actualPort != "" {
if actualPort.Address != "" {
// Set serial port property
uploadProperties.Set("serial.port", actualPort)
if strings.HasPrefix(actualPort, "/dev/") {
uploadProperties.Set("serial.port.file", actualPort[5:])
} else {
uploadProperties.Set("serial.port.file", actualPort)
uploadProperties.Set("serial.port", actualPort.Address)
if actualPort.Protocol == "serial" {
// This must be done only for serial ports
portFile := strings.TrimPrefix(actualPort.Address, "/dev/")
uploadProperties.Set("serial.port.file", portFile)
}
}

Expand Down
Loading