Skip to content

Commit 9cec567

Browse files
committed
builder: renamed variable and moved dir creation up
1 parent 0dfdc38 commit 9cec567

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

arduino/builder/sketch.go

+7-11
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ var (
3838
// The .ino files are merged together to create a .cpp file (by the way, the
3939
// .cpp file still needs to be Arduino-preprocessed to compile).
4040
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+
}
4144
if offset, mergedSource, err := sketchMergeSources(b.sketch, sourceOverrides); err != nil {
4245
return 0, err
4346
} 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
5053
}
5154

5255
// 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 {
5457
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-
}
5858

59-
destFile := destPath.Join(fmt.Sprintf("%s.cpp", sketchName))
59+
destFile := buildPath.Join(fmt.Sprintf("%s.cpp", sketchName))
6060

6161
if err := destFile.WriteFile(contents); err != nil {
6262
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
114114

115115
// sketchCopyAdditionalFiles copies the additional files for a sketch to the
116116
// 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 {
122118
for _, file := range sketch.AdditionalFiles {
123119
relpath, err := sketch.FullPath.RelTo(file)
124120
if err != nil {
125121
return errors.Wrap(err, tr("unable to compute relative path to the sketch for the item"))
126122
}
127123

128-
targetPath := destPath.JoinPath(relpath)
124+
targetPath := buildPath.JoinPath(relpath)
129125
// create the directory containing the target
130126
if err = targetPath.Parent().MkdirAll(); err != nil {
131127
return errors.Wrap(err, tr("unable to create the folder containing the item"))

0 commit comments

Comments
 (0)