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 d106a67

Browse files
[skip-changelog] Use LoadSketch in upload function and return rpc.Port in GetPort (#2297)
* Change GetPort's returned type to rpc.Port * Use LoadSketch in runUploadCommand
1 parent 9dede8a commit d106a67

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

‎internal/cli/arguments/fqbn.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,5 @@ func CalculateFQBNAndPort(portArgs *Port, fqbnArg *Fqbn, instance *rpc.Instance,
8989
if err != nil {
9090
feedback.Fatal(tr("Error getting port metadata: %v", err), feedback.ErrGeneric)
9191
}
92-
return fqbn, port.ToRPC()
92+
return fqbn, port
9393
}

‎internal/cli/arguments/port.go‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"time"
2121

2222
"github.com/arduino/arduino-cli/arduino"
23-
"github.com/arduino/arduino-cli/arduino/discovery"
2423
"github.com/arduino/arduino-cli/commands"
2524
"github.com/arduino/arduino-cli/commands/board"
2625
"github.com/arduino/arduino-cli/internal/cli/feedback"
@@ -70,8 +69,7 @@ func (p *Port) GetPortAddressAndProtocol(instance *rpc.Instance, defaultAddress,
7069

7170
// GetPort returns the Port obtained by parsing command line arguments.
7271
// The extra metadata for the ports is obtained using the pluggable discoveries.
73-
func (p *Port) GetPort(instance *rpc.Instance, defaultAddress, defaultProtocol string) (*discovery.Port, error) {
74-
// TODO: REMOVE discovery from here (use board.List instead)
72+
func (p *Port) GetPort(instance *rpc.Instance, defaultAddress, defaultProtocol string) (*rpc.Port, error) {
7573

7674
address := p.address
7775
protocol := p.protocol
@@ -84,7 +82,7 @@ func (p *Port) GetPort(instance *rpc.Instance, defaultAddress, defaultProtocol s
8482
// the attached board without specifying explictly a port.
8583
// Tools that work this way must be specified using the property
8684
// "BOARD_ID.upload.tool.default" in the platform's boards.txt.
87-
return &discovery.Port{
85+
return &rpc.Port{
8886
Protocol: "default",
8987
}, nil
9088
}
@@ -113,13 +111,13 @@ func (p *Port) GetPort(instance *rpc.Instance, defaultAddress, defaultProtocol s
113111
}
114112
port := portEvent.Port
115113
if (protocol == "" || protocol == port.Protocol) && address == port.Address {
116-
return port, nil
114+
return port.ToRPC(), nil
117115
}
118116

119117
case <-deadline:
120118
// No matching port found
121119
if protocol == "" {
122-
return &discovery.Port{
120+
return &rpc.Port{
123121
Address: address,
124122
Protocol: "serial",
125123
}, nil

‎internal/cli/burnbootloader/burnbootloader.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func runBootloaderCommand(command *cobra.Command, args []string) {
7676
if _, err := upload.BurnBootloader(context.Background(), &rpc.BurnBootloaderRequest{
7777
Instance: instance,
7878
Fqbn: fqbn.String(),
79-
Port: discoveryPort.ToRPC(),
79+
Port: discoveryPort,
8080
Verbose: verbose,
8181
Verify: verify,
8282
Programmer: programmer.String(),

‎internal/cli/upload/upload.go‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424

2525
"github.com/arduino/arduino-cli/arduino"
2626
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
27-
"github.com/arduino/arduino-cli/arduino/sketch"
2827
"github.com/arduino/arduino-cli/commands"
28+
sk "github.com/arduino/arduino-cli/commands/sketch"
2929
"github.com/arduino/arduino-cli/commands/upload"
3030
"github.com/arduino/arduino-cli/i18n"
3131
"github.com/arduino/arduino-cli/internal/cli/arguments"
@@ -90,7 +90,7 @@ func runUploadCommand(command *cobra.Command, args []string) {
9090
arguments.WarnDeprecatedFiles(sketchPath)
9191
}
9292

93-
sk, err := sketch.New(sketchPath)
93+
sketch, err := sk.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
9494
if err != nil && importDir == "" && importFile == "" {
9595
feedback.Fatal(tr("Error during Upload: %v", err), feedback.ErrGeneric)
9696
}
@@ -99,7 +99,7 @@ func runUploadCommand(command *cobra.Command, args []string) {
9999
var profile *rpc.Profile
100100

101101
if profileArg.Get() == "" {
102-
inst, profile = instance.CreateAndInitWithProfile(sk.Project.DefaultProfile, sketchPath)
102+
inst, profile = instance.CreateAndInitWithProfile(sketch.GetDefaultProfile().GetName(), sketchPath)
103103
} else {
104104
inst, profile = instance.CreateAndInitWithProfile(profileArg.Get(), sketchPath)
105105
}
@@ -108,8 +108,9 @@ func runUploadCommand(command *cobra.Command, args []string) {
108108
fqbnArg.Set(profile.GetFqbn())
109109
}
110110

111-
defaultFQBN := sk.GetDefaultFQBN()
112-
defaultAddress, defaultProtocol := sk.GetDefaultPortAddressAndProtocol()
111+
defaultFQBN := sketch.GetDefaultFqbn()
112+
defaultAddress := sketch.GetDefaultPort()
113+
defaultProtocol := sketch.GetDefaultProtocol()
113114
fqbn, port := arguments.CalculateFQBNAndPort(&portArgs, &fqbnArg, inst, defaultFQBN, defaultAddress, defaultProtocol)
114115

115116
userFieldRes, err := upload.SupportedUserFields(context.Background(), &rpc.SupportedUserFieldsRequest{

0 commit comments

Comments
(0)

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