Ejemplo n.º 1
0
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
}
Ejemplo n.º 2
0
func assignDefaultBoardToPlatform(targetPlatform *types.Platform) {
	if targetPlatform.DefaultBoard == nil {
		for _, board := range targetPlatform.Boards {
			if targetPlatform.DefaultBoard == nil {
				targetPlatform.DefaultBoard = board
			}
		}
	}
}
Ejemplo n.º 3
0
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
}