aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRon Evans <[email protected]>2019-02-23 11:31:38 +0100
committerRon Evans <[email protected]>2019-02-23 11:31:38 +0100
commitacaf0965864a49079d52838c0999be16e8f3f4d5 (patch)
tree5bf9212c73283d918d66ac769645f47c3ae47d26
parent942d4903ce4ad5a4257eed9ba1e7dbee744e18c3 (diff)
downloadtinygo-acaf0965864a49079d52838c0999be16e8f3f4d5.tar.gz
tinygo-acaf0965864a49079d52838c0999be16e8f3f4d5.zip
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]>
-rw-r--r--main.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/main.go b/main.go
index 48ca5c61d..ca0bd2842 100644
--- a/main.go
+++ b/main.go
@@ -318,14 +318,29 @@ func Flash(pkgName, target, port string, config *BuildConfig) error {
return err
}
- return Compile(pkgName, ".hex", spec, config, func(tmppath string) error {
+ // determine the type of file to compile
+ var fileExt string
+
+ switch {
+ case strings.Contains(spec.Flasher, "{hex}"):
+ fileExt = ".hex"
+ case strings.Contains(spec.Flasher, "{elf}"):
+ fileExt = ".elf"
+ case strings.Contains(spec.Flasher, "{bin}"):
+ fileExt = ".bin"
+ default:
+ return errors.New("invalid target file - did you forget the {hex} token in the 'flash' section?")
+ }
+
+ return Compile(pkgName, fileExt, spec, config, func(tmppath string) error {
if spec.Flasher == "" {
return errors.New("no flash command specified - did you miss a -target flag?")
}
// Create the command.
flashCmd := spec.Flasher
- flashCmd = strings.Replace(flashCmd, "{hex}", tmppath, -1)
+ fileToken := "{" + fileExt[1:] + "}"
+ flashCmd = strings.Replace(flashCmd, fileToken, tmppath, -1)
flashCmd = strings.Replace(flashCmd, "{port}", port, -1)
// Execute the command.