//FIXME it's also resolving previously resolved libraries
func resolveLibraries(includes []string, headerToLibraries map[string][]*types.Library, previousImportedLibraries []*types.Library, platforms []*types.Platform, debugLevel int, logger i18n.Logger) ([]*types.Library, error) {
	markImportedLibrary := make(map[*types.Library]bool)
	for _, header := range includes {
		libraries := headerToLibraries[header]
		if libraries != nil {
			if len(libraries) == 1 {
				markImportedLibrary[libraries[0]] = true
			} else {
				var library *types.Library
				for _, platform := range platforms {
					if platform != nil && library == nil {
						librariesWithinSpecifiedPlatform, err := librariesWithinPlatform(libraries, platform)
						if err != nil {
							return nil, utils.WrapError(err)
						}
						library = findBestLibraryWithHeader(header, librariesWithinSpecifiedPlatform)
					}
				}
				for _, platform := range platforms {
					if platform != nil && library == nil {
						library = findBestLibraryWithHeader(header, librariesCompatibleWithPlatform(libraries, platform))
					}
				}
				if library == nil {
					library = findBestLibraryWithHeader(header, libraries)
				}
				if library == nil {
					library = libraries[0]
				}
				if debugLevel > 0 && !sliceContainsLibrary(previousImportedLibraries, library) {
					logger.Fprintln(os.Stderr, constants.MSG_LIBRARIES_MULTIPLE_LIBS_FOUND_FOR, header)
					logger.Fprintln(os.Stderr, constants.MSG_LIBRARIES_USED, library.Folder)
					for _, notUsedLibrary := range libraries {
						if library != notUsedLibrary {
							logger.Fprintln(os.Stderr, constants.MSG_LIBRARIES_NOT_USED, notUsedLibrary.Folder)
						}
					}
				}
				markImportedLibrary[library] = true
			}
		}
	}

	var importedLibraries []*types.Library
	for library, _ := range markImportedLibrary {
		importedLibraries = append(importedLibraries, library)
	}

	return importedLibraries, nil
}
예제 #2
0
func makeNewLibrary(libraryFolder string, debugLevel int, logger i18n.Logger) (*types.Library, error) {
	properties, err := props.Load(filepath.Join(libraryFolder, constants.LIBRARY_PROPERTIES), logger)
	if err != nil {
		return nil, utils.WrapError(err)
	}

	if properties[constants.LIBRARY_MAINTAINER] == constants.EMPTY_STRING && properties[constants.LIBRARY_EMAIL] != constants.EMPTY_STRING {
		properties[constants.LIBRARY_MAINTAINER] = properties[constants.LIBRARY_EMAIL]
	}

	for _, propName := range LIBRARY_NOT_SO_MANDATORY_PROPERTIES {
		if properties[propName] == constants.EMPTY_STRING {
			properties[propName] = "-"
		}
	}

	library := &types.Library{}
	if stat, err := os.Stat(filepath.Join(libraryFolder, constants.LIBRARY_FOLDER_SRC)); err == nil && stat.IsDir() {
		library.Layout = types.LIBRARY_RECURSIVE
		library.SrcFolder = filepath.Join(libraryFolder, constants.LIBRARY_FOLDER_SRC)
	} else {
		library.Layout = types.LIBRARY_FLAT
		library.SrcFolder = libraryFolder
	}

	subFolders, err := utils.ReadDirFiltered(libraryFolder, utils.FilterDirs)
	if err != nil {
		return nil, utils.WrapError(err)
	}

	if debugLevel > 0 {
		for _, subFolder := range subFolders {
			if utils.IsSCCSOrHiddenFile(subFolder) {
				if !utils.IsSCCSFile(subFolder) && utils.IsHiddenFile(subFolder) {
					logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_WARNING_SPURIOUS_FILE_IN_LIB, filepath.Base(subFolder.Name()), properties[constants.LIBRARY_NAME])
				}
			}
		}
	}

	if properties[constants.LIBRARY_ARCHITECTURES] == constants.EMPTY_STRING {
		properties[constants.LIBRARY_ARCHITECTURES] = constants.LIBRARY_ALL_ARCHS
	}
	library.Archs = []string{}
	for _, arch := range strings.Split(properties[constants.LIBRARY_ARCHITECTURES], ",") {
		library.Archs = append(library.Archs, strings.TrimSpace(arch))
	}

	properties[constants.LIBRARY_CATEGORY] = strings.TrimSpace(properties[constants.LIBRARY_CATEGORY])
	if !LIBRARY_CATEGORIES[properties[constants.LIBRARY_CATEGORY]] {
		logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_WARNING_LIB_INVALID_CATEGORY, properties[constants.LIBRARY_CATEGORY], properties[constants.LIBRARY_NAME], constants.LIB_CATEGORY_UNCATEGORIZED)
		properties[constants.LIBRARY_CATEGORY] = constants.LIB_CATEGORY_UNCATEGORIZED
	}
	library.Category = properties[constants.LIBRARY_CATEGORY]

	if properties[constants.LIBRARY_LICENSE] == constants.EMPTY_STRING {
		properties[constants.LIBRARY_LICENSE] = constants.LIB_LICENSE_UNSPECIFIED
	}
	library.License = properties[constants.LIBRARY_LICENSE]

	library.Folder = libraryFolder
	library.Name = filepath.Base(libraryFolder)
	library.Version = strings.TrimSpace(properties[constants.LIBRARY_VERSION])
	library.Author = strings.TrimSpace(properties[constants.LIBRARY_AUTHOR])
	library.Maintainer = strings.TrimSpace(properties[constants.LIBRARY_MAINTAINER])
	library.Sentence = strings.TrimSpace(properties[constants.LIBRARY_SENTENCE])
	library.Paragraph = strings.TrimSpace(properties[constants.LIBRARY_PARAGRAPH])
	library.URL = strings.TrimSpace(properties[constants.LIBRARY_URL])
	library.IsLegacy = false
	library.DotALinkage = strings.TrimSpace(properties[constants.LIBRARY_DOT_A_LINKAGE]) == "true"
	library.Properties = properties

	return library, nil
}