Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fail if multiple core version are found #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ 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_ARCHIVING_CORE_CACHE = "Archiving built core (caching) in: {0}"
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 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"

"github.com/arduino/arduino-builder/constants"
"github.com/arduino/arduino-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 utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,17 +295,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