@@ -21,33 +21,32 @@ import (
2121
2222 "github.com/arduino/arduino-cli/arduino/builder/utils"
2323 "github.com/arduino/arduino-cli/legacy/builder/constants"
24- "github.com/arduino/arduino-cli/legacy/builder/types"
2524 "github.com/arduino/go-paths-helper"
2625 properties "github.com/arduino/go-properties-orderedmap"
2726 "github.com/pkg/errors"
2827)
2928
30- type WipeoutBuildPathIfBuildOptionsChanged struct {}
31-
32- func (s * WipeoutBuildPathIfBuildOptionsChanged ) Run (ctx * types.Context ) error {
33- if ctx .Clean {
34- return doCleanup (ctx .BuildPath )
29+ func WipeoutBuildPathIfBuildOptionsChanged (
30+ clean bool ,
31+ buildPath * paths.Path ,
32+ buildOptionsJson , buildOptionsJsonPrevious string ,
33+ buildProperties * properties.Map ,
34+ ) (string , error ) {
35+ if clean {
36+ return "" , doCleanup (buildPath )
3537 }
36- if ctx . BuildOptionsJsonPrevious == "" {
37- return nil
38+ if buildOptionsJsonPrevious == "" {
39+ return "" , nil
3840 }
39- buildOptionsJson := ctx .BuildOptionsJson
40- previousBuildOptionsJson := ctx .BuildOptionsJsonPrevious
4141
4242 var opts * properties.Map
4343 if err := json .Unmarshal ([]byte (buildOptionsJson ), & opts ); err != nil || opts == nil {
4444 panic (constants .BUILD_OPTIONS_FILE + " is invalid" )
4545 }
4646
4747 var prevOpts * properties.Map
48- if err := json .Unmarshal ([]byte (previousBuildOptionsJson ), & prevOpts ); err != nil || prevOpts == nil {
49- ctx .Info (tr ("%[1]s invalid, rebuilding all" , constants .BUILD_OPTIONS_FILE ))
50- return doCleanup (ctx .BuildPath )
48+ if err := json .Unmarshal ([]byte (buildOptionsJsonPrevious ), & prevOpts ); err != nil || prevOpts == nil {
49+ return tr ("%[1]s invalid, rebuilding all" , constants .BUILD_OPTIONS_FILE ), doCleanup (buildPath )
5150 }
5251
5352 // If SketchLocation path is different but filename is the same, consider it equal
@@ -61,21 +60,20 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error {
6160 // check if any of the files contained in the core folders has changed
6261 // since the json was generated - like platform.txt or similar
6362 // if so, trigger a "safety" wipe
64- buildProperties := ctx .BuildProperties
6563 targetCoreFolder := buildProperties .GetPath (constants .BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH )
6664 coreFolder := buildProperties .GetPath ("build.core.path" )
6765 realCoreFolder := coreFolder .Parent ().Parent ()
68- jsonPath := ctx . BuildPath .Join (constants .BUILD_OPTIONS_FILE )
66+ jsonPath := buildPath .Join (constants .BUILD_OPTIONS_FILE )
6967 coreUnchanged , _ := utils .DirContentIsOlderThan (realCoreFolder , jsonPath , ".txt" )
7068 if coreUnchanged && targetCoreFolder != nil && ! realCoreFolder .EqualsTo (targetCoreFolder ) {
7169 coreUnchanged , _ = utils .DirContentIsOlderThan (targetCoreFolder , jsonPath , ".txt" )
7270 }
7371 if coreUnchanged {
74- return nil
72+ return "" , nil
7573 }
7674 }
7775
78- return doCleanup (ctx . BuildPath )
76+ return "" , doCleanup (buildPath )
7977}
8078
8179func doCleanup (buildPath * paths.Path ) error {
0 commit comments