Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

‎commands/sketch/warn_deprecated.go‎

Lines changed: 36 additions & 0 deletions
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 license@arduino.cc.
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+
}

‎internal/cli/arguments/sketch.go‎

Lines changed: 3 additions & 15 deletions
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
}

‎internal/cli/compile/compile.go‎

Lines changed: 9 additions & 11 deletions
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 {

‎internal/cli/sketch/archive.go‎

Lines changed: 3 additions & 2 deletions
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 {

‎internal/cli/upload/upload.go‎

Lines changed: 10 additions & 13 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /