Skip to content

Commit c7913f9

Browse files
committed
Moved subroutine that warns about .pde files in feedback package
1 parent 17de7ab commit c7913f9

File tree

9 files changed

+28
-74
lines changed

9 files changed

+28
-74
lines changed

Diff for: internal/arduino/sketch/sketch_test.go

-35
Original file line numberDiff line numberDiff line change
@@ -291,41 +291,6 @@ func TestGenBuildPath(t *testing.T) {
291291
assert.Equal(t, "ACBD18DB4CC2F85CEDEF654FCCC4A4D8", (&Sketch{FullPath: paths.New("foo")}).Hash())
292292
}
293293

294-
func TestCheckForPdeFiles(t *testing.T) {
295-
sketchPath := paths.New("testdata", "SketchSimple")
296-
files := CheckForPdeFiles(sketchPath)
297-
require.Empty(t, files)
298-
299-
sketchPath = paths.New("testdata", "SketchPde")
300-
files = CheckForPdeFiles(sketchPath)
301-
require.Len(t, files, 1)
302-
require.Equal(t, sketchPath.Join("SketchPde.pde"), files[0])
303-
304-
sketchPath = paths.New("testdata", "SketchMultipleMainFiles")
305-
files = CheckForPdeFiles(sketchPath)
306-
require.Len(t, files, 1)
307-
require.Equal(t, sketchPath.Join("SketchMultipleMainFiles.pde"), files[0])
308-
309-
sketchPath = paths.New("testdata", "SketchSimple", "SketchSimple.ino")
310-
files = CheckForPdeFiles(sketchPath)
311-
require.Empty(t, files)
312-
313-
sketchPath = paths.New("testdata", "SketchPde", "SketchPde.pde")
314-
files = CheckForPdeFiles(sketchPath)
315-
require.Len(t, files, 1)
316-
require.Equal(t, sketchPath.Parent().Join("SketchPde.pde"), files[0])
317-
318-
sketchPath = paths.New("testdata", "SketchMultipleMainFiles", "SketchMultipleMainFiles.ino")
319-
files = CheckForPdeFiles(sketchPath)
320-
require.Len(t, files, 1)
321-
require.Equal(t, sketchPath.Parent().Join("SketchMultipleMainFiles.pde"), files[0])
322-
323-
sketchPath = paths.New("testdata", "SketchMultipleMainFiles", "SketchMultipleMainFiles.pde")
324-
files = CheckForPdeFiles(sketchPath)
325-
require.Len(t, files, 1)
326-
require.Equal(t, sketchPath.Parent().Join("SketchMultipleMainFiles.pde"), files[0])
327-
}
328-
329294
func TestNewSketchWithSymlink(t *testing.T) {
330295
sketchPath, _ := paths.New("testdata", "SketchWithSymlink").Abs()
331296
mainFilePath := sketchPath.Join("SketchWithSymlink.ino")

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

+1-7
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ import (
2828

2929
// InitSketchPath returns an instance of paths.Path pointing to sketchPath.
3030
// If sketchPath is an empty string returns the current working directory.
31-
// In both cases it warns the user if he's using deprecated files
32-
func InitSketchPath(path string, printWarnings bool) (sketchPath *paths.Path) {
31+
func InitSketchPath(path string) (sketchPath *paths.Path) {
3332
if path != "" {
3433
sketchPath = paths.New(path)
3534
} else {
@@ -40,11 +39,6 @@ func InitSketchPath(path string, printWarnings bool) (sketchPath *paths.Path) {
4039
logrus.Infof("Reading sketch from dir: %s", wd)
4140
sketchPath = wd
4241
}
43-
if printWarnings {
44-
if msg := sketch.WarnDeprecatedFiles(sketchPath); msg != "" {
45-
feedback.Warning(msg)
46-
}
47-
}
4842
return sketchPath
4943
}
5044

Diff for: internal/cli/board/attach.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func initAttachCommand() *cobra.Command {
5353
}
5454

5555
func runAttachCommand(path string, port *arguments.Port, fqbn string) {
56-
sketchPath := arguments.InitSketchPath(path, true)
56+
sketchPath := arguments.InitSketchPath(path)
5757

5858
portAddress, portProtocol, _ := port.GetPortAddressAndProtocol(nil, "", "")
5959
newDefaults, err := sketch.SetSketchDefaults(context.Background(), &rpc.SetSketchDefaultsRequest{

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
158158
path = args[0]
159159
}
160160

161-
sketchPath := arguments.InitSketchPath(path, true)
162-
161+
sketchPath := arguments.InitSketchPath(path)
163162
sk, err := sketch.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
164163
if err != nil {
165164
feedback.FatalError(err, feedback.ErrGeneric)
166165
}
166+
feedback.WarnAboutDeprecatedFiles(sk)
167167

168168
var inst *rpc.Instance
169169
var profile *rpc.Profile

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ func runDebugCommand(args []string, portArgs *arguments.Port, fqbnArg *arguments
8181
path = args[0]
8282
}
8383

84-
sketchPath := arguments.InitSketchPath(path, true)
84+
sketchPath := arguments.InitSketchPath(path)
8585
sk, err := sketch.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
8686
if err != nil {
8787
feedback.FatalError(err, feedback.ErrGeneric)
8888
}
89+
feedback.WarnAboutDeprecatedFiles(sk)
90+
8991
fqbn, port := arguments.CalculateFQBNAndPort(portArgs, fqbnArg, instance, sk.GetDefaultFqbn(), sk.GetDefaultPort(), sk.GetDefaultProtocol())
9092
debugConfigRequested := &rpc.GetDebugConfigRequest{
9193
Instance: instance,

Diff for: commands/sketch/warn_deprecated.go renamed to internal/cli/feedback/warn_deprecated.go

+14-15
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,32 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to [email protected].
1515

16-
package sketch
16+
package feedback
1717

1818
import (
1919
"fmt"
20+
"strings"
2021

21-
paths "github.com/arduino/go-paths-helper"
22+
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2223
)
2324

24-
// WarnDeprecatedFiles warns the user that a type of sketch files are deprecated
25-
func WarnDeprecatedFiles(sketchPath *paths.Path) string {
26-
if sketchPath.IsNotDir() {
27-
sketchPath = sketchPath.Parent()
25+
// WarnAboutDeprecatedFiles warns the user that a type of sketch files are deprecated
26+
func WarnAboutDeprecatedFiles(s *rpc.Sketch) {
27+
var files []string
28+
for _, f := range s.OtherSketchFiles {
29+
if strings.HasSuffix(f, ".pde") {
30+
files = append(files, f)
31+
}
2832
}
29-
30-
files, err := sketchPath.ReadDirRecursive()
31-
if err != nil {
32-
return ""
33+
if strings.HasSuffix(s.MainFile, ".pde") {
34+
files = append(files, s.MainFile)
3335
}
34-
files.FilterSuffix(".pde")
35-
36-
// .pde files are still supported but deprecated, this warning urges the user to rename them
3736
if len(files) > 0 {
37+
// .pde files are still supported but deprecated, this warning urges the user to rename them
3838
msg := tr("Sketches with .pde extension are deprecated, please rename the following files to .ino:")
3939
for _, f := range files {
4040
msg += fmt.Sprintf("\n - %s", f)
4141
}
42-
return msg
42+
Warning(msg)
4343
}
44-
return ""
4544
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func runMonitorCmd(
103103
// If both {--port --profile} are set we read the fqbn in the following order: profile -> default_fqbn -> discovery
104104
// If only --port is set we read the fqbn in the following order: default_fqbn -> discovery
105105
// If only --fqbn is set we read the port in the following order: default_port
106-
sketchPath := arguments.InitSketchPath(sketchPathArg, false)
106+
sketchPath := arguments.InitSketchPath(sketchPathArg)
107107
sketch, err := sk.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
108108
if err != nil && !portArgs.IsPortFlagSet() {
109109
feedback.Fatal(

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

-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ func runArchiveCommand(args []string, includeBuildDir bool, overwrite bool) {
6060
sketchPath = paths.New(args[0])
6161
}
6262

63-
if msg := sk.WarnDeprecatedFiles(sketchPath); msg != "" {
64-
feedback.Warning(msg)
65-
}
66-
6763
archivePath := ""
6864
if len(args) == 2 {
6965
archivePath = args[1]

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

+6-8
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,13 @@ func runUploadCommand(args []string, uploadFieldsArgs map[string]string) {
9090
if len(args) > 0 {
9191
path = args[0]
9292
}
93-
sketchPath := arguments.InitSketchPath(path, true)
94-
95-
if msg := sk.WarnDeprecatedFiles(sketchPath); importDir == "" && importFile == "" && msg != "" {
96-
feedback.Warning(msg)
97-
}
98-
93+
sketchPath := arguments.InitSketchPath(path)
9994
sketch, err := sk.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
100-
if err != nil && importDir == "" && importFile == "" {
101-
feedback.Fatal(tr("Error during Upload: %v", err), feedback.ErrGeneric)
95+
if importDir == "" && importFile == "" {
96+
if err != nil {
97+
feedback.Fatal(tr("Error during Upload: %v", err), feedback.ErrGeneric)
98+
}
99+
feedback.WarnAboutDeprecatedFiles(sketch)
102100
}
103101

104102
var inst *rpc.Instance

0 commit comments

Comments
 (0)