38
38
// The .ino files are merged together to create a .cpp file (by the way, the
39
39
// .cpp file still needs to be Arduino-preprocessed to compile).
40
40
func (b * Builder ) PrepareSketchBuildPath (sourceOverrides map [string ]string , buildPath * paths.Path ) (int , error ) {
41
+ if err := buildPath .MkdirAll (); err != nil {
42
+ return 0 , errors .Wrap (err , tr ("unable to create a folder to save the sketch" ))
43
+ }
41
44
if offset , mergedSource , err := sketchMergeSources (b .sketch , sourceOverrides ); err != nil {
42
45
return 0 , err
43
46
} else if err := SketchSaveItemCpp (b .sketch .MainFile , []byte (mergedSource ), buildPath ); err != nil {
@@ -50,13 +53,10 @@ func (b *Builder) PrepareSketchBuildPath(sourceOverrides map[string]string, buil
50
53
}
51
54
52
55
// SketchSaveItemCpp saves a preprocessed .cpp sketch file on disk
53
- func SketchSaveItemCpp (path * paths.Path , contents []byte , destPath * paths.Path ) error {
56
+ func SketchSaveItemCpp (path * paths.Path , contents []byte , buildPath * paths.Path ) error {
54
57
sketchName := path .Base ()
55
- if err := destPath .MkdirAll (); err != nil {
56
- return errors .Wrap (err , tr ("unable to create a folder to save the sketch" ))
57
- }
58
58
59
- destFile := destPath .Join (fmt .Sprintf ("%s.cpp" , sketchName ))
59
+ destFile := buildPath .Join (fmt .Sprintf ("%s.cpp" , sketchName ))
60
60
61
61
if err := destFile .WriteFile (contents ); err != nil {
62
62
return errors .Wrap (err , tr ("unable to save the sketch on disk" ))
@@ -114,18 +114,14 @@ func sketchMergeSources(sk *sketch.Sketch, overrides map[string]string) (int, st
114
114
115
115
// sketchCopyAdditionalFiles copies the additional files for a sketch to the
116
116
// specified destination directory.
117
- func sketchCopyAdditionalFiles (sketch * sketch.Sketch , destPath * paths.Path , overrides map [string ]string ) error {
118
- if err := destPath .MkdirAll (); err != nil {
119
- return errors .Wrap (err , tr ("unable to create a folder to save the sketch files" ))
120
- }
121
-
117
+ func sketchCopyAdditionalFiles (sketch * sketch.Sketch , buildPath * paths.Path , overrides map [string ]string ) error {
122
118
for _ , file := range sketch .AdditionalFiles {
123
119
relpath , err := sketch .FullPath .RelTo (file )
124
120
if err != nil {
125
121
return errors .Wrap (err , tr ("unable to compute relative path to the sketch for the item" ))
126
122
}
127
123
128
- targetPath := destPath .JoinPath (relpath )
124
+ targetPath := buildPath .JoinPath (relpath )
129
125
// create the directory containing the target
130
126
if err = targetPath .Parent ().MkdirAll (); err != nil {
131
127
return errors .Wrap (err , tr ("unable to create the folder containing the item" ))
0 commit comments