Commit b6a5eb49 authored by Cristian Maglie's avatar Cristian Maglie

Download ctags builtin tool during Init

parent f027d134
......@@ -111,7 +111,7 @@ func run(cmd *cobra.Command, args []string) {
Quiet: flags.quiet,
VidPid: flags.vidPid,
ExportFile: flags.exportFile,
}, os.Stdout, os.Stderr, cli.OutputTaskProgress(), cli.OutputProgressBar())
}, os.Stdout, os.Stderr)
if err == nil {
outputCompileResp(compRes)
} else {
......
......@@ -15,13 +15,13 @@
* a commercial license, send an email to license@arduino.cc.
*/
package compile
package commands
import (
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/arduino/resources"
"go.bug.st/relaxed-semver"
semver "go.bug.st/relaxed-semver"
)
func loadBuiltinCtagsMetadata(pm *packagemanager.PackageManager) {
......@@ -85,5 +85,6 @@ func loadBuiltinCtagsMetadata(pm *packagemanager.PackageManager) {
var ctagsVersion = semver.ParseRelaxed("5.8-arduino11")
func getBuiltinCtagsTool(pm *packagemanager.PackageManager) (*cores.ToolRelease, error) {
loadBuiltinCtagsMetadata(pm)
return pm.Package("builtin").Tool("ctags").Release(ctagsVersion).Get()
}
......@@ -88,6 +88,7 @@ func loadBuiltinSerialDiscoveryMetadata(pm *packagemanager.PackageManager) {
}
func getBuiltinSerialDiscoveryTool(pm *packagemanager.PackageManager) (*cores.ToolRelease, error) {
loadBuiltinSerialDiscoveryMetadata(pm)
return pm.Package("builtin").Tool("serial-discovery").Release(serialDiscoveryVersion).Get()
}
......
......@@ -40,10 +40,7 @@ import (
"github.com/sirupsen/logrus"
)
func Compile(ctx context.Context, req *rpc.CompileReq,
outStream io.Writer, errStream io.Writer,
taskCB commands.TaskProgressCB, downloadCB commands.DownloadProgressCB) (*rpc.CompileResp, error) {
func Compile(ctx context.Context, req *rpc.CompileReq, outStream io.Writer, errStream io.Writer) (*rpc.CompileResp, error) {
pm := commands.GetPackageManager(req)
if pm == nil {
return nil, errors.New("invalid instance")
......@@ -71,24 +68,6 @@ func Compile(ctx context.Context, req *rpc.CompileReq,
return nil, fmt.Errorf("incorrect FQBN: %s", err)
}
// Check for ctags tool
loadBuiltinCtagsMetadata(pm)
ctags, _ := getBuiltinCtagsTool(pm)
if !ctags.IsInstalled() {
taskCB(&rpc.TaskProgress{Name: "Downloading missing tool " + ctags.String()})
commands.DownloadToolRelease(pm, ctags, downloadCB)
taskCB(&rpc.TaskProgress{Completed: true})
commands.InstallToolRelease(pm, ctags, taskCB)
if err := pm.LoadHardware(cli.Config); err != nil {
return nil, fmt.Errorf("loading hardware packages: %s", err)
}
ctags, _ = getBuiltinCtagsTool(pm)
if !ctags.IsInstalled() {
return nil, fmt.Errorf("missing ctags tool")
}
}
targetPlatform := pm.FindPlatform(&packagemanager.PlatformReference{
Package: fqbn.Package,
PlatformArchitecture: fqbn.PlatformArch,
......
......@@ -25,6 +25,7 @@ import (
"path"
"time"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/cores/packageindex"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/arduino/discovery"
......@@ -81,26 +82,45 @@ func GetDiscoveries(req InstanceContainer) []*discovery.Discovery {
return i.discoveries
}
func (instance *CoreInstance) startDiscoveries(downloadCB DownloadProgressCB, taskCB TaskProgressCB) error {
func (instance *CoreInstance) installToolIfMissing(tool *cores.ToolRelease, downloadCB DownloadProgressCB, taskCB TaskProgressCB) (bool, error) {
if tool.IsInstalled() {
return false, nil
}
taskCB(&rpc.TaskProgress{Name: "Downloading missing tool " + tool.String()})
if err := DownloadToolRelease(instance.pm, tool, downloadCB); err != nil {
return false, fmt.Errorf("downloading %s tool: %s", tool, err)
}
taskCB(&rpc.TaskProgress{Completed: true})
if err := InstallToolRelease(instance.pm, tool, taskCB); err != nil {
return false, fmt.Errorf("installing %s tool: %s", tool, err)
}
return true, nil
}
func (instance *CoreInstance) checkForBuiltinTools(downloadCB DownloadProgressCB, taskCB TaskProgressCB) error {
// Check for ctags tool
ctags, _ := getBuiltinCtagsTool(instance.pm)
ctagsInstalled, err := instance.installToolIfMissing(ctags, downloadCB, taskCB)
if err != nil {
return err
}
// 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)
}
serialDiscoveryTool, _ := getBuiltinSerialDiscoveryTool(instance.pm)
serialDiscoveryInstalled, err := instance.installToolIfMissing(serialDiscoveryTool, downloadCB, taskCB)
if err != nil {
return err
}
if ctagsInstalled || serialDiscoveryInstalled {
if err := instance.pm.LoadHardware(instance.config); err != nil {
return fmt.Errorf("could not load hardware packages: %s", err)
}
}
return nil
}
func (instance *CoreInstance) startDiscoveries() error {
serialDiscovery, err := newBuiltinSerialDiscovery(instance.pm)
if err != nil {
return fmt.Errorf("starting serial discovery: %s", err)
......@@ -162,10 +182,16 @@ func Init(ctx context.Context, req *rpc.InitReq, downloadCB DownloadProgressCB,
instancesCount++
instances[handle] = instance
if err := instance.startDiscoveries(downloadCB, taskCB); err != nil {
if err := instance.checkForBuiltinTools(downloadCB, taskCB); err != nil {
fmt.Println(err)
return nil, err
}
if err := instance.startDiscoveries(); err != nil {
// TODO: handle discovery errors
fmt.Println(err)
}
return &rpc.InitResp{
Instance: &rpc.Instance{Id: handle},
PlatformsIndexErrors: reqPltIndex,
......@@ -271,7 +297,7 @@ func Rescan(ctx context.Context, req *rpc.RescanReq) (*rpc.RescanResp, error) {
coreInstance.pm = pm
coreInstance.lm = lm
coreInstance.startDiscoveries(nil, nil)
coreInstance.startDiscoveries()
return &rpc.RescanResp{
PlatformsIndexErrors: reqPltIndex,
......
......@@ -120,8 +120,6 @@ func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileReq, stream rpc.ArduinoC
stream.Context(), req,
feedStream(func(data []byte) { stream.Send(&rpc.CompileResp{OutStream: data}) }),
feedStream(func(data []byte) { stream.Send(&rpc.CompileResp{ErrStream: data}) }),
func(p *rpc.TaskProgress) { stream.Send(&rpc.CompileResp{TaskProgress: p}) },
func(p *rpc.DownloadProgress) { stream.Send(&rpc.CompileResp{DownloadProgress: p}) },
)
if err != nil {
return err
......
......@@ -42,6 +42,4 @@ message CompileReq {
message CompileResp {
bytes out_stream = 1;
bytes err_stream = 2;
DownloadProgress download_progress = 3;
TaskProgress task_progress = 4;
}
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