Skip to content

Commit

Permalink
Don't fail if multiple core version are found
Browse files Browse the repository at this point in the history
use the latest one based on semver
a dependency was added (github.com/blang/semver), hopefully we'll use it somwhere else since it's really useful

Signed-off-by: Martino Facchin <[email protected]>
  • Loading branch information
facchinm committed Dec 16, 2015
1 parent db653b2 commit cc60774
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 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 @@ -213,6 +213,7 @@ const MSG_CANT_FIND_SKETCH_IN_PATH = "Unable to find {0} in {1}"
const MSG_INVALID_QUOTING = "Invalid quoting: no closing [{0}] char found."
const MSG_LIB_LEGACY = "(legacy)"
const MSG_LIBRARIES_MULTIPLE_LIBS_FOUND_FOR = "Multiple libraries were found for \"{0}\""
const MSG_CORES_MULTIPLE_CORES_FOUND_FOR = "Multiple versions of {0} core were found, using {1}"
const MSG_LIBRARIES_NOT_USED = " Not used: {0}"
const MSG_LIBRARIES_USED = " Used: {0}"
const MSG_LIBRARY_CAN_USE_SRC_AND_UTILITY_FOLDERS = "Library can't use both 'src' and 'utility' folders. Double check {0}"
Expand Down
13 changes: 9 additions & 4 deletions src/arduino.cc/builder/hardware_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (s *HardwareLoader) Run(context map[string]interface{}) error {
}

targetPackage := getOrCreatePackage(packages, packageId)
err = loadPackage(targetPackage, subfolderPath, logger)
err = loadPackage(targetPackage, subfolderPath, logger, context)
if err != nil {
return utils.WrapError(err)
}
Expand All @@ -110,7 +110,7 @@ func getOrCreatePackage(packages *types.Packages, packageId string) *types.Packa
return &targetPackage
}

func loadPackage(targetPackage *types.Package, folder string, logger i18n.Logger) error {
func loadPackage(targetPackage *types.Package, folder string, logger i18n.Logger, context map[string]interface{}) error {
packagePlatformTxt, err := props.SafeLoad(filepath.Join(folder, constants.FILE_PLATFORM_TXT), logger)
if err != nil {
return utils.WrapError(err)
Expand All @@ -131,9 +131,14 @@ 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, err := utils.TheBestSubfolderOf(subfolderPath)
if err != nil {
return utils.WrapError(err)
if theOnlySubfolder != constants.EMPTY_STRING {
logger := context[constants.CTX_LOGGER].(i18n.Logger)
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_CORES_MULTIPLE_CORES_FOUND_FOR, platformId, err.Error())
} else {
return utils.WrapError(err)
}
}

if theOnlySubfolder != constants.EMPTY_STRING {
Expand Down
21 changes: 17 additions & 4 deletions src/arduino.cc/builder/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"arduino.cc/builder/types"
"crypto/md5"
"encoding/hex"
"github.com/blang/semver"
"github.com/go-errors/errors"
"io/ioutil"
"os"
Expand Down Expand Up @@ -358,17 +359,29 @@ func ReadFileToRows(file string) ([]string, error) {
return strings.Split(txt, "\n"), nil
}

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

if len(subfolders) != 1 {
if len(subfolders) > 0 {
latest, _ := semver.Make(subfolders[0].Name())
latest_index := 0
for i, _ := range subfolders {
test, _ := semver.Make(subfolders[i].Name())
if test.GT(latest) {
latest = test
latest_index = i
}
}
if len(subfolders) > 1 {
err = errors.New(subfolders[latest_index].Name())
}
return subfolders[latest_index].Name(), err
} else {
return constants.EMPTY_STRING, nil
}

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

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

0 comments on commit cc60774

Please sign in to comment.