作者:andy52
项目:arduino-builde
func getOrCreatePlatform(platforms map[string]*types.Platform, platformId string) *types.Platform {
if _, ok := platforms[platformId]; ok {
return platforms[platformId]
}
targetPlatform := types.Platform{}
targetPlatform.PlatformId = platformId
targetPlatform.Boards = make(map[string]*types.Board)
targetPlatform.Properties = make(map[string]string)
targetPlatform.Programmers = make(map[string]map[string]string)
return &targetPlatform
}
作者:andy52
项目:arduino-builde
func assignDefaultBoardToPlatform(targetPlatform *types.Platform) {
if targetPlatform.DefaultBoard == nil {
for _, board := range targetPlatform.Boards {
if targetPlatform.DefaultBoard == nil {
targetPlatform.DefaultBoard = board
}
}
}
}
作者:me-no-de
项目:arduino-builde
func loadPlatform(targetPlatform *types.Platform, packageId string, folder string, logger i18n.Logger) error {
_, err := os.Stat(filepath.Join(folder, constants.FILE_BOARDS_TXT))
if err != nil && !os.IsNotExist(err) {
return i18n.WrapError(err)
}
if os.IsNotExist(err) {
return nil
}
targetPlatform.Folder = folder
err = loadBoards(targetPlatform.Boards, packageId, targetPlatform.PlatformId, folder, logger)
if err != nil {
return i18n.WrapError(err)
}
assignDefaultBoardToPlatform(targetPlatform)
platformTxt, err := props.SafeLoad(filepath.Join(folder, constants.FILE_PLATFORM_TXT), logger)
if err != nil {
return i18n.WrapError(err)
}
localPlatformProperties, err := props.SafeLoad(filepath.Join(folder, constants.FILE_PLATFORM_LOCAL_TXT), logger)
if err != nil {
return i18n.WrapError(err)
}
targetPlatform.Properties = targetPlatform.Properties.Clone()
targetPlatform.Properties.Merge(platformTxt)
targetPlatform.Properties.Merge(localPlatformProperties)
programmersProperties, err := props.SafeLoad(filepath.Join(folder, constants.FILE_PROGRAMMERS_TXT), logger)
if err != nil {
return i18n.WrapError(err)
}
targetPlatform.Programmers = props.MergeMapsOfProperties(make(map[string]props.PropertiesMap), targetPlatform.Programmers, programmersProperties.FirstLevelOf())
return nil
}