Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiler: extend flash command to support different output file types #198

Merged
merged 1 commit into from
Feb 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down