@@ -21,33 +21,32 @@ import (
21
21
22
22
"github.com/arduino/arduino-cli/arduino/builder/utils"
23
23
"github.com/arduino/arduino-cli/legacy/builder/constants"
24
- "github.com/arduino/arduino-cli/legacy/builder/types"
25
24
"github.com/arduino/go-paths-helper"
26
25
properties "github.com/arduino/go-properties-orderedmap"
27
26
"github.com/pkg/errors"
28
27
)
29
28
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 )
35
37
}
36
- if ctx . BuildOptionsJsonPrevious == "" {
37
- return nil
38
+ if buildOptionsJsonPrevious == "" {
39
+ return "" , nil
38
40
}
39
- buildOptionsJson := ctx .BuildOptionsJson
40
- previousBuildOptionsJson := ctx .BuildOptionsJsonPrevious
41
41
42
42
var opts * properties.Map
43
43
if err := json .Unmarshal ([]byte (buildOptionsJson ), & opts ); err != nil || opts == nil {
44
44
panic (constants .BUILD_OPTIONS_FILE + " is invalid" )
45
45
}
46
46
47
47
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 )
51
50
}
52
51
53
52
// 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 {
61
60
// check if any of the files contained in the core folders has changed
62
61
// since the json was generated - like platform.txt or similar
63
62
// if so, trigger a "safety" wipe
64
- buildProperties := ctx .BuildProperties
65
63
targetCoreFolder := buildProperties .GetPath ("runtime.platform.path" )
66
64
coreFolder := buildProperties .GetPath ("build.core.path" )
67
65
realCoreFolder := coreFolder .Parent ().Parent ()
68
- jsonPath := ctx . BuildPath .Join (constants .BUILD_OPTIONS_FILE )
66
+ jsonPath := buildPath .Join (constants .BUILD_OPTIONS_FILE )
69
67
coreUnchanged , _ := utils .DirContentIsOlderThan (realCoreFolder , jsonPath , ".txt" )
70
68
if coreUnchanged && targetCoreFolder != nil && ! realCoreFolder .EqualsTo (targetCoreFolder ) {
71
69
coreUnchanged , _ = utils .DirContentIsOlderThan (targetCoreFolder , jsonPath , ".txt" )
72
70
}
73
71
if coreUnchanged {
74
- return nil
72
+ return "" , nil
75
73
}
76
74
}
77
75
78
- return doCleanup (ctx . BuildPath )
76
+ return "" , doCleanup (buildPath )
79
77
}
80
78
81
79
func doCleanup (buildPath * paths.Path ) error {
0 commit comments