Skip to content

Commit 5856a16

Browse files
committed
Ensure that no spurious file is added to AdditionalFiles
If the build is executed "in place" (inside the sketch folder) intermediate cpp files were added to the AdditionaFiles list. This was solved (badly) in 849faa1#diff-b54df391d234f64238253f1d968e2e39R89 . This patch fixes the issue by not including these files in the list in the first place, so we can avoid removing them later.
1 parent 2ca23f1 commit 5856a16

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

sketch_loader.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (s *SketchLoader) Run(ctx *types.Context) error {
7676
return i18n.ErrorfWithLogger(logger, constants.MSG_CANT_FIND_SKETCH_IN_PATH, sketchLocation, filepath.Dir(sketchLocation))
7777
}
7878

79-
sketch, err := makeSketch(sketchLocation, allSketchFilePaths, logger)
79+
sketch, err := makeSketch(sketchLocation, allSketchFilePaths, ctx.BuildPath, logger)
8080
if err != nil {
8181
return i18n.WrapError(err)
8282
}
@@ -100,7 +100,7 @@ func collectAllSketchFiles(from string) ([]string, error) {
100100
return filePaths, i18n.WrapError(err)
101101
}
102102

103-
func makeSketch(sketchLocation string, allSketchFilePaths []string, logger i18n.Logger) (*types.Sketch, error) {
103+
func makeSketch(sketchLocation string, allSketchFilePaths []string, buildLocation string, logger i18n.Logger) (*types.Sketch, error) {
104104
sketchFilesMap := make(map[string]types.SketchFile)
105105
for _, sketchFilePath := range allSketchFilePaths {
106106
source, err := ioutil.ReadFile(sketchFilePath)
@@ -123,7 +123,9 @@ func makeSketch(sketchLocation string, allSketchFilePaths []string, logger i18n.
123123
otherSketchFiles = append(otherSketchFiles, sketchFile)
124124
}
125125
} else if ADDITIONAL_FILE_VALID_EXTENSIONS[ext] {
126-
additionalFiles = append(additionalFiles, sketchFile)
126+
if !strings.Contains(filepath.Dir(sketchFile.Name), buildLocation) {
127+
additionalFiles = append(additionalFiles, sketchFile)
128+
}
127129
} else {
128130
return nil, i18n.ErrorfWithLogger(logger, constants.MSG_UNKNOWN_SKETCH_EXT, sketchFile.Name)
129131
}

wipeout_build_path_if_build_options_changed.go

-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
"encoding/json"
3434
"os"
3535
"path/filepath"
36-
"strings"
3736

3837
"github.com/arduino/arduino-builder/builder_utils"
3938
"github.com/arduino/arduino-builder/constants"
@@ -86,10 +85,6 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error {
8685
if err != nil {
8786
return i18n.WrapError(err)
8887
}
89-
// if build path is inside the sketch folder, also wipe ctx.AdditionalFiles
90-
if strings.Contains(ctx.BuildPath, filepath.Dir(ctx.SketchLocation)) {
91-
ctx.Sketch.AdditionalFiles = ctx.Sketch.AdditionalFiles[:0]
92-
}
9388
for _, file := range files {
9489
os.RemoveAll(filepath.Join(buildPath, file.Name()))
9590
}

0 commit comments

Comments
 (0)