Skip to content

Commit 1e235bd

Browse files
committed
compile produce output on the current folder
1 parent 5cc26f3 commit 1e235bd

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

commands/compile/compile.go

+13
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ package compile
3232
import (
3333
"fmt"
3434
"os"
35+
"os/exec"
3536
"path/filepath"
3637
"sort"
3738
"strings"
@@ -230,4 +231,16 @@ func run(cmd *cobra.Command, args []string) {
230231
formatter.PrintError(err, "Compilation failed.")
231232
os.Exit(commands.ErrGeneric)
232233
}
234+
235+
outputPath := ctx.BuildProperties.ExpandPropsInString("{build.path}/{recipe.output.tmp_file}")
236+
ext := filepath.Ext(outputPath)
237+
fqbn = strings.Replace(fqbn, ":", ".", -1)
238+
if err := exec.Command("cp", outputPath, sketch.Name+"."+fqbn+ext).Run(); err != nil {
239+
formatter.PrintError(err, "Error copying output file.")
240+
os.Exit(commands.ErrGeneric)
241+
}
242+
if err := exec.Command("cp", outputPath[:len(outputPath)-3]+"elf", sketch.Name+"."+fqbn+".elf").Run(); err != nil {
243+
formatter.PrintError(err, "Error copying output file.")
244+
os.Exit(commands.ErrGeneric)
245+
}
233246
}

sketches/sketches.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,20 @@ func NewSketchFromCurrentSketchbook(name string) (*sketches.Sketch, error) {
5555
if err != nil {
5656
return nil, err
5757
}
58-
sketch := sketches.Sketch{FullPath: filepath.Join(sketchbookLocation, name)}
58+
sketch := sketches.Sketch{
59+
FullPath: filepath.Join(sketchbookLocation, name),
60+
Name: name,
61+
}
5962
sketch.ImportMetadata()
6063
return &sketch, nil
6164
}
6265

6366
// NewSketchFromPath loads a sketch from the specified path
6467
func NewSketchFromPath(path string) (*sketches.Sketch, error) {
65-
sketch := sketches.Sketch{FullPath: path}
68+
sketch := sketches.Sketch{
69+
FullPath: path,
70+
Name: filepath.Base(path),
71+
}
6672
sketch.ImportMetadata()
6773
return &sketch, nil
6874
}

0 commit comments

Comments
 (0)