Skip to content

Commit

Permalink
Emit a warning if found multiple core for same arch
Browse files Browse the repository at this point in the history
Also try to avoid failure by choosing one randomly (from a user POW this is perfectly acceptable since the erratic behaviour is due to a bug in Board Manager core). The warning reports the full path of the folder for easy copy/paste operations
  • Loading branch information
facchinm committed Aug 12, 2016
1 parent d3c3646 commit 315f22f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/arduino.cc/builder/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ const LOG_LEVEL_INFO = "info"
const LOG_LEVEL_WARN = "warn"
const MSG_ARCH_FOLDER_NOT_SUPPORTED = "'arch' folder is no longer supported! See http://goo.gl/gfFJzU for more information"
const MSG_BOARD_UNKNOWN = "Board {0} (platform {1}, package {2}) is unknown"
const MSG_BOARD_MULTIPLE_CORES = "Folder {0} contains {1} packages for {2} architecture, please manually remove the unwanted ones"
const MSG_BOOTLOADER_FILE_MISSING = "Bootloader file specified but missing: {0}"
const MSG_BUILD_OPTIONS_CHANGED = "Build options changed, rebuilding all"
const MSG_CANT_FIND_SKETCH_IN_PATH = "Unable to find {0} in {1}"
Expand Down
8 changes: 7 additions & 1 deletion src/arduino.cc/builder/hardware_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ package builder
import (
"os"
"path/filepath"
"strconv"

"arduino.cc/builder/constants"
"arduino.cc/builder/i18n"
Expand Down Expand Up @@ -132,11 +133,16 @@ func loadPackage(targetPackage *types.Package, folder string, logger i18n.Logger

_, err := os.Stat(filepath.Join(subfolderPath, constants.FILE_BOARDS_TXT))
if err != nil && os.IsNotExist(err) {
theOnlySubfolder, err := utils.TheOnlySubfolderOf(subfolderPath)
theOnlySubfolder, numSubfolders, err := utils.TheOnlySubfolderOf(subfolderPath)
if err != nil {
return i18n.WrapError(err)
}

if numSubfolders > 1 {
i18n.ErrorfWithLogger(logger, constants.MSG_BOARD_MULTIPLE_CORES,
subfolderPath, strconv.Itoa(numSubfolders), platformId)
}

if theOnlySubfolder != constants.EMPTY_STRING {
subfolderPath = filepath.Join(subfolderPath, theOnlySubfolder)
}
Expand Down
10 changes: 5 additions & 5 deletions src/arduino.cc/builder/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,17 @@ func ReadFileToRows(file string) ([]string, error) {
return strings.Split(txt, "\n"), nil
}

func TheOnlySubfolderOf(folder string) (string, error) {
func TheOnlySubfolderOf(folder string) (string, int, error) {
subfolders, err := ReadDirFiltered(folder, FilterDirs)
if err != nil {
return constants.EMPTY_STRING, i18n.WrapError(err)
return constants.EMPTY_STRING, 0, i18n.WrapError(err)
}

if len(subfolders) != 1 {
return constants.EMPTY_STRING, nil
if len(subfolders) == 0 {
return constants.EMPTY_STRING, 0, nil
}

return subfolders[0].Name(), nil
return subfolders[0].Name(), len(subfolders), nil
}

func FilterOutFoldersByNames(folders []os.FileInfo, names ...string) []os.FileInfo {
Expand Down

0 comments on commit 315f22f

Please sign in to comment.