@@ -25,6 +25,18 @@ var commands = map[string]string{
25
25
"clang" : "clang-7" ,
26
26
}
27
27
28
+ // commandError is an error type to wrap os/exec.Command errors. This provides
29
+ // some more information regarding what went wrong while running a command.
30
+ type commandError struct {
31
+ Msg string
32
+ File string
33
+ Err error
34
+ }
35
+
36
+ func (e * commandError ) Error () string {
37
+ return e .Msg + " " + e .File + ": " + e .Err .Error ()
38
+ }
39
+
28
40
type BuildConfig struct {
29
41
opt string
30
42
gc string
@@ -200,7 +212,7 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act
200
212
cmd .Dir = sourceDir ()
201
213
err := cmd .Run ()
202
214
if err != nil {
203
- return err
215
+ return & commandError { "failed to build" , path , err }
204
216
}
205
217
ldflags = append (ldflags , outpath )
206
218
}
@@ -216,7 +228,7 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act
216
228
cmd .Dir = sourceDir ()
217
229
err := cmd .Run ()
218
230
if err != nil {
219
- return err
231
+ return & commandError { "failed to build" , path , err }
220
232
}
221
233
ldflags = append (ldflags , outpath )
222
234
}
@@ -229,7 +241,7 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act
229
241
cmd .Dir = sourceDir ()
230
242
err = cmd .Run ()
231
243
if err != nil {
232
- return err
244
+ return & commandError { "failed to link" , executable , err }
233
245
}
234
246
235
247
if config .printSizes == "short" || config .printSizes == "full" {
@@ -263,7 +275,7 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act
263
275
cmd .Stderr = os .Stderr
264
276
err = cmd .Run ()
265
277
if err != nil {
266
- return err
278
+ return & commandError { "failed to extract " + format + " from" , executable , err }
267
279
}
268
280
}
269
281
return action (tmppath )
@@ -325,7 +337,11 @@ func Flash(pkgName, target, port string, config *BuildConfig) error {
325
337
cmd .Stdout = os .Stdout
326
338
cmd .Stderr = os .Stderr
327
339
cmd .Dir = sourceDir ()
328
- return cmd .Run ()
340
+ err := cmd .Run ()
341
+ if err != nil {
342
+ return & commandError {"failed to flash" , tmppath , err }
343
+ }
344
+ return nil
329
345
})
330
346
}
331
347
@@ -392,7 +408,11 @@ func FlashGDB(pkgName, target, port string, ocdOutput bool, config *BuildConfig)
392
408
cmd .Stdin = os .Stdin
393
409
cmd .Stdout = os .Stdout
394
410
cmd .Stderr = os .Stderr
395
- return cmd .Run ()
411
+ err := cmd .Run ()
412
+ if err != nil {
413
+ return & commandError {"failed to run gdb with" , tmppath , err }
414
+ }
415
+ return nil
396
416
})
397
417
}
398
418
@@ -415,8 +435,9 @@ func Run(pkgName, target string, config *BuildConfig) error {
415
435
// Workaround for QEMU which always exits with an error.
416
436
return nil
417
437
}
438
+ return & commandError {"failed to run compiled binary" , tmppath , err }
418
439
}
419
- return err
440
+ return nil
420
441
} else {
421
442
// Run in an emulator.
422
443
args := append (spec .Emulator [1 :], tmppath )
@@ -429,8 +450,9 @@ func Run(pkgName, target string, config *BuildConfig) error {
429
450
// Workaround for QEMU which always exits with an error.
430
451
return nil
431
452
}
453
+ return & commandError {"failed to run emulator with" , tmppath , err }
432
454
}
433
- return err
455
+ return nil
434
456
}
435
457
})
436
458
}
0 commit comments