Commit 14186ed4 authored by Cristian Maglie's avatar Cristian Maglie

Reimplemented serial-discovery discovery

parent 65f1043b
...@@ -21,12 +21,8 @@ import ( ...@@ -21,12 +21,8 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"os"
"github.com/arduino/arduino-cli/arduino/discovery"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/arduino/arduino-cli/rpc" "github.com/arduino/arduino-cli/rpc"
) )
...@@ -36,32 +32,6 @@ func BoardList(ctx context.Context, req *rpc.BoardListReq) (*rpc.BoardListResp, ...@@ -36,32 +32,6 @@ func BoardList(ctx context.Context, req *rpc.BoardListReq) (*rpc.BoardListResp,
return nil, errors.New("invalid instance") return nil, errors.New("invalid instance")
} }
// Check for bultin serial-discovery tool
loadBuiltinSerialDiscoveryMetadata(pm)
serialDiscoveryTool, _ := getBuiltinSerialDiscoveryTool(pm)
if !serialDiscoveryTool.IsInstalled() {
formatter.Print("Downloading and installing missing tool: " + serialDiscoveryTool.String())
commands.DownloadToolRelease(pm, serialDiscoveryTool, cli.OutputProgressBar())
commands.InstallToolRelease(pm, serialDiscoveryTool, cli.OutputTaskProgress())
if err := pm.LoadHardware(cli.Config); err != nil {
formatter.PrintError(err, "Could not load hardware packages.")
os.Exit(cli.ErrCoreConfig)
}
serialDiscoveryTool, _ = getBuiltinSerialDiscoveryTool(pm)
if !serialDiscoveryTool.IsInstalled() {
formatter.PrintErrorMessage("Missing serial-discovery tool.")
os.Exit(cli.ErrCoreConfig)
}
}
// TODO: move to 'commands' modules
_, err := discovery.NewFromCommandLine(serialDiscoveryTool.InstallDir.Join("serial-discovery").String())
if err != nil {
formatter.PrintError(err, "Error setting up serial-discovery tool.")
os.Exit(cli.ErrCoreConfig)
}
resp := &rpc.BoardListResp{Ports: []*rpc.DetectedPort{}} resp := &rpc.BoardListResp{Ports: []*rpc.DetectedPort{}}
for _, disc := range commands.GetDiscoveries(req) { for _, disc := range commands.GetDiscoveries(req) {
ports, err := disc.List() ports, err := disc.List()
......
...@@ -15,11 +15,14 @@ ...@@ -15,11 +15,14 @@
// a commercial license, send an email to license@arduino.cc. // a commercial license, send an email to license@arduino.cc.
// //
package board package commands
import ( import (
"fmt"
"github.com/arduino/arduino-cli/arduino/cores" "github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager" "github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/arduino/discovery"
"github.com/arduino/arduino-cli/arduino/resources" "github.com/arduino/arduino-cli/arduino/resources"
semver "go.bug.st/relaxed-semver" semver "go.bug.st/relaxed-semver"
) )
...@@ -87,3 +90,14 @@ func loadBuiltinSerialDiscoveryMetadata(pm *packagemanager.PackageManager) { ...@@ -87,3 +90,14 @@ func loadBuiltinSerialDiscoveryMetadata(pm *packagemanager.PackageManager) {
func getBuiltinSerialDiscoveryTool(pm *packagemanager.PackageManager) (*cores.ToolRelease, error) { func getBuiltinSerialDiscoveryTool(pm *packagemanager.PackageManager) (*cores.ToolRelease, error) {
return pm.Package("builtin").Tool("serial-discovery").Release(serialDiscoveryVersion).Get() return pm.Package("builtin").Tool("serial-discovery").Release(serialDiscoveryVersion).Get()
} }
func newBuiltinSerialDiscovery(pm *packagemanager.PackageManager) (*discovery.Discovery, error) {
t, err := getBuiltinSerialDiscoveryTool(pm)
if err != nil {
return nil, err
}
if !t.IsInstalled() {
return nil, fmt.Errorf("missing serial-discovery tool")
}
return discovery.NewFromCommandLine(t.InstallDir.Join("serial-discovery").String())
}
...@@ -82,8 +82,35 @@ func GetDiscoveries(req InstanceContainer) []*discovery.Discovery { ...@@ -82,8 +82,35 @@ func GetDiscoveries(req InstanceContainer) []*discovery.Discovery {
} }
func (instance *CoreInstance) startDiscoveries(downloadCB DownloadProgressCB, taskCB TaskProgressCB) error { func (instance *CoreInstance) startDiscoveries(downloadCB DownloadProgressCB, taskCB TaskProgressCB) error {
// Check for bultin serial-discovery tool
loadBuiltinSerialDiscoveryMetadata(instance.pm)
if downloadCB != nil {
serialDiscoveryTool, _ := getBuiltinSerialDiscoveryTool(instance.pm)
if !serialDiscoveryTool.IsInstalled() {
//formatter.Print("Downloading and installing missing tool: " + serialDiscoveryTool.String())
if err := DownloadToolRelease(instance.pm, serialDiscoveryTool, downloadCB); err != nil {
return fmt.Errorf(("could not download serial-discovery tool"))
}
if err := InstallToolRelease(instance.pm, serialDiscoveryTool, taskCB); err != nil {
return fmt.Errorf(("could not install serial-discovery tool"))
}
if err := instance.pm.LoadHardware(instance.config); err != nil {
return fmt.Errorf("could not load hardware packages: %s", err)
}
}
}
serialDiscovery, err := newBuiltinSerialDiscovery(instance.pm)
if err != nil {
return fmt.Errorf("starting serial discovery: %s", err)
}
discoveriesToStop := instance.discoveries discoveriesToStop := instance.discoveries
discoveriesToStart := discovery.ExtractDiscoveriesFromPlatforms(instance.pm) discoveriesToStart := append(
discovery.ExtractDiscoveriesFromPlatforms(instance.pm),
serialDiscovery,
)
instance.discoveries = []*discovery.Discovery{} instance.discoveries = []*discovery.Discovery{}
for _, disc := range discoveriesToStart { for _, disc := range discoveriesToStart {
......
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