mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-18 11:33:59 +00:00
compiler: extend flash command to support different output file types, based on contents of flash key in target file
Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
@@ -318,14 +318,29 @@ func Flash(pkgName, target, port string, config *BuildConfig) error {
|
|||||||
return err
|
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 == "" {
|
if spec.Flasher == "" {
|
||||||
return errors.New("no flash command specified - did you miss a -target flag?")
|
return errors.New("no flash command specified - did you miss a -target flag?")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the command.
|
// Create the command.
|
||||||
flashCmd := spec.Flasher
|
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)
|
flashCmd = strings.Replace(flashCmd, "{port}", port, -1)
|
||||||
|
|
||||||
// Execute the command.
|
// Execute the command.
|
||||||
|
|||||||
Reference in New Issue
Block a user