Skip to content

Commit 6724540

Browse files
committed
Removed sketch name from regexp. Do not full-rebuild if only sketch path changed.
This commit fix two problems: 1) the sketch path is used as-is in a regexp: this causes troubles if the path contains regexp control chars like `[-]().\` etc. 2) the sketch is not fully rebuild if the only thing that changes is the sketch path. Signed-off-by: Cristian Maglie <[email protected]>
1 parent 4e56760 commit 6724540

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

Diff for: src/arduino.cc/builder/props/properties.go

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/go-errors/errors"
3636
"io/ioutil"
3737
"os"
38+
"reflect"
3839
"regexp"
3940
"runtime"
4041
"strings"
@@ -170,6 +171,10 @@ func (aMap PropertiesMap) Clone() PropertiesMap {
170171
return newMap
171172
}
172173

174+
func (aMap PropertiesMap) Equals(anotherMap PropertiesMap) bool {
175+
return reflect.DeepEqual(aMap, anotherMap)
176+
}
177+
173178
func MergeMapsOfProperties(target map[string]PropertiesMap, sources ...map[string]PropertiesMap) map[string]PropertiesMap {
174179
for _, source := range sources {
175180
for key, value := range source {

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

+12-9
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ import (
3333
"arduino.cc/builder/constants"
3434
"arduino.cc/builder/gohasissues"
3535
"arduino.cc/builder/i18n"
36+
"arduino.cc/builder/props"
3637
"arduino.cc/builder/types"
38+
"encoding/json"
3739
"os"
3840
"path/filepath"
39-
"regexp"
4041
)
4142

4243
type WipeoutBuildPathIfBuildOptionsChanged struct{}
@@ -49,16 +50,18 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error {
4950
previousBuildOptionsJson := ctx.BuildOptionsJsonPrevious
5051
logger := ctx.GetLogger()
5152

52-
if buildOptionsJson == previousBuildOptionsJson {
53-
return nil
54-
}
53+
var opts props.PropertiesMap
54+
var prevOpts props.PropertiesMap
55+
json.Unmarshal([]byte(buildOptionsJson), &opts)
56+
json.Unmarshal([]byte(previousBuildOptionsJson), &prevOpts)
5557

56-
re := regexp.MustCompile("(?m)^.*" + ctx.SketchLocation + ".*$[\r\n]+")
57-
buildOptionsJson = re.ReplaceAllString(buildOptionsJson, "")
58-
previousBuildOptionsJson = re.ReplaceAllString(previousBuildOptionsJson, "")
58+
// If SketchLocation path is different but filename is the same, consider it equal
59+
if filepath.Base(opts["sketchLocation"]) == filepath.Base(prevOpts["sketchLocation"]) {
60+
delete(opts, "sketchLocation")
61+
delete(prevOpts, "sketchLocation")
62+
}
5963

60-
// if the only difference is the sketch path skip deleting everything
61-
if buildOptionsJson == previousBuildOptionsJson {
64+
if opts.Equals(prevOpts) {
6265
return nil
6366
}
6467

0 commit comments

Comments
 (0)