Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-cli
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-cli
Commits
be5022e0
Commit
be5022e0
authored
Nov 19, 2021
by
Umberto Baldi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor sketch path calculation
parent
9771b998
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
56 additions
and
69 deletions
+56
-69
cli/arguments/port.go
cli/arguments/port.go
+12
-0
cli/arguments/sketch.go
cli/arguments/sketch.go
+32
-7
cli/compile/compile.go
cli/compile/compile.go
+3
-22
cli/debug/debug.go
cli/debug/debug.go
+4
-11
cli/sketch/archive.go
cli/sketch/archive.go
+2
-8
cli/upload/upload.go
cli/upload/upload.go
+3
-21
No files found.
cli/arguments/port.go
View file @
be5022e0
...
...
@@ -18,10 +18,12 @@ package arguments
import
(
"fmt"
"net/url"
"os"
"time"
"github.com/arduino/arduino-cli/arduino/discovery"
"github.com/arduino/arduino-cli/arduino/sketch"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/feedback"
"github.com/arduino/arduino-cli/commands"
rpc
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
...
...
@@ -144,3 +146,13 @@ func (p *Port) GetPort(instance *rpc.Instance, sk *sketch.Sketch) (*discovery.Po
}
}
}
// GetDiscoveryPort is a helper function useful to get the port and handle possible errors
func
(
p
*
Port
)
GetDiscoveryPort
(
instance
*
rpc
.
Instance
,
sk
*
sketch
.
Sketch
)
*
discovery
.
Port
{
discoveryPort
,
err
:=
p
.
GetPort
(
instance
,
sk
)
if
err
!=
nil
{
feedback
.
Errorf
(
tr
(
"Error discovering port: %v"
),
err
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
}
return
discoveryPort
}
cli/arguments/sketch.go
View file @
be5022e0
...
...
@@ -18,6 +18,7 @@ package arguments
import
(
"os"
"github.com/arduino/arduino-cli/arduino/sketch"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/feedback"
"github.com/arduino/go-paths-helper"
...
...
@@ -26,16 +27,40 @@ import (
// InitSketchPath returns an instance of paths.Path pointing to sketchPath.
// If sketchPath is an empty string returns the current working directory.
func
InitSketchPath
(
sketchPath
string
)
*
paths
.
Path
{
if
sketchPath
!=
""
{
return
paths
.
New
(
sketchPath
)
// In both cases it warns the user if he's using deprecated files
func
InitSketchPath
(
path
string
)
(
sketchPath
*
paths
.
Path
)
{
if
path
!=
""
{
sketchPath
=
paths
.
New
(
path
)
}
else
{
wd
,
err
:=
paths
.
Getwd
()
if
err
!=
nil
{
feedback
.
Errorf
(
tr
(
"Couldn't get current working directory: %v"
),
err
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
}
logrus
.
Infof
(
"Reading sketch from dir: %s"
,
wd
)
sketchPath
=
wd
}
WarnDeprecatedFiles
(
sketchPath
)
return
sketchPath
}
wd
,
err
:=
paths
.
Getwd
()
// NewSketch is a helper function useful to create a sketch instance
func
NewSketch
(
sketchPath
*
paths
.
Path
)
*
sketch
.
Sketch
{
sketch
,
err
:=
sketch
.
New
(
sketchPath
)
if
err
!=
nil
{
feedback
.
Errorf
(
tr
(
"
Couldn't get current working directory
: %v"
),
err
)
feedback
.
Errorf
(
tr
(
"
Error creating sketch
: %v"
),
err
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
}
logrus
.
Infof
(
"Reading sketch from dir: %s"
,
wd
)
return
wd
return
sketch
}
// 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
{
feedback
.
Error
(
tr
(
"Sketches with .pde extension are deprecated, please rename the following files to .ino:"
))
for
_
,
f
:=
range
files
{
feedback
.
Error
(
f
)
}
}
}
cli/compile/compile.go
View file @
be5022e0
...
...
@@ -21,8 +21,6 @@ import (
"encoding/json"
"os"
"github.com/arduino/arduino-cli/arduino/discovery"
"github.com/arduino/arduino-cli/arduino/sketch"
"github.com/arduino/arduino-cli/cli/arguments"
"github.com/arduino/arduino-cli/cli/feedback"
"github.com/arduino/arduino-cli/cli/output"
...
...
@@ -129,15 +127,8 @@ func run(cmd *cobra.Command, args []string) {
if
len
(
args
)
>
0
{
path
=
args
[
0
]
}
sketchPath
:=
arguments
.
InitSketchPath
(
path
)
// .pde files are still supported but deprecated, this warning urges the user to rename them
if
files
:=
sketch
.
CheckForPdeFiles
(
sketchPath
);
len
(
files
)
>
0
{
feedback
.
Error
(
tr
(
"Sketches with .pde extension are deprecated, please rename the following files to .ino:"
))
for
_
,
f
:=
range
files
{
feedback
.
Error
(
f
)
}
}
sketchPath
:=
arguments
.
InitSketchPath
(
path
)
var
overrides
map
[
string
]
string
if
sourceOverrides
!=
""
{
...
...
@@ -189,18 +180,8 @@ func run(cmd *cobra.Command, args []string) {
}
if
compileError
==
nil
&&
uploadAfterCompile
{
var
sk
*
sketch
.
Sketch
sk
,
err
:=
sketch
.
New
(
sketchPath
)
if
err
!=
nil
{
feedback
.
Errorf
(
tr
(
"Error during Upload: %v"
),
err
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
}
var
discoveryPort
*
discovery
.
Port
discoveryPort
,
err
=
port
.
GetPort
(
inst
,
sk
)
if
err
!=
nil
{
feedback
.
Errorf
(
tr
(
"Error during Upload: %v"
),
err
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
}
sk
:=
arguments
.
NewSketch
(
sketchPath
)
discoveryPort
:=
port
.
GetDiscoveryPort
(
inst
,
sk
)
userFieldRes
,
err
:=
upload
.
SupportedUserFields
(
context
.
Background
(),
&
rpc
.
SupportedUserFieldsRequest
{
Instance
:
inst
,
...
...
cli/debug/debug.go
View file @
be5022e0
...
...
@@ -21,7 +21,6 @@ import (
"os/signal"
"sort"
"github.com/arduino/arduino-cli/arduino/sketch"
"github.com/arduino/arduino-cli/cli/arguments"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/feedback"
...
...
@@ -81,17 +80,11 @@ func run(command *cobra.Command, args []string) {
if
len
(
args
)
>
0
{
path
=
args
[
0
]
}
sketchPath
:=
arguments
.
InitSketchPath
(
path
)
sk
,
err
:=
sketch
.
New
(
sketchPath
)
if
err
!=
nil
{
feedback
.
Errorf
(
tr
(
"Error during Debug: %v"
),
err
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
}
discoveryPort
,
err
:=
port
.
GetPort
(
instance
,
sk
)
if
err
!=
nil
{
feedback
.
Errorf
(
tr
(
"Error during Debug: %v"
),
err
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
}
sk
:=
arguments
.
NewSketch
(
sketchPath
)
discoveryPort
:=
port
.
GetDiscoveryPort
(
instance
,
sk
)
debugConfigRequested
:=
&
dbg
.
DebugConfigRequest
{
Instance
:
instance
,
Fqbn
:
fqbn
,
...
...
cli/sketch/archive.go
View file @
be5022e0
...
...
@@ -20,7 +20,7 @@ import (
"fmt"
"os"
"github.com/arduino/arduino-cli/
arduino/sketch
"
"github.com/arduino/arduino-cli/
cli/arguments
"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/feedback"
sk
"github.com/arduino/arduino-cli/commands/sketch"
...
...
@@ -61,13 +61,7 @@ func runArchiveCommand(cmd *cobra.Command, args []string) {
sketchPath
=
paths
.
New
(
args
[
0
])
}
// .pde files are still supported but deprecated, this warning urges the user to rename them
if
files
:=
sketch
.
CheckForPdeFiles
(
sketchPath
);
len
(
files
)
>
0
{
feedback
.
Error
(
tr
(
"Sketches with .pde extension are deprecated, please rename the following files to .ino:"
))
for
_
,
f
:=
range
files
{
feedback
.
Error
(
f
)
}
}
arguments
.
WarnDeprecatedFiles
(
sketchPath
)
archivePath
:=
""
if
len
(
args
)
==
2
{
...
...
cli/upload/upload.go
View file @
be5022e0
...
...
@@ -19,7 +19,6 @@ import (
"context"
"os"
"github.com/arduino/arduino-cli/arduino/sketch"
"github.com/arduino/arduino-cli/cli/arguments"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/feedback"
...
...
@@ -86,27 +85,10 @@ func run(command *cobra.Command, args []string) {
if
len
(
args
)
>
0
{
path
=
args
[
0
]
}
sketchPath
:=
arguments
.
InitSketchPath
(
path
)
// .pde files are still supported but deprecated, this warning urges the user to rename them
if
files
:=
sketch
.
CheckForPdeFiles
(
sketchPath
);
len
(
files
)
>
0
&&
importDir
==
""
&&
importFile
==
""
{
feedback
.
Error
(
tr
(
"Sketches with .pde extension are deprecated, please rename the following files to .ino:"
))
for
_
,
f
:=
range
files
{
feedback
.
Error
(
f
)
}
}
sk
,
err
:=
sketch
.
New
(
sketchPath
)
if
err
!=
nil
&&
importDir
==
""
&&
importFile
==
""
{
feedback
.
Errorf
(
tr
(
"Error during Upload: %v"
),
err
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
}
discoveryPort
,
err
:=
port
.
GetPort
(
instance
,
sk
)
if
err
!=
nil
{
feedback
.
Errorf
(
tr
(
"Error during Upload: %v"
),
err
)
os
.
Exit
(
errorcodes
.
ErrGeneric
)
}
sketchPath
:=
arguments
.
InitSketchPath
(
path
)
sk
:=
arguments
.
NewSketch
(
sketchPath
)
discoveryPort
:=
port
.
GetDiscoveryPort
(
instance
,
sk
)
if
fqbn
==
""
&&
sk
!=
nil
&&
sk
.
Metadata
!=
nil
{
// If the user didn't specify an FQBN and a sketch.json file is present
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment