Skip to content

Commit e94d28e

Browse files
committed
add check to buildOptionsJson too
1 parent 922eb68 commit e94d28e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

legacy/builder/constants/constants.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ const MSG_ERROR_ARCHIVING_CORE_CACHE = "Error archiving built core (caching) in
8686
const MSG_CORE_CACHE_UNAVAILABLE = "Unable to cache built core, please tell {0} maintainers to follow http://goo.gl/QdCUjo"
8787
const MSG_BOARD_UNKNOWN = "Board {0} (platform {1}, package {2}) is unknown"
8888
const MSG_BOOTLOADER_FILE_MISSING = "Bootloader file specified but missing: {0}"
89-
const MSG_BUILD_OPTIONS_CHANGED = "Build options changed, rebuilding all"
90-
const MSG_BUILD_OPTIONS_INVALID = "{0} invalid, rebuilding all"
89+
const MSG_REBUILD_ALL = ", rebuilding all"
90+
const MSG_BUILD_OPTIONS_CHANGED = "Build options changed"
91+
const MSG_BUILD_OPTIONS_INVALID = "{0} invalid"
9192
const MSG_CANT_FIND_SKETCH_IN_PATH = "Unable to find {0} in {1}"
9293
const MSG_FQBN_INVALID = "{0} is not a valid fully qualified board name. Required format is targetPackageName:targetPlatformName:targetBoardName."
9394
const MSG_FIND_INCLUDES_FAILED = "Error while detecting libraries included by {0}"

legacy/builder/wipeout_build_path_if_build_options_changed.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ package builder
1818
import (
1919
"encoding/json"
2020
"path/filepath"
21+
"os"
2122

23+
"github.com/arduino/arduino-cli/cli/errorcodes"
2224
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
2325
"github.com/arduino/arduino-cli/legacy/builder/constants"
2426
"github.com/arduino/arduino-cli/legacy/builder/types"
@@ -40,11 +42,14 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error {
4042
previousBuildOptionsJson := ctx.BuildOptionsJsonPrevious
4143

4244
var opts *properties.Map
43-
json.Unmarshal([]byte(buildOptionsJson), &opts)
45+
if err := json.Unmarshal([]byte(buildOptionsJson), &opts); err != nil || opts == nil {
46+
ctx.GetLogger().Println(constants.LOG_LEVEL_DEBUG, constants.MSG_BUILD_OPTIONS_INVALID, constants.BUILD_OPTIONS_FILE)
47+
os.Exit(errorcodes.ErrGeneric)
48+
}
4449

4550
var prevOpts *properties.Map
4651
if err := json.Unmarshal([]byte(previousBuildOptionsJson), &prevOpts); err != nil || prevOpts == nil {
47-
ctx.GetLogger().Println(constants.LOG_LEVEL_DEBUG, constants.MSG_BUILD_OPTIONS_INVALID, constants.BUILD_OPTIONS_FILE)
52+
ctx.GetLogger().Println(constants.LOG_LEVEL_DEBUG, constants.MSG_BUILD_OPTIONS_INVALID + constants.MSG_REBUILD_ALL, constants.BUILD_OPTIONS_FILE)
4853
return doCleanup(ctx.BuildPath)
4954
}
5055

@@ -77,7 +82,7 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error {
7782
func doCleanup(buildPath *paths.Path) error {
7883
// FIXME: this should go outside legacy and behind a `logrus` call so users can
7984
// control when this should be printed.
80-
// logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_BUILD_OPTIONS_CHANGED)
85+
// logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_BUILD_OPTIONS_CHANGED + MSG_REBUILD_ALL)
8186

8287
if files, err := buildPath.ReadDir(); err != nil {
8388
return errors.WithMessage(err, "cleaning build path")

0 commit comments

Comments
 (0)