@@ -65,6 +65,7 @@ func Upload(ctx context.Context, req *rpc.UploadRequest, outStream io.Writer, er
6565 false , // burnBootloader
6666 outStream ,
6767 errStream ,
68+ req .GetDryRun (),
6869 )
6970 if err != nil {
7071 return nil , err
@@ -98,7 +99,8 @@ func runProgramAction(pm *packagemanager.PackageManager,
9899 importFile , importDir , fqbnIn , port string ,
99100 programmerID string ,
100101 verbose , verify , burnBootloader bool ,
101- outStream , errStream io.Writer ) error {
102+ outStream , errStream io.Writer ,
103+ dryRun bool ) error {
102104
103105 if burnBootloader && programmerID == "" {
104106 return fmt .Errorf ("no programmer specified for burning bootloader" )
@@ -308,35 +310,42 @@ func runProgramAction(pm *packagemanager.PackageManager,
308310 outStream .Write ([]byte (fmt .Sprintln ("Skipping 1200-bps touch reset: no serial port selected!" )))
309311 }
310312
311- var cb * serialutils.ResetProgressCallbacks
312- if verbose {
313- cb = & serialutils.ResetProgressCallbacks {
314- TouchingPort : func (port string ) {
315- logrus .WithField ("phase" , "board reset" ).Infof ("Performing 1200-bps touch reset on serial port %s" , port )
313+ cb := & serialutils.ResetProgressCallbacks {
314+ TouchingPort : func (port string ) {
315+ logrus .WithField ("phase" , "board reset" ).Infof ("Performing 1200-bps touch reset on serial port %s" , port )
316+ if verbose {
316317 outStream .Write ([]byte (fmt .Sprintf ("Performing 1200-bps touch reset on serial port %s" , port )))
317318 outStream .Write ([]byte (fmt .Sprintln ()))
318- },
319- WaitingForNewSerial : func () {
320- logrus .WithField ("phase" , "board reset" ).Info ("Waiting for upload port..." )
319+ }
320+ },
321+ WaitingForNewSerial : func () {
322+ logrus .WithField ("phase" , "board reset" ).Info ("Waiting for upload port..." )
323+ if verbose {
321324 outStream .Write ([]byte (fmt .Sprintln ("Waiting for upload port..." )))
322- },
323- BootloaderPortFound : func (port string ) {
325+ }
326+ },
327+ BootloaderPortFound : func (port string ) {
328+ if port != "" {
329+ logrus .WithField ("phase" , "board reset" ).Infof ("Upload port found on %s" , port )
330+ } else {
331+ logrus .WithField ("phase" , "board reset" ).Infof ("No upload port found, using %s as fallback" , actualPort )
332+ }
333+ if verbose {
324334 if port != "" {
325- logrus .WithField ("phase" , "board reset" ).Infof ("Upload port found on %s" , port )
326335 outStream .Write ([]byte (fmt .Sprintf ("Upload port found on %s" , port )))
327336 outStream .Write ([]byte (fmt .Sprintln ()))
328337 } else {
329- logrus .WithField ("phase" , "board reset" ).Infof ("No upload port found, using %s as fallback" , actualPort )
330338 outStream .Write ([]byte (fmt .Sprintf ("No upload port found, using %s as fallback" , actualPort )))
331339 outStream .Write ([]byte (fmt .Sprintln ()))
332340 }
333- },
334- Debug : func ( msg string ) {
335- logrus . WithField ( "phase" , "board reset" ). Debug (msg )
336- },
337- }
341+ }
342+ },
343+ Debug : func (msg string ) {
344+ logrus . WithField ( "phase" , "board reset" ). Debug ( msg )
345+ },
338346 }
339- if newPort , err := serialutils .Reset (portToTouch , wait , cb ); err != nil {
347+
348+ if newPort , err := serialutils .Reset (portToTouch , wait , cb , dryRun ); err != nil {
340349 outStream .Write ([]byte (fmt .Sprintf ("Cannot perform port reset: %s" , err )))
341350 outStream .Write ([]byte (fmt .Sprintln ()))
342351 } else {
@@ -358,18 +367,18 @@ func runProgramAction(pm *packagemanager.PackageManager,
358367
359368 // Run recipes for upload
360369 if burnBootloader {
361- if err := runTool ("erase.pattern" , uploadProperties , outStream , errStream , verbose ); err != nil {
370+ if err := runTool ("erase.pattern" , uploadProperties , outStream , errStream , verbose , dryRun ); err != nil {
362371 return fmt .Errorf ("chip erase error: %s" , err )
363372 }
364- if err := runTool ("bootloader.pattern" , uploadProperties , outStream , errStream , verbose ); err != nil {
373+ if err := runTool ("bootloader.pattern" , uploadProperties , outStream , errStream , verbose , dryRun ); err != nil {
365374 return fmt .Errorf ("burn bootloader error: %s" , err )
366375 }
367376 } else if programmer != nil {
368- if err := runTool ("program.pattern" , uploadProperties , outStream , errStream , verbose ); err != nil {
377+ if err := runTool ("program.pattern" , uploadProperties , outStream , errStream , verbose , dryRun ); err != nil {
369378 return fmt .Errorf ("programming error: %s" , err )
370379 }
371380 } else {
372- if err := runTool ("upload.pattern" , uploadProperties , outStream , errStream , verbose ); err != nil {
381+ if err := runTool ("upload.pattern" , uploadProperties , outStream , errStream , verbose , dryRun ); err != nil {
373382 return fmt .Errorf ("uploading error: %s" , err )
374383 }
375384 }
@@ -378,7 +387,7 @@ func runProgramAction(pm *packagemanager.PackageManager,
378387 return nil
379388}
380389
381- func runTool (recipeID string , props * properties.Map , outStream , errStream io.Writer , verbose bool ) error {
390+ func runTool (recipeID string , props * properties.Map , outStream , errStream io.Writer , verbose bool , dryRun bool ) error {
382391 recipe , ok := props .GetOk (recipeID )
383392 if ! ok {
384393 return fmt .Errorf ("recipe not found '%s'" , recipeID )
@@ -396,9 +405,13 @@ func runTool(recipeID string, props *properties.Map, outStream, errStream io.Wri
396405 }
397406
398407 // Run Tool
408+ logrus .WithField ("phase" , "upload" ).Tracef ("Executing upload tool: %s" , cmdLine )
399409 if verbose {
400410 outStream .Write ([]byte (fmt .Sprintln (cmdLine )))
401411 }
412+ if dryRun {
413+ return nil
414+ }
402415 cmd , err := executils .NewProcess (cmdArgs ... )
403416 if err != nil {
404417 return fmt .Errorf ("cannot execute upload tool: %s" , err )
0 commit comments