Skip to content

Commit 8043231

Browse files
[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
1 parent 28fc9d6 commit 8043231

File tree

5 files changed

+61
-41
lines changed

5 files changed

+61
-41
lines changed

Diff for: commands/sketch/warn_deprecated.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package sketch
17+
18+
import (
19+
"fmt"
20+
21+
"github.com/arduino/arduino-cli/arduino/sketch"
22+
paths "github.com/arduino/go-paths-helper"
23+
)
24+
25+
// WarnDeprecatedFiles warns the user that a type of sketch files are deprecated
26+
func WarnDeprecatedFiles(sketchPath *paths.Path) string {
27+
// .pde files are still supported but deprecated, this warning urges the user to rename them
28+
if files := sketch.CheckForPdeFiles(sketchPath); len(files) > 0 {
29+
msg := tr("Sketches with .pde extension are deprecated, please rename the following files to .ino:")
30+
for _, f := range files {
31+
msg += fmt.Sprintf("\n - %s", f)
32+
}
33+
return msg
34+
}
35+
return ""
36+
}

Diff for: internal/cli/arguments/sketch.go

+3-15
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
package arguments
1717

1818
import (
19-
"fmt"
20-
21-
"github.com/arduino/arduino-cli/arduino/sketch"
19+
sk "github.com/arduino/arduino-cli/commands/sketch"
2220
"github.com/arduino/arduino-cli/internal/cli/feedback"
2321
"github.com/arduino/go-paths-helper"
2422
"github.com/sirupsen/logrus"
@@ -38,18 +36,8 @@ func InitSketchPath(path string) (sketchPath *paths.Path) {
3836
logrus.Infof("Reading sketch from dir: %s", wd)
3937
sketchPath = wd
4038
}
41-
WarnDeprecatedFiles(sketchPath)
42-
return sketchPath
43-
}
44-
45-
// WarnDeprecatedFiles warns the user that a type of sketch files are deprecated
46-
func WarnDeprecatedFiles(sketchPath *paths.Path) {
47-
// .pde files are still supported but deprecated, this warning urges the user to rename them
48-
if files := sketch.CheckForPdeFiles(sketchPath); len(files) > 0 {
49-
msg := tr("Sketches with .pde extension are deprecated, please rename the following files to .ino:")
50-
for _, f := range files {
51-
msg += fmt.Sprintf("\n - %s", f)
52-
}
39+
if msg := sk.WarnDeprecatedFiles(sketchPath); msg != "" {
5340
feedback.Warning(msg)
5441
}
42+
return sketchPath
5543
}

Diff for: internal/cli/compile/compile.go

+9-11
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ import (
2525
"strings"
2626

2727
"github.com/arduino/arduino-cli/arduino"
28-
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
29-
"github.com/arduino/arduino-cli/commands"
3028
"github.com/arduino/arduino-cli/commands/compile"
29+
"github.com/arduino/arduino-cli/commands/core"
3130
"github.com/arduino/arduino-cli/commands/sketch"
3231
"github.com/arduino/arduino-cli/commands/upload"
3332
"github.com/arduino/arduino-cli/configuration"
@@ -363,17 +362,16 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
363362
panic(tr("Platform ID is not correct"))
364363
}
365364

366-
// FIXME: Here we should not access PackageManager...
367-
pme, release := commands.GetPackageManagerExplorer(compileRequest)
368-
platform := pme.FindPlatform(&packagemanager.PlatformReference{
369-
Package: split[0],
370-
PlatformArchitecture: split[1],
371-
})
372-
release()
373-
374365
if profileArg.String() == "" {
375366
res.Error += fmt.Sprintln()
376-
if platform != nil {
367+
368+
if platform, err := core.PlatformSearch(&rpc.PlatformSearchRequest{
369+
Instance: inst,
370+
SearchArgs: platformErr.Platform,
371+
AllVersions: false,
372+
}); err != nil {
373+
res.Error += err.Error()
374+
} else if len(platform.GetSearchOutput()) > 0 {
377375
suggestion := fmt.Sprintf("`%s core install %s`", version.VersionInfo.Application, platformErr.Platform)
378376
res.Error += tr("Try running %s", suggestion)
379377
} else {

Diff for: internal/cli/sketch/archive.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"os"
2222

2323
sk "github.com/arduino/arduino-cli/commands/sketch"
24-
"github.com/arduino/arduino-cli/internal/cli/arguments"
2524
"github.com/arduino/arduino-cli/internal/cli/feedback"
2625
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2726
"github.com/arduino/go-paths-helper"
@@ -61,7 +60,9 @@ func runArchiveCommand(args []string, includeBuildDir bool, overwrite bool) {
6160
sketchPath = paths.New(args[0])
6261
}
6362

64-
arguments.WarnDeprecatedFiles(sketchPath)
63+
if msg := sk.WarnDeprecatedFiles(sketchPath); msg != "" {
64+
feedback.Warning(msg)
65+
}
6566

6667
archivePath := ""
6768
if len(args) == 2 {

Diff for: internal/cli/upload/upload.go

+10-13
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import (
2323
"strings"
2424

2525
"github.com/arduino/arduino-cli/arduino"
26-
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
27-
"github.com/arduino/arduino-cli/commands"
26+
"github.com/arduino/arduino-cli/commands/core"
2827
sk "github.com/arduino/arduino-cli/commands/sketch"
2928
"github.com/arduino/arduino-cli/commands/upload"
3029
"github.com/arduino/arduino-cli/i18n"
@@ -86,8 +85,8 @@ func runUploadCommand(command *cobra.Command, args []string) {
8685
}
8786
sketchPath := arguments.InitSketchPath(path)
8887

89-
if importDir == "" && importFile == "" {
90-
arguments.WarnDeprecatedFiles(sketchPath)
88+
if msg := sk.WarnDeprecatedFiles(sketchPath); importDir == "" && importFile == "" && msg != "" {
89+
feedback.Warning(msg)
9190
}
9291

9392
sketch, err := sk.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
@@ -130,16 +129,14 @@ func runUploadCommand(command *cobra.Command, args []string) {
130129
panic(tr("Platform ID is not correct"))
131130
}
132131

133-
// FIXME: Here we must not access package manager...
134-
pme, release := commands.GetPackageManagerExplorer(&rpc.UploadRequest{Instance: inst})
135-
platform := pme.FindPlatform(&packagemanager.PlatformReference{
136-
Package: split[0],
137-
PlatformArchitecture: split[1],
138-
})
139-
release()
140-
141132
msg += "\n"
142-
if platform != nil {
133+
if platform, err := core.PlatformSearch(&rpc.PlatformSearchRequest{
134+
Instance: inst,
135+
SearchArgs: platformErr.Platform,
136+
AllVersions: false,
137+
}); err != nil {
138+
msg += err.Error()
139+
} else if len(platform.GetSearchOutput()) > 0 {
143140
msg += tr("Try running %s", fmt.Sprintf("`%s core install %s`", version.VersionInfo.Application, platformErr.Platform))
144141
} else {
145142
msg += tr("Platform %s is not found in any known index\nMaybe you need to add a 3rd party URL?", platformErr.Platform)

0 commit comments

Comments
 (0)