Skip to content

Commit cad8dcb

Browse files
facchinmcmaglie
authored andcommitted
Emit a warning if found multiple core for same arch
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
1 parent 0d042f0 commit cad8dcb

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

constants/constants.go

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ const LOG_LEVEL_WARN = "warn"
152152
const MSG_ARCH_FOLDER_NOT_SUPPORTED = "'arch' folder is no longer supported! See http://goo.gl/gfFJzU for more information"
153153
const MSG_ARCHIVING_CORE_CACHE = "Archiving built core (caching) in: {0}"
154154
const MSG_BOARD_UNKNOWN = "Board {0} (platform {1}, package {2}) is unknown"
155+
const MSG_BOARD_MULTIPLE_CORES = "Folder {0} contains {1} packages for {2} architecture, please manually remove the unwanted ones"
155156
const MSG_BOOTLOADER_FILE_MISSING = "Bootloader file specified but missing: {0}"
156157
const MSG_BUILD_OPTIONS_CHANGED = "Build options changed, rebuilding all"
157158
const MSG_CANT_FIND_SKETCH_IN_PATH = "Unable to find {0} in {1}"

hardware_loader.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ package builder
3232
import (
3333
"os"
3434
"path/filepath"
35+
"strconv"
3536

3637
"github.com/arduino/arduino-builder/constants"
3738
"github.com/arduino/arduino-builder/i18n"
@@ -132,11 +133,16 @@ func loadPackage(targetPackage *types.Package, folder string, logger i18n.Logger
132133

133134
_, err := os.Stat(filepath.Join(subfolderPath, constants.FILE_BOARDS_TXT))
134135
if err != nil && os.IsNotExist(err) {
135-
theOnlySubfolder, err := utils.TheOnlySubfolderOf(subfolderPath)
136+
theOnlySubfolder, numSubfolders, err := utils.TheOnlySubfolderOf(subfolderPath)
136137
if err != nil {
137138
return i18n.WrapError(err)
138139
}
139140

141+
if numSubfolders > 1 {
142+
i18n.ErrorfWithLogger(logger, constants.MSG_BOARD_MULTIPLE_CORES,
143+
subfolderPath, strconv.Itoa(numSubfolders), platformId)
144+
}
145+
140146
if theOnlySubfolder != constants.EMPTY_STRING {
141147
subfolderPath = filepath.Join(subfolderPath, theOnlySubfolder)
142148
}

utils/utils.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -295,17 +295,17 @@ func ReadFileToRows(file string) ([]string, error) {
295295
return strings.Split(txt, "\n"), nil
296296
}
297297

298-
func TheOnlySubfolderOf(folder string) (string, error) {
298+
func TheOnlySubfolderOf(folder string) (string, int, error) {
299299
subfolders, err := ReadDirFiltered(folder, FilterDirs)
300300
if err != nil {
301-
return constants.EMPTY_STRING, i18n.WrapError(err)
301+
return constants.EMPTY_STRING, 0, i18n.WrapError(err)
302302
}
303303

304-
if len(subfolders) != 1 {
305-
return constants.EMPTY_STRING, nil
304+
if len(subfolders) == 0 {
305+
return constants.EMPTY_STRING, 0, nil
306306
}
307307

308-
return subfolders[0].Name(), nil
308+
return subfolders[0].Name(), len(subfolders), nil
309309
}
310310

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

0 commit comments

Comments
 (0)