From c2b951c885fe26c8b432c74b5c499e8a9f629586 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 20 Apr 2016 10:42:59 +0200 Subject: [PATCH] Wipe anyway if the sketch name has changed solves https://github.com/arduino/Arduino/issues/4862 --- ...out_build_path_if_build_options_changed.go | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go b/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go index e60d6472..f36da9e9 100644 --- a/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go +++ b/src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go @@ -34,9 +34,9 @@ import ( "arduino.cc/builder/gohasissues" "arduino.cc/builder/i18n" "arduino.cc/builder/types" + "encoding/json" "os" "path/filepath" - "regexp" ) type WipeoutBuildPathIfBuildOptionsChanged struct{} @@ -53,13 +53,23 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error { return nil } - re := regexp.MustCompile("(?m)^.*" + ctx.SketchLocation + ".*$[\r\n]+") - buildOptionsJson = re.ReplaceAllString(buildOptionsJson, "") - previousBuildOptionsJson = re.ReplaceAllString(previousBuildOptionsJson, "") + // unmarshal jsons and check if every field is equal except SketchLocation + // if SketchLocation path is different but filename is the same, don't wipe + var buildOptions map[string]string + var previousBuildOptions map[string]string + json.Unmarshal([]byte(buildOptionsJson), &buildOptions) + json.Unmarshal([]byte(previousBuildOptionsJson), &previousBuildOptions) - // if the only difference is the sketch path skip deleting everything - if buildOptionsJson == previousBuildOptionsJson { - return nil + for key, _ := range buildOptions { + if buildOptions[key] != previousBuildOptions[key] { + if key == "sketchLocation" { + if filepath.Base(buildOptions[key]) == filepath.Base(previousBuildOptions[key]) { + return nil + } + } else { + break + } + } } logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_BUILD_OPTIONS_CHANGED)