Unverified Commit 8043231c authored by MatteoPologruto's avatar MatteoPologruto Committed by GitHub

[skip-changelog] Remove most of the direct accesses to `arduino` package (#2296)

* Move WarnDeprecatedFiles to commands/sketch

* Change FindPlatform's signature to avoid references to the Package Manager

* Replace direct access to the package manager with a call to PlatformSearch function
parent 28fc9d60
// 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 (
"fmt"
"github.com/arduino/arduino-cli/arduino/sketch"
paths "github.com/arduino/go-paths-helper"
)
// WarnDeprecatedFiles warns the user that a type of sketch files are deprecated
func WarnDeprecatedFiles(sketchPath *paths.Path) string {
// .pde files are still supported but deprecated, this warning urges the user to rename them
if files := sketch.CheckForPdeFiles(sketchPath); len(files) > 0 {
msg := tr("Sketches with .pde extension are deprecated, please rename the following files to .ino:")
for _, f := range files {
msg += fmt.Sprintf("\n - %s", f)
}
return msg
}
return ""
}
...@@ -16,9 +16,7 @@ ...@@ -16,9 +16,7 @@
package arguments package arguments
import ( import (
"fmt" sk "github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/arduino/sketch"
"github.com/arduino/arduino-cli/internal/cli/feedback" "github.com/arduino/arduino-cli/internal/cli/feedback"
"github.com/arduino/go-paths-helper" "github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
...@@ -38,18 +36,8 @@ func InitSketchPath(path string) (sketchPath *paths.Path) { ...@@ -38,18 +36,8 @@ func InitSketchPath(path string) (sketchPath *paths.Path) {
logrus.Infof("Reading sketch from dir: %s", wd) logrus.Infof("Reading sketch from dir: %s", wd)
sketchPath = wd sketchPath = wd
} }
WarnDeprecatedFiles(sketchPath) if msg := sk.WarnDeprecatedFiles(sketchPath); msg != "" {
return sketchPath
}
// 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
if files := sketch.CheckForPdeFiles(sketchPath); len(files) > 0 {
msg := tr("Sketches with .pde extension are deprecated, please rename the following files to .ino:")
for _, f := range files {
msg += fmt.Sprintf("\n - %s", f)
}
feedback.Warning(msg) feedback.Warning(msg)
} }
return sketchPath
} }
...@@ -25,9 +25,8 @@ import ( ...@@ -25,9 +25,8 @@ import (
"strings" "strings"
"github.com/arduino/arduino-cli/arduino" "github.com/arduino/arduino-cli/arduino"
"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/compile"
"github.com/arduino/arduino-cli/commands/core"
"github.com/arduino/arduino-cli/commands/sketch" "github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/commands/upload" "github.com/arduino/arduino-cli/commands/upload"
"github.com/arduino/arduino-cli/configuration" "github.com/arduino/arduino-cli/configuration"
...@@ -363,17 +362,16 @@ func runCompileCommand(cmd *cobra.Command, args []string) { ...@@ -363,17 +362,16 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
panic(tr("Platform ID is not correct")) panic(tr("Platform ID is not correct"))
} }
// FIXME: Here we should not access PackageManager...
pme, release := commands.GetPackageManagerExplorer(compileRequest)
platform := pme.FindPlatform(&packagemanager.PlatformReference{
Package: split[0],
PlatformArchitecture: split[1],
})
release()
if profileArg.String() == "" { if profileArg.String() == "" {
res.Error += fmt.Sprintln() res.Error += fmt.Sprintln()
if platform != nil {
if platform, err := core.PlatformSearch(&rpc.PlatformSearchRequest{
Instance: inst,
SearchArgs: platformErr.Platform,
AllVersions: false,
}); err != nil {
res.Error += err.Error()
} else if len(platform.GetSearchOutput()) > 0 {
suggestion := fmt.Sprintf("`%s core install %s`", version.VersionInfo.Application, platformErr.Platform) suggestion := fmt.Sprintf("`%s core install %s`", version.VersionInfo.Application, platformErr.Platform)
res.Error += tr("Try running %s", suggestion) res.Error += tr("Try running %s", suggestion)
} else { } else {
......
...@@ -21,7 +21,6 @@ import ( ...@@ -21,7 +21,6 @@ import (
"os" "os"
sk "github.com/arduino/arduino-cli/commands/sketch" sk "github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/internal/cli/arguments"
"github.com/arduino/arduino-cli/internal/cli/feedback" "github.com/arduino/arduino-cli/internal/cli/feedback"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/go-paths-helper" "github.com/arduino/go-paths-helper"
...@@ -61,7 +60,9 @@ func runArchiveCommand(args []string, includeBuildDir bool, overwrite bool) { ...@@ -61,7 +60,9 @@ func runArchiveCommand(args []string, includeBuildDir bool, overwrite bool) {
sketchPath = paths.New(args[0]) sketchPath = paths.New(args[0])
} }
arguments.WarnDeprecatedFiles(sketchPath) if msg := sk.WarnDeprecatedFiles(sketchPath); msg != "" {
feedback.Warning(msg)
}
archivePath := "" archivePath := ""
if len(args) == 2 { if len(args) == 2 {
......
...@@ -23,8 +23,7 @@ import ( ...@@ -23,8 +23,7 @@ import (
"strings" "strings"
"github.com/arduino/arduino-cli/arduino" "github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager" "github.com/arduino/arduino-cli/commands/core"
"github.com/arduino/arduino-cli/commands"
sk "github.com/arduino/arduino-cli/commands/sketch" sk "github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/commands/upload" "github.com/arduino/arduino-cli/commands/upload"
"github.com/arduino/arduino-cli/i18n" "github.com/arduino/arduino-cli/i18n"
...@@ -86,8 +85,8 @@ func runUploadCommand(command *cobra.Command, args []string) { ...@@ -86,8 +85,8 @@ func runUploadCommand(command *cobra.Command, args []string) {
} }
sketchPath := arguments.InitSketchPath(path) sketchPath := arguments.InitSketchPath(path)
if importDir == "" && importFile == "" { if msg := sk.WarnDeprecatedFiles(sketchPath); importDir == "" && importFile == "" && msg != "" {
arguments.WarnDeprecatedFiles(sketchPath) feedback.Warning(msg)
} }
sketch, err := sk.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()}) sketch, err := sk.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
...@@ -130,16 +129,14 @@ func runUploadCommand(command *cobra.Command, args []string) { ...@@ -130,16 +129,14 @@ func runUploadCommand(command *cobra.Command, args []string) {
panic(tr("Platform ID is not correct")) panic(tr("Platform ID is not correct"))
} }
// FIXME: Here we must not access package manager...
pme, release := commands.GetPackageManagerExplorer(&rpc.UploadRequest{Instance: inst})
platform := pme.FindPlatform(&packagemanager.PlatformReference{
Package: split[0],
PlatformArchitecture: split[1],
})
release()
msg += "\n" msg += "\n"
if platform != nil { if platform, err := core.PlatformSearch(&rpc.PlatformSearchRequest{
Instance: inst,
SearchArgs: platformErr.Platform,
AllVersions: false,
}); err != nil {
msg += err.Error()
} else if len(platform.GetSearchOutput()) > 0 {
msg += tr("Try running %s", fmt.Sprintf("`%s core install %s`", version.VersionInfo.Application, platformErr.Platform)) msg += tr("Try running %s", fmt.Sprintf("`%s core install %s`", version.VersionInfo.Application, platformErr.Platform))
} else { } else {
msg += tr("Platform %s is not found in any known index\nMaybe you need to add a 3rd party URL?", platformErr.Platform) msg += tr("Platform %s is not found in any known index\nMaybe you need to add a 3rd party URL?", platformErr.Platform)
......
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