Skip to content

Commit

Permalink
Always return an updatedUploadPort.
Browse files Browse the repository at this point in the history
Arduino CLI should always return the port after an upload, even in the case
where no port change is expected. The consumer shouldn't be required to
implement "if not updated_upload_port, use original port" logic.

The whole point is that all the logic for determining which port should be
selected after an upload should be implemented in Arduino CLI. The consumer
should be able to simply select the port Arduino CLI tells it to select in
all cases.
  • Loading branch information
cmaglie committed Aug 9, 2023
1 parent 9f8d266 commit 5896fba
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions commands/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func UsingProgrammer(ctx context.Context, req *rpc.UploadUsingProgrammerRequest,
func runProgramAction(pme *packagemanager.Explorer,
sk *sketch.Sketch,
watch <-chan *rpc.BoardListWatchResponse,
importFile, importDir, fqbnIn string, port *rpc.Port,
importFile, importDir, fqbnIn string, userPort *rpc.Port,
programmerID string,
verbose, verify, burnBootloader bool,
outStream, errStream io.Writer,
Expand All @@ -212,6 +212,7 @@ func runProgramAction(pme *packagemanager.Explorer,
go f.DiscardCh(watch)
}()

port := userPort
if port == nil || (port.Address == "" && port.Protocol == "") {
// For no-port uploads use "default" protocol
port = &rpc.Port{Protocol: "default"}
Expand Down Expand Up @@ -519,7 +520,11 @@ func runProgramAction(pme *packagemanager.Explorer,
uploadCompleted()
logrus.Tracef("Upload successful")

return updatedUploadPort.Await(), nil
updatedPort := updatedUploadPort.Await()
if updatedPort == nil {
updatedPort = userPort
}
return userPort, nil
}

func detectUploadPort(uploadCtx context.Context, uploadPort *rpc.Port, watch <-chan *rpc.BoardListWatchResponse, result f.Future[*rpc.Port]) {
Expand Down

0 comments on commit 5896fba

Please sign in to comment.