Skip to content

Commit 297cbb5

Browse files
committed
Wipe anyway if the sketch name has changed
solves arduino/Arduino#4862
1 parent faf42c0 commit 297cbb5

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

Diff for: src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go

+17-7
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ import (
3434
"arduino.cc/builder/gohasissues"
3535
"arduino.cc/builder/i18n"
3636
"arduino.cc/builder/types"
37+
"encoding/json"
3738
"os"
3839
"path/filepath"
39-
"regexp"
4040
)
4141

4242
type WipeoutBuildPathIfBuildOptionsChanged struct{}
@@ -53,13 +53,23 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error {
5353
return nil
5454
}
5555

56-
re := regexp.MustCompile("(?m)^.*" + ctx.SketchLocation + ".*$[\r\n]+")
57-
buildOptionsJson = re.ReplaceAllString(buildOptionsJson, "")
58-
previousBuildOptionsJson = re.ReplaceAllString(previousBuildOptionsJson, "")
56+
// unmarshal jsons and check if every field is equal except SketchLocation
57+
// if SketchLocation path is different but filename is the same, don't wipe
58+
var buildOptions map[string]string
59+
var previousBuildOptions map[string]string
60+
json.Unmarshal([]byte(buildOptionsJson), &buildOptions)
61+
json.Unmarshal([]byte(previousBuildOptionsJson), &previousBuildOptions)
5962

60-
// if the only difference is the sketch path skip deleting everything
61-
if buildOptionsJson == previousBuildOptionsJson {
62-
return nil
63+
for key, _ := range buildOptions {
64+
if buildOptions[key] != previousBuildOptions[key] {
65+
if key == "sketchLocation" {
66+
if filepath.Base(buildOptions[key]) == filepath.Base(previousBuildOptions[key]) {
67+
return nil
68+
}
69+
} else {
70+
break
71+
}
72+
}
6373
}
6474

6575
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_BUILD_OPTIONS_CHANGED)

0 commit comments

Comments
 (0)