Skip to content

Commit acaf096

Browse files
committed
compiler: extend flash command to support different output file types, based on contents of flash key in target file
Signed-off-by: Ron Evans <[email protected]>
1 parent 942d490 commit acaf096

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

main.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,29 @@ func Flash(pkgName, target, port string, config *BuildConfig) error {
318318
return err
319319
}
320320

321-
return Compile(pkgName, ".hex", spec, config, func(tmppath string) error {
321+
// determine the type of file to compile
322+
var fileExt string
323+
324+
switch {
325+
case strings.Contains(spec.Flasher, "{hex}"):
326+
fileExt = ".hex"
327+
case strings.Contains(spec.Flasher, "{elf}"):
328+
fileExt = ".elf"
329+
case strings.Contains(spec.Flasher, "{bin}"):
330+
fileExt = ".bin"
331+
default:
332+
return errors.New("invalid target file - did you forget the {hex} token in the 'flash' section?")
333+
}
334+
335+
return Compile(pkgName, fileExt, spec, config, func(tmppath string) error {
322336
if spec.Flasher == "" {
323337
return errors.New("no flash command specified - did you miss a -target flag?")
324338
}
325339

326340
// Create the command.
327341
flashCmd := spec.Flasher
328-
flashCmd = strings.Replace(flashCmd, "{hex}", tmppath, -1)
342+
fileToken := "{" + fileExt[1:] + "}"
343+
flashCmd = strings.Replace(flashCmd, fileToken, tmppath, -1)
329344
flashCmd = strings.Replace(flashCmd, "{port}", port, -1)
330345

331346
// Execute the command.

0 commit comments

Comments
 (0)