diff --git a/legacy/builder/container_build_options.go b/legacy/builder/container_build_options.go index 416c69bc7ee..b71a6ef82fe 100644 --- a/legacy/builder/container_build_options.go +++ b/legacy/builder/container_build_options.go @@ -39,13 +39,18 @@ func (s *ContainerBuildOptions) Run(ctx *types.Context) error { } ctx.BuildOptionsJsonPrevious = buildOptionsJsonPrevious - commands := []types.Command{&WipeoutBuildPathIfBuildOptionsChanged{}} - for _, command := range commands { - PrintRingNameIfDebug(ctx, command) - err := command.Run(ctx) - if err != nil { - return errors.WithStack(err) - } + infoOut, err := WipeoutBuildPathIfBuildOptionsChanged( + ctx.Clean, + ctx.BuildPath, + ctx.BuildOptionsJson, + ctx.BuildOptionsJsonPrevious, + ctx.BuildProperties, + ) + if err != nil { + return errors.WithStack(err) + } + if infoOut != "" { + ctx.Info(infoOut) } return StoreBuildOptionsMap(ctx.BuildPath, ctx.BuildOptionsJson) diff --git a/legacy/builder/test/wipeout_build_path_if_build_options_changed_test.go b/legacy/builder/test/wipeout_build_path_if_build_options_changed_test.go index dd72c1926e9..7df448e9b54 100644 --- a/legacy/builder/test/wipeout_build_path_if_build_options_changed_test.go +++ b/legacy/builder/test/wipeout_build_path_if_build_options_changed_test.go @@ -34,14 +34,14 @@ func TestWipeoutBuildPathIfBuildOptionsChanged(t *testing.T) { buildPath.Join("should_be_deleted.txt").Truncate() - commands := []types.Command{ - &builder.WipeoutBuildPathIfBuildOptionsChanged{}, - } - - for _, command := range commands { - err := command.Run(ctx) - require.NoError(t, err) - } + _, err := builder.WipeoutBuildPathIfBuildOptionsChanged( + ctx.Clean, + ctx.BuildPath, + ctx.BuildOptionsJson, + ctx.BuildOptionsJsonPrevious, + ctx.BuildProperties, + ) + require.NoError(t, err) exist, err := buildPath.ExistCheck() require.NoError(t, err) @@ -66,14 +66,14 @@ func TestWipeoutBuildPathIfBuildOptionsChangedNoPreviousBuildOptions(t *testing. require.NoError(t, buildPath.Join("should_not_be_deleted.txt").Truncate()) - commands := []types.Command{ - &builder.WipeoutBuildPathIfBuildOptionsChanged{}, - } - - for _, command := range commands { - err := command.Run(ctx) - require.NoError(t, err) - } + _, err := builder.WipeoutBuildPathIfBuildOptionsChanged( + ctx.Clean, + ctx.BuildPath, + ctx.BuildOptionsJson, + ctx.BuildOptionsJsonPrevious, + ctx.BuildProperties, + ) + require.NoError(t, err) exist, err := buildPath.ExistCheck() require.NoError(t, err) diff --git a/legacy/builder/wipeout_build_path_if_build_options_changed.go b/legacy/builder/wipeout_build_path_if_build_options_changed.go index 72b00b8671a..a4463349145 100644 --- a/legacy/builder/wipeout_build_path_if_build_options_changed.go +++ b/legacy/builder/wipeout_build_path_if_build_options_changed.go @@ -21,23 +21,23 @@ import ( "github.com/arduino/arduino-cli/arduino/builder/utils" "github.com/arduino/arduino-cli/legacy/builder/constants" - "github.com/arduino/arduino-cli/legacy/builder/types" "github.com/arduino/go-paths-helper" properties "github.com/arduino/go-properties-orderedmap" "github.com/pkg/errors" ) -type WipeoutBuildPathIfBuildOptionsChanged struct{} - -func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error { - if ctx.Clean { - return doCleanup(ctx.BuildPath) +func WipeoutBuildPathIfBuildOptionsChanged( + clean bool, + buildPath *paths.Path, + buildOptionsJson, buildOptionsJsonPrevious string, + buildProperties *properties.Map, +) (string, error) { + if clean { + return "", doCleanup(buildPath) } - if ctx.BuildOptionsJsonPrevious == "" { - return nil + if buildOptionsJsonPrevious == "" { + return "", nil } - buildOptionsJson := ctx.BuildOptionsJson - previousBuildOptionsJson := ctx.BuildOptionsJsonPrevious var opts *properties.Map if err := json.Unmarshal([]byte(buildOptionsJson), &opts); err != nil || opts == nil { @@ -45,9 +45,8 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error { } var prevOpts *properties.Map - if err := json.Unmarshal([]byte(previousBuildOptionsJson), &prevOpts); err != nil || prevOpts == nil { - ctx.Info(tr("%[1]s invalid, rebuilding all", constants.BUILD_OPTIONS_FILE)) - return doCleanup(ctx.BuildPath) + if err := json.Unmarshal([]byte(buildOptionsJsonPrevious), &prevOpts); err != nil || prevOpts == nil { + return tr("%[1]s invalid, rebuilding all", constants.BUILD_OPTIONS_FILE), doCleanup(buildPath) } // 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 { // check if any of the files contained in the core folders has changed // since the json was generated - like platform.txt or similar // if so, trigger a "safety" wipe - buildProperties := ctx.BuildProperties targetCoreFolder := buildProperties.GetPath(constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH) coreFolder := buildProperties.GetPath("build.core.path") realCoreFolder := coreFolder.Parent().Parent() - jsonPath := ctx.BuildPath.Join(constants.BUILD_OPTIONS_FILE) + jsonPath := buildPath.Join(constants.BUILD_OPTIONS_FILE) coreUnchanged, _ := utils.DirContentIsOlderThan(realCoreFolder, jsonPath, ".txt") if coreUnchanged && targetCoreFolder != nil && !realCoreFolder.EqualsTo(targetCoreFolder) { coreUnchanged, _ = utils.DirContentIsOlderThan(targetCoreFolder, jsonPath, ".txt") } if coreUnchanged { - return nil + return "", nil } } - return doCleanup(ctx.BuildPath) + return "", doCleanup(buildPath) } func doCleanup(buildPath *paths.Path) error {