def CreateUserTag(self, baseConfig: BaseConfig) -> Optional[object]:
        templateRootPaths = GetTemplatePaths(baseConfig.ToolConfig)
        subDirs = []  # type: List[str]
        for entry in templateRootPaths:
            subDirs += IOUtil.GetDirectoriesAt(entry.ResolvedPath, True)

        templates = {}  # type: Dict[str, List[XmlNewTemplateFile]]
        for currentDir in subDirs:
            languageDir = IOUtil.GetFileName(currentDir)
            dirs = IOUtil.GetDirectoriesAt(currentDir, True)
            for possibleDir in dirs:
                templatePath = IOUtil.Join(possibleDir, g_templateFileName)
                if IOUtil.IsFile(templatePath):
                    if not languageDir in templates:
                        templates[languageDir] = []
                    xmlNewTemplateFile = XmlNewTemplateFile(baseConfig, templatePath)
                    existingTemplateFile = TryFind(templates[languageDir], xmlNewTemplateFile)
                    if existingTemplateFile is None:
                        templates[languageDir].append(xmlNewTemplateFile)
                    else:
                        raise Exception("Duplicated template name '{0}' found at '{1}' and '{2}'".format(xmlNewTemplateFile.Name, xmlNewTemplateFile.Path, existingTemplateFile.Path))

        # sort the templates
        for listEntry in templates.values():
            listEntry.sort(key=lambda s: s.Name.lower())

        removeKeys = [key for key in templates if len(templates[key]) <= 0]
        for key in removeKeys:
            templates.pop(key)
        return templates
Beispiel #2
0
    def __init__(self, log: Log, platformName: str, vsVersion: int,
                 languageTemplates: VSVersionLanguageTemplates,
                 activeTemplate: str, sdkConfigTemplatePath: str) -> None:
        super().__init__()
        self.__TemplateExecutablePrefix = "Executable"
        self.__TemplateLibraryPrefix = "Library"

        self.UsingLinuxTools = (
            platformName != PackageConfig.PlatformNameString.WINDOWS
        ) and activeTemplate == MagicStrings.VSDefaultCPPTemplate
        if self.UsingLinuxTools:
            activeTemplate = MagicStrings.VSDefaultCPPLinuxTemplate

        template = languageTemplates.TryGet(activeTemplate)
        if template is None:
            raise UnsupportedException(
                "No template found for '{0}' named '{1}'".format(
                    PackageLanguage.ToString(
                        languageTemplates.PackageLanguage), activeTemplate))

        # ScanForTemplates
        templateDirectories = IOUtil.GetDirectoriesAt(template.Path, False)
        self.__ExecutableTemplateDict = self.__BuildTemplateDict(
            templateDirectories, self.__TemplateExecutablePrefix, log,
            template, vsVersion, self.UsingLinuxTools)
        self.__LibraryTemplateDict = self.__BuildTemplateDict(
            templateDirectories, self.__TemplateLibraryPrefix, log, template,
            vsVersion, self.UsingLinuxTools)

        self.__Bat = CodeTemplateProjectBatFiles(log, sdkConfigTemplatePath)
        self.__HeaderLib = self.__LoadHeaderLib(log, template, vsVersion,
                                                self.UsingLinuxTools)
Beispiel #3
0
    def __BuildCompilerFileDict(self, basePath: str) -> Dict[str, List[str]]:
        compilerDependentFilePath = IOUtil.Join(basePath, "CompilerId")
        if not IOUtil.IsDirectory(compilerDependentFilePath):
            return dict()
        foundDirs = IOUtil.GetDirectoriesAt(compilerDependentFilePath, False)
        if len(foundDirs) <= 0:
            return dict()

        result = dict() # type: Dict[str, List[str]]
        for dirName in foundDirs:
            absDirName = IOUtil.Join(compilerDependentFilePath, dirName)
            foundFiles = IOUtil.GetFilesAt(absDirName, True)
            if len(foundFiles) > 0:
                result[dirName] = foundFiles
        return result
Beispiel #4
0
 def __ScanDir(self, path: str) -> List[str]:
     return IOUtil.GetDirectoriesAt(path, True)
Beispiel #5
0
    def __CacheLocation(self, rScannedPathsCacheSet: Set[str],
                        rLocationDict: Dict[str, PackageLocationCacheRecord],
                        locationPackageName: str,
                        sourcePath: str,
                        scanMethod: int,
                        sourceLocation: ToolConfigPackageLocation,
                        rNewLocations: Optional[List[PackageLocationCachePath]] = None) -> None:
        # if rNewLocations is not None all new locations we find will be added to this list
        # Prevent multiple scannings of the same path
        if sourcePath in rScannedPathsCacheSet:
            return
        rScannedPathsCacheSet.add(sourcePath)

        directories = IOUtil.GetDirectoriesAt(sourcePath, False)
        directories.sort()

        for dirEntry in directories:
            if not Util.IsValidPackageName(dirEntry, True):
                if self.Log.Verbosity >= 4:
                    self.Log.LogPrint("Ignored directory '{0}' at '{1}' as it was not a valid package name".format(dirEntry, IOUtil.Join(sourcePath, dirEntry)))
                continue
            absoluteDirPath = IOUtil.Join(sourcePath, dirEntry)
            if absoluteDirPath in self.__RootLocationPaths:
                if self.Log.Verbosity >= g_verbosityMaxLevel:
                    self.Log.LogPrint("Not scanning '{0}' as a child of '{1}' since it is a root location".format(absoluteDirPath, sourceLocation.ResolvedPath))
                continue
            if self.__IsBlacklisted(absoluteDirPath, sourceLocation.Blacklist):
                if self.Log.Verbosity >= g_verbosityMaxLevel:
                    self.Log.LogPrint("Not scanning '{0}' as it was blacklisted".format(absoluteDirPath))
                continue

            # This is not a original location path, so we can cache it as a 'child' of this location
            directoryLocationPackageName = locationPackageName + dirEntry
            absoluteDirPackageFilename = IOUtil.Join(absoluteDirPath, self.__GenFilename)
            foundPackageFilePath = absoluteDirPackageFilename if IOUtil.IsFile(absoluteDirPackageFilename) else None

            newLocationRecord = PackageLocationCachePath(directoryLocationPackageName, absoluteDirPath, foundPackageFilePath, sourceLocation)
            if directoryLocationPackageName not in rLocationDict:
                newRecord = PackageLocationCacheRecord(directoryLocationPackageName)
                rLocationDict[directoryLocationPackageName] = newRecord
                if self.Log.Verbosity >= g_verbosityMaxLevel:
                    if foundPackageFilePath is None:
                        self.Log.LogPrint("- Cached '{0}' at '{1}'".format(directoryLocationPackageName, absoluteDirPath))
                    else:
                        self.Log.LogPrint("- Cached '{0}' at '{1}', found package here.".format(directoryLocationPackageName, absoluteDirPath))
            elif self.Log.Verbosity >= g_verbosityMaxLevel:
                if foundPackageFilePath is None:
                    self.Log.LogPrint("- Cached alias to '{0}' at '{1}'".format(directoryLocationPackageName, absoluteDirPath))
                else:
                    self.Log.LogPrint("- Cached alias to '{0}' at '{1}', found package here.".format(directoryLocationPackageName, absoluteDirPath))

            cacheRecord = rLocationDict[directoryLocationPackageName]
            cacheRecord.Append(newLocationRecord)
            if rNewLocations is not None:
                rNewLocations.append(newLocationRecord)

            if scanMethod == ScanMethod.Directory:
                # we already scanned the directory, so do nothing
                pass
            elif scanMethod == ScanMethod.OneSubDirectory:
                newLocationPackageName = directoryLocationPackageName + "."
                self.__CacheLocation(rScannedPathsCacheSet, rLocationDict, newLocationPackageName, absoluteDirPath, ScanMethod.Directory, sourceLocation, rNewLocations)
            elif scanMethod == ScanMethod.AllSubDirectories:
                newLocationPackageName = directoryLocationPackageName + "."
                self.__CacheLocation(rScannedPathsCacheSet, rLocationDict, newLocationPackageName, absoluteDirPath, ScanMethod.AllSubDirectories, sourceLocation, rNewLocations)
            else:
                raise Exception("Unsupported ScanMethod {0}".format(ScanMethod.TryToString(scanMethod, True)))