@@ -65,6 +65,7 @@ func Upload(ctx context.Context, req *rpc.UploadRequest, outStream io.Writer, er
65
65
false , // burnBootloader
66
66
outStream ,
67
67
errStream ,
68
+ req .GetDryRun (),
68
69
)
69
70
if err != nil {
70
71
return nil , err
@@ -98,7 +99,8 @@ func runProgramAction(pm *packagemanager.PackageManager,
98
99
importFile , importDir , fqbnIn , port string ,
99
100
programmerID string ,
100
101
verbose , verify , burnBootloader bool ,
101
- outStream , errStream io.Writer ) error {
102
+ outStream , errStream io.Writer ,
103
+ dryRun bool ) error {
102
104
103
105
if burnBootloader && programmerID == "" {
104
106
return fmt .Errorf ("no programmer specified for burning bootloader" )
@@ -308,35 +310,42 @@ func runProgramAction(pm *packagemanager.PackageManager,
308
310
outStream .Write ([]byte (fmt .Sprintln ("Skipping 1200-bps touch reset: no serial port selected!" )))
309
311
}
310
312
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 {
316
317
outStream .Write ([]byte (fmt .Sprintf ("Performing 1200-bps touch reset on serial port %s" , port )))
317
318
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 {
321
324
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 {
324
334
if port != "" {
325
- logrus .WithField ("phase" , "board reset" ).Infof ("Upload port found on %s" , port )
326
335
outStream .Write ([]byte (fmt .Sprintf ("Upload port found on %s" , port )))
327
336
outStream .Write ([]byte (fmt .Sprintln ()))
328
337
} else {
329
- logrus .WithField ("phase" , "board reset" ).Infof ("No upload port found, using %s as fallback" , actualPort )
330
338
outStream .Write ([]byte (fmt .Sprintf ("No upload port found, using %s as fallback" , actualPort )))
331
339
outStream .Write ([]byte (fmt .Sprintln ()))
332
340
}
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
+ },
338
346
}
339
- if newPort , err := serialutils .Reset (portToTouch , wait , cb ); err != nil {
347
+
348
+ if newPort , err := serialutils .Reset (portToTouch , wait , cb , dryRun ); err != nil {
340
349
outStream .Write ([]byte (fmt .Sprintf ("Cannot perform port reset: %s" , err )))
341
350
outStream .Write ([]byte (fmt .Sprintln ()))
342
351
} else {
@@ -358,18 +367,18 @@ func runProgramAction(pm *packagemanager.PackageManager,
358
367
359
368
// Run recipes for upload
360
369
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 {
362
371
return fmt .Errorf ("chip erase error: %s" , err )
363
372
}
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 {
365
374
return fmt .Errorf ("burn bootloader error: %s" , err )
366
375
}
367
376
} 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 {
369
378
return fmt .Errorf ("programming error: %s" , err )
370
379
}
371
380
} 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 {
373
382
return fmt .Errorf ("uploading error: %s" , err )
374
383
}
375
384
}
@@ -378,7 +387,7 @@ func runProgramAction(pm *packagemanager.PackageManager,
378
387
return nil
379
388
}
380
389
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 {
382
391
recipe , ok := props .GetOk (recipeID )
383
392
if ! ok {
384
393
return fmt .Errorf ("recipe not found '%s'" , recipeID )
@@ -396,9 +405,13 @@ func runTool(recipeID string, props *properties.Map, outStream, errStream io.Wri
396
405
}
397
406
398
407
// Run Tool
408
+ logrus .WithField ("phase" , "upload" ).Tracef ("Executing upload tool: %s" , cmdLine )
399
409
if verbose {
400
410
outStream .Write ([]byte (fmt .Sprintln (cmdLine )))
401
411
}
412
+ if dryRun {
413
+ return nil
414
+ }
402
415
cmd , err := executils .NewProcess (cmdArgs ... )
403
416
if err != nil {
404
417
return fmt .Errorf ("cannot execute upload tool: %s" , err )
0 commit comments