def _GeneratedFileSet(log: Log, generatorConfig: GeneratorConfig,
                          cmakeConfig: GeneratorCMakeConfig,
                          topLevelPackage: Package) -> Set[str]:
        """
        Generate a list of all build files that will be generated for the given topLevelPackage by this generator
        """
        fileSet = set()  # type: Set[str]

        for toolProjectContext in generatorConfig.ToolConfig.ProjectInfo.Contexts:
            filename = GeneratorCMake._GetProjectPackageBuildFileName(
                toolProjectContext.Location)
            if IOUtil.IsFile(filename):
                fileSet.add(filename)

        for depPackage in topLevelPackage.ResolvedAllDependencies:
            filename = GeneratorCMake._GetPackageBuildFileName(
                depPackage.Package)
            if IOUtil.IsFile(filename):
                fileSet.add(filename)

            # These should probably be added as "generated config files"
            # so we can detect if they are missing and use it as another reason to run configure (just as if a build file was modified)
            # But then again if people delete anything else from the "build" folder things might easily stop working
            #if dstPackage.Type == PackageType.Executable:
            #    buildPath = GeneratorCMake._GetPackageBuildDir(generatorConfig, cmakeConfig, dstPackage)
            #    fileSet.add(IOUtil.Join(buildPath,  ".fsl-build/config_Debug.json"))
            #    fileSet.add(IOUtil.Join(buildPath,  ".fsl-build/config_Release.json"))
        return fileSet
Esempio n. 2
0
    def DoExecute(self) -> None:
        """ Copy a file or directory to the destination """
        # Try to do a lookup
        srcPath = self.TryResolveSrcPathString(self.__SourceCommand.From)
        if srcPath is None:
            srcPath = IOUtil.Join(self.Info.SrcRootPath,
                                  self.__SourceCommand.From)

        dstPath = self.TryResolveDstPathString(self.__SourceCommand.To)
        if dstPath is None:
            dstPath = IOUtil.Join(
                self.Info.DstRootPath, self.__SourceCommand.To) if len(
                    self.__SourceCommand.To) > 0 else self.Info.DstRootPath

        fileExist = IOUtil.Exists(dstPath)
        if not IOUtil.Exists(dstPath) or self.__Overwrite:
            if fileExist:
                self.LogPrint(
                    "Copying from '{0}' to '{1}' overwriting the existing file"
                    .format(srcPath, dstPath))
            else:
                self.LogPrint("Copying from '{0}' to '{1}'".format(
                    srcPath, dstPath))
            if IOUtil.IsFile(srcPath):
                self._CreateDirectory(IOUtil.GetDirectoryName(dstPath))
                shutil.copy2(srcPath, dstPath)
            elif IOUtil.IsDirectory(srcPath):
                self._CreateDirectory(IOUtil.GetDirectoryName(dstPath))
                shutil.copytree(srcPath, dstPath)
            else:
                raise Exception("Copy source '{0}' not found".format(srcPath))
        else:
            self.LogPrint(
                "Copying from '{0}' to '{1}' skipped as target exist".format(
                    srcPath, dstPath))
Esempio n. 3
0
 def GetTempFileName(self, contentPath: str, contentFileRecord: PathRecord) -> str:
     fileName = IOUtil.GetFileName(contentFileRecord.RelativePath) + ".tmp"
     tempFileName = IOUtil.Join(contentPath, fileName)
     while IOUtil.IsFile(tempFileName):
         fileName = '_' + fileName
         tempFileName = IOUtil.Join(contentPath, fileName)
     return tempFileName
    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
    def __DoValidateEnvironmentVariable(self, rErrorRecordList: List[ErrorRecord],
                                        command: XmlRecipeValidateCommandEnvironmentVariable) -> Tuple[bool, Optional[str]]:
        value = os.environ.get(command.Name)
        if not value:
            rErrorRecordList.append(ErrorRecord(ErrorClassification.Environment, "Environment variable '{0}' is not defined, please define it as required.".format(command.Name)))
            return False, value

        if self.__BasicConfig.Verbosity >= 4:
            self.__BasicConfig.LogPrint("ValidateEnvironmentVariable: '{0}'='{1}'".format(command.Name, value))

        if command.Method == BuildRecipeValidateMethod.IsDirectory:
            if not IOUtil.IsDirectory(value):
                rErrorRecordList.append(ErrorRecord(ErrorClassification.Environment, "Environment variable '{0}' contained '{1}' which is not a directory.".format(command.Name, value)))
                return False, value
        elif command.Method == BuildRecipeValidateMethod.IsFile:
            if not IOUtil.IsFile(value):
                fileHelp = self.__GetFailedFileCheckExtraHelpString(value)
                rErrorRecordList.append(ErrorRecord(ErrorClassification.Environment, "Environment variable '{0}' contained '{1}' which is not a file.{2}".format(command.Name, value, fileHelp)))
                return False, value
        elif command.Method == BuildRecipeValidateMethod.Exists:
            if not IOUtil.Exists(value):
                rErrorRecordList.append(ErrorRecord(ErrorClassification.Environment, "Environment variable '{0}' contained '{1}' which is a path that dont exist.".format(command.Name, value)))
                return False, value
        else:
            raise Exception("Unsupported BuildRecipeValidateMethod '{0}'".format(command.Method))


        if not command.AllowEndSlash  and (value.endswith('/') or value.endswith('\\')):
            rErrorRecordList.append(ErrorRecord(ErrorClassification.Environment, "Environment variable '{0}' content '{1}' can not end with a slash '/' or backslash '\\'.".format(command.Name, value)))
            return False, value

        return True, IOUtil.NormalizePath(value)
Esempio n. 6
0
 def IsValidCacheFile(
         cachePath: str,
         sourceCommand: XmlRecipePipelineFetchCommandDownload) -> bool:
     if not IOUtil.IsFile(cachePath):
         return False
     filehash = PipelineCommandFetch.GenerateFileHash(cachePath)
     return filehash == sourceCommand.Hash
    def __DoValidatePath(self, rErrorRecordList: List[ErrorRecord],
                         installationPath: Optional[str],
                         command: XmlRecipeValidateCommandPath) -> Tuple[bool, Optional[str]]:
        if self.__BasicConfig.Verbosity >= 4:
            self.__BasicConfig.LogPrint("ValidatePath '{0}'".format(command.Name))

        result, path = self.__TryResolvePath(rErrorRecordList, installationPath, command.Name)
        if not result or path is None:
            return False, path

        if self.__BasicConfig.Verbosity >= 4:
            self.__BasicConfig.LogPrint("Resolving to '{0}'".format(path))

        if command.Method == BuildRecipeValidateMethod.IsDirectory:
            if not IOUtil.IsDirectory(path):
                rErrorRecordList.append(ErrorRecord(ErrorClassification.Critical, "Path '{0}' resolved to '{1}' which is not a directory.".format(command.Name, path)))
                return False, path
        elif command.Method == BuildRecipeValidateMethod.IsFile:
            if not IOUtil.IsFile(path):
                fileHelp = self.__GetFailedFileCheckExtraHelpString(path)
                rErrorRecordList.append(ErrorRecord(ErrorClassification.Critical, "Path '{0}' resolved to '{1}' which is not a file.{2}".format(command.Name, path, fileHelp)))
                return False, path
        elif command.Method == BuildRecipeValidateMethod.Exists:
            if not IOUtil.Exists(path):
                rErrorRecordList.append(ErrorRecord(ErrorClassification.Critical, "Path '{0}' resolved to '{1}' which is a path that dont exist.".format(command.Name, path)))
                return False, path
        else:
            raise Exception("Unsupported BuildRecipeValidateMethod '{0}'".format(command.Method))
        return True, path
Esempio n. 8
0
    def DownloadFromUrl(self, url: str, dstPath: str) -> None:
        if IOUtil.IsFile(dstPath):
            self.LogPrint("Downloaded archive found at '{0}', skipping download.".format(dstPath))
            return

        self.DoPrint("Downloading '{0}' to '{1}'".format(url, dstPath))
        reporter = DownloadTask.__MakeDownReporter(self.DoPrint, IOUtil.GetFileName(dstPath))
        urllib.request.urlretrieve(url, dstPath, reporthook=reporter)
def __TryValidateInstallation(basicConfig: BasicConfig,
                              validationEngine: ValidationEngine,
                              package: Package, packagesToBuild: List[Package],
                              recipePackageStateCache: RecipePackageStateCache,
                              cmakeConfig: GeneratorCMakeConfig) -> bool:
    if package.ResolvedDirectExperimentalRecipe is None:
        raise Exception("Invalid package")
    sourceRecipe = package.ResolvedDirectExperimentalRecipe
    installPath = sourceRecipe.ResolvedInstallLocation
    if installPath is not None:
        if not IOUtil.IsDirectory(installPath.ResolvedPath):
            basicConfig.LogPrintVerbose(
                2, "Installation directory not located: {0}".format(
                    installPath.ResolvedPath))
            return False
        elif basicConfig.Verbosity >= 2:
            basicConfig.LogPrint(
                "Installation directory located at '{0}'".format(
                    installPath.ResolvedPath))

    # Check if the user decided to do a build override by creating the required file.
    # This allows the user to tell the system that it has been build and it should mind its own buisness
    packageHasUserBuildOverride = False
    if not installPath is None:
        overrideFilename = IOUtil.Join(
            installPath.ResolvedPath,
            __g_BuildPackageInformationOverrideFilename)
        packageHasUserBuildOverride = IOUtil.IsFile(overrideFilename)
        if packageHasUserBuildOverride:
            basicConfig.LogPrint(
                "Package {0} contained a build override file '{1}'".format(
                    package.Name, __g_BuildPackageInformationOverrideFilename))

    if not __RunValidationEngineCheck(validationEngine, package):
        if packageHasUserBuildOverride:
            raise Exception(
                "Package {0} contained a build override file '{1}', but it failed validation. Fix the issues or delete the override file '{2}'"
                .format(package.Name,
                        __g_BuildPackageInformationOverrideFilename,
                        overrideFilename))
        basicConfig.LogPrintVerbose(2, "Install validation failed")
        return False

    # If there is a user build override we dont check the build dependency json file
    if packageHasUserBuildOverride:
        return True

    # If there is no build pipeline we consider the validation to be completed, else we need to check the saved build info
    if not PackageRecipeUtil.HasBuildPipeline(package):
        return True

    if not BuildInfoFileUtil.TryValidateBuildInformation(
            basicConfig, package, packagesToBuild, recipePackageStateCache,
            cmakeConfig, __g_BuildPackageInformationFilename):
        basicConfig.LogPrintVerbose(
            2, "Install validator failed to load build information")
        return False
    return True
 def __LoadHeaderLib(self, log: Log, template: XmlNewVSProjectTemplateFile, vsVersion: int, usingLinuxTools: bool) -> Optional[CodeTemplateVC]:
     # FIX: this might not work correctly after the recent template changes
     #      but the headerlib is only used by the experimental visual studio linux tools support
     #      so its not critical to fix it now
     name = "HeaderLib"
     path = IOUtil.Join(template.Path, "{0}.sln".format(name))
     if not IOUtil.IsFile(path):
         return None
     templateCustomization = self.__LoadTemplateCustomization(log, template, "Dummy")
     return CodeTemplateVC(log, template, name, vsVersion, usingLinuxTools, templateCustomization)
Esempio n. 11
0
 def DoExecute(self) -> None:
     """ Delete a file or directory if it exist """
     sourcePath = self.__SourceCommand.Path
     path = sourcePath
     if '../' in path or '/..' in path or path.startswith(
             '/') or '\\' in path or path == '..' or len(path) <= 0:
         raise Exception("Invalid path format '{0}'".format(path))
     path = IOUtil.Join(self.FinalDstPath, path)
     if IOUtil.IsDirectory(path):
         self.LogPrint("Deleting directory '{0}'".format(sourcePath))
         IOUtil.SafeRemoveDirectoryTree(path)
     elif IOUtil.IsFile(path):
         self.LogPrint("Deleting file '{0}'".format(sourcePath))
         IOUtil.RemoveFile(path)
    def __DoValidateFile(self, rErrorRecordList: List[ErrorRecord],
                         installationPath: Optional[str],
                         filename: str,
                         allowEnvironmentVariable: bool) -> Tuple[bool, Optional[str]]:
        result, path = self.__TryResolvePath(rErrorRecordList, installationPath, filename, allowEnvironmentVariable)
        if not result or path is None:
            return False, path

        if self.__BasicConfig.Verbosity >= 4:
            self.__BasicConfig.LogPrint("Resolving to '{0}'".format(path))

        if not IOUtil.IsFile(path):
            fileHelp = self.__GetFailedFileCheckExtraHelpString(path)
            rErrorRecordList.append(ErrorRecord(ErrorClassification.Critical, "Path '{0}' resolved to '{1}' which is not a file.{2}".format(filename, path, fileHelp)))
            return False, path
        return True, path
Esempio n. 13
0
    def DoExecute(self) -> None:
        try:
            targetFilename = PipelineCommandDownload.GetTargetFilename(
                self.__SourceCommand)
            archiveFilePath = IOUtil.Join(self.Info.DstRootPath,
                                          targetFilename)

            if not self.Info.AllowDownloads and not PipelineCommandDownload.IsValidCacheFile(
                    archiveFilePath, self.__SourceCommand):
                raise Exception(
                    "Could not download {0} to {1} as downloads have been disabled. Enable downloads or download it manually."
                    .format(self.__SourceCommand.URL, archiveFilePath))

            self.Task.DownloadFromUrl(self.__SourceCommand.URL,
                                      archiveFilePath)
            # Generate file hash
            filehash = PipelineCommandFetch.GenerateFileHash(archiveFilePath)
            if self.__SourceCommand.Hash is None:
                if self.Log.Verbosity >= 1:
                    self.Log.LogPrintWarning(
                        "No hash value defined for file {0} which has a hash value of {1}"
                        .format(archiveFilePath, filehash))
            elif filehash != self.__SourceCommand.Hash:
                raise Exception(
                    "The downloaded file {0} has a hash of {1} which did not match the expected value of {2}"
                    .format(archiveFilePath, filehash,
                            self.__SourceCommand.Hash))
            elif self.Log.Verbosity >= 2:
                self.LogPrint(
                    "The downloaded file {0} hash was {1} as expected.".format(
                        archiveFilePath, filehash))
        except Exception:
            # A error occurred removing the targetPath
            if IOUtil.IsFile(archiveFilePath):
                self.LogPrint(
                    "* A error occurred removing '{0}' to be safe.".format(
                        archiveFilePath))
                IOUtil.RemoveFile(archiveFilePath)
            raise
    def ProcessAppInfo(self, currentDirPath: str,
                       localToolConfig: LocalToolConfig,
                       appInfoChoice: int) -> None:
        requestedFileList = []  # type: List[str]
        localFile = IOUtil.Join(currentDirPath, g_InfoFilename)
        if IOUtil.IsFile(localFile):
            requestedFileList.append(localFile)

        activePlatformNameId = localToolConfig.PlatformName.lower()

        isRecursive = appInfoChoice == AppInfoChoice.Recursive
        loader = AppInfoLoader(self.Log, g_InfoFilename, requestedFileList,
                               isRecursive, currentDirPath,
                               activePlatformNameId)
        if loader.IsEmpty():
            self.Log.LogPrint("No '{0}' files found".format(g_InfoFilename))
            return

        requirementTree = AppInfoRequirementTree(self.Log, loader.GetDict(),
                                                 activePlatformNameId)

        if localToolConfig.BuildPackageFilters is None or localToolConfig.BuildPackageFilters.ExtensionNameList is None:
            raise Exception("BuildPackageFilters.ExtensionNameList is invalid")

        # Now we basically need to apply the same filters as the other build tools
        completePackageList = [
            AppInfoPackage(self.Log, appInfo, filename)
            for filename, appInfo in loader.GetDict().items()
        ]
        completePackageList.sort(key=lambda s: s.Name.lower())
        filteredPackageList = PackageFilter.FilterAppInfo(
            self.Log, completePackageList, requirementTree.GlobalTree,
            localToolConfig.BuildPackageFilters)

        # Then its time to run the the packages that are left
        self.__RunPackages(filteredPackageList, localToolConfig.RemainingArgs,
                           localToolConfig.BuildVariantsDict)
Esempio n. 15
0
 def __ParseSync(self, log: Log, jsonContent: Any, sourceFilename: str,
                 parentElementName: str, defaultSourcePath: str,
                 pathVariables: PathVariables) -> List[ContentFileRecord]:
     sourcePath = self.__TryReadKey(jsonContent, "SourcePath",
                                    defaultSourcePath)
     sourceRoot = ContentRootRecord(log, sourcePath, pathVariables)
     contentKey = "Content"
     if not contentKey in jsonContent:
         raise Exception(
             "The key '{0}' was not found under '{1}' in file '{2}".format(
                 contentKey, parentElementName, sourceFilename))
     content = jsonContent[contentKey]
     uniqueFiles = {}  # type: Dict[str, ContentFileRecord]
     files = []  # type: List[ContentFileRecord]
     for entry in content:
         self.__ValidateContentName(entry, sourceFilename)
         absolutePath = IOUtil.Join(sourceRoot.ResolvedPath, entry)
         directory = IOUtil.GetDirectoryName(absolutePath)
         filename = IOUtil.GetFileName(absolutePath)
         # check if there is a wild card in the filename
         if '*' in filename:
             self.__AppendFilesUsingWildcard(log, uniqueFiles, files,
                                             sourceRoot, entry,
                                             absolutePath, directory,
                                             filename)
         elif IOUtil.IsDirectory(absolutePath):
             self.__AppendDirectory(log, uniqueFiles, files, sourceRoot,
                                    entry, absolutePath)
         elif IOUtil.IsFile(absolutePath):
             self.__AppendFile(log, uniqueFiles, files, sourceRoot, entry,
                               absolutePath)
         else:
             raise Exception(
                 "No file or directory found for entry '{0}' which expands to '{1}'"
                 .format(entry, absolutePath))
     return files
Esempio n. 16
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)))
Esempio n. 17
0
def ProcessPackages(toolAppContext: ToolAppContext, config: Config,
                    packages: List[Package],
                    activeRootDir: ToolConfigRootDirectory,
                    extractArguments: Optional[str],
                    buildDocConfiguration: BuildDocConfiguration,
                    currentDir: str) -> List[str]:
    log = config  # type: Log
    ignoreRequirementSet = set()  # type: Set[str]
    for requirement in buildDocConfiguration.Requirements:
        if requirement.Skip:
            ignoreRequirementSet.add(requirement.Name)

    exePackages = ExtractPackages(packages, PackageType.Executable)
    exePackages = __RemoveIgnored(log, exePackages, ignoreRequirementSet)
    exePackages = [
        package for package in exePackages if package.ShowInMainReadme
    ]
    exePackages.sort(key=lambda s: None
                     if s.AbsolutePath is None else s.AbsolutePath.lower())

    packageArgumentsDict = {}  # type: Dict[Package, JsonDictType]
    if extractArguments is not None:
        packageArgumentsDict = ExtractArguments(toolAppContext, config,
                                                exePackages, extractArguments,
                                                currentDir)

    uniqueDict = {}  # type: Dict[str, List[Package]]
    for package in exePackages:
        if package.Namespace is None:
            raise Exception("Invalid package")
        if not package.Namespace in uniqueDict:
            uniqueDict[package.Namespace] = []
        uniqueDict[package.Namespace].append(package)

    # sort the content
    for packageList in list(uniqueDict.values()):
        packageList.sort(key=lambda s: s.Name.lower())
    sortedKeys = list(uniqueDict.keys())
    sortedKeys.sort()

    # Format it
    isFirst = True
    result = []
    for key in sortedKeys:
        if isFirst:
            isFirst = False
        else:
            result.append("")
        result.append("## {0}".format(key))
        result.append("")
        for package in uniqueDict[key]:
            if package.AbsolutePath is None:
                raise Exception("Invalid package")
            rootDir = config.ToolConfig.TryFindRootDirectory(
                package.AbsolutePath)
            if rootDir == activeRootDir:
                config.LogPrintVerbose(
                    4, "Processing package '{0}'".format(package.Name))
                packageDir = package.AbsolutePath[len(rootDir.ResolvedPath) +
                                                  1:]
                result.append("### [{0}]({1})".format(package.ShortName,
                                                      packageDir))
                exampleImagePath = IOUtil.Join(package.AbsolutePath,
                                               "Example.jpg")
                if IOUtil.IsFile(exampleImagePath):
                    exampleImagePath = exampleImagePath[len(rootDir.
                                                            ResolvedPath) + 1:]
                    #result.append('<a href="{0}">'.format(packageDir))
                    result.append('<a href="{0}">'.format(exampleImagePath))
                    #result.append('<img src="{0}" height="108px" style="float:right;clear:both;display:table;margin:1px">'.format(exampleImagePath))
                    result.append('<img src="{0}" height="108px">'.format(
                        exampleImagePath))
                    result.append('</a>')
                    result.append("")

                readmePath = IOUtil.Join(package.AbsolutePath, "README.md")
                packageReadMeLines = TryLoadReadMe(config, readmePath)
                if packageReadMeLines is not None:
                    packageReadMeLines = UpdatePackageReadMe(
                        config, package, packageReadMeLines,
                        packageArgumentsDict, readmePath)
                    SaveReadMe(config, readmePath, packageReadMeLines)
                    brief = TryExtractBrief(config, packageReadMeLines,
                                            readmePath)
                    if brief is not None:
                        result = result + brief
                        result.append("")

                result.append("")
            #else:
            #    config.LogPrintVerbose(4, "Skipping package '{0}' with rootDir '{1}' is not part of the activeRootDir '{2}'".format(package.Name, rootDir.ResolvedPath, activeRootDir.ResolvedPath))

    return result
Esempio n. 18
0
 def __TryLoadTemplate(self, log: Log,
                       path: str) -> Optional[XmlNewVSProjectTemplateFile]:
     if IOUtil.IsFile(path):
         return XmlNewVSProjectTemplateFile(log, path)
     return None
Esempio n. 19
0
 def __AddSpecialFile(self, files: List[FileConfig], srcPath: str,
                      dstPath: str) -> None:
     if IOUtil.IsFile(srcPath):
         files.append(FileConfig(srcPath, dstPath))
    def __init__(self, log: Log, template: XmlNewVSProjectTemplateFile,
                subDirectory: str, vsVersion: int, useLinuxTools: bool,
                customization: XmlNewVSProjectTemplateCustomizationFile) -> None:
        super().__init__()
        strVSPath = template.Path

        strTemplatePath = IOUtil.Join(strVSPath, subDirectory)
        strTemplateSolutionPath = IOUtil.Join(strTemplatePath, "Template_sln")
        strTemplateProjectPath = IOUtil.Join(strTemplatePath, "Template_{0}".format(template.Template.ProjectExtension))
        strTemplateFilterPath = IOUtil.Join(strTemplatePath, "Template_filters")

        strTemplateNuGetPackageConfigPath = IOUtil.Join(strTemplatePath, "Template_packages_config")

        self.BuildOutputLocation = customization.BuildOutput.Location
        self.FilterExtension = "vcxproj.filters"
        self.SolutionExtension = "sln"
        self.ProjectExtension = template.Template.ProjectExtension

        self.TemplateFileRecordManager = TemplateFileRecordManager(strTemplatePath)

        nuGetPackageConfig = IOUtil.TryReadFile(IOUtil.Join(strTemplateNuGetPackageConfigPath, "Master.txt"))
        self.NuGetPackageConfig = NuGetPackageConfigSnippets(log, strTemplateNuGetPackageConfigPath, nuGetPackageConfig) if nuGetPackageConfig is not None else None

        self.TemplateSLN = IOUtil.ReadFile(IOUtil.Join(strTemplateSolutionPath, "Master.txt"))
        self.SLNAddProject = IOUtil.ReadFile(IOUtil.Join(strTemplateSolutionPath, "AddProject.txt"))
        self.SLNSnippet1 = IOUtil.ReadFile(IOUtil.Join(strTemplateSolutionPath, "Snippet1.txt"))
        self.SLNSnippet2 = IOUtil.ReadFile(IOUtil.Join(strTemplateSolutionPath, "Snippet2.txt"))
        self.Master = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "Master.txt"))
        self.VariantProjectConfiguration = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "VariantProjectConfiguration.txt"))
        self.ProjectReferences = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "ProjectReferences.txt"))
        self.ProjectReferences_1 = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "ProjectReferences_1.txt"))
        self.PackageReferences = IOUtil.TryReadFile(IOUtil.Join(strTemplateProjectPath, "PackageReferences.txt"))
        self.PackageReferences_1 = IOUtil.TryReadFile(IOUtil.Join(strTemplateProjectPath, "PackageReferences_1.txt"))
        self.AssemblyReferenceSimple = IOUtil.TryReadFile(IOUtil.Join(strTemplateProjectPath, "AssemblyReferenceSimple.txt"))
        self.AssemblyReferenceComplex = IOUtil.TryReadFile(IOUtil.Join(strTemplateProjectPath, "AssemblyReferenceComplex.txt"))
        self.AssemblyReferenceComplex_Private = IOUtil.TryReadFile(IOUtil.Join(strTemplateProjectPath, "AssemblyReferenceComplex_Private.txt"))
        self.AddHeaderFile = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "AddHeaderFile.txt"))
        self.AddSourceFile = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "AddSourceFile.txt"))
        self.AddNatvisFile = self.SafeReadFile(IOUtil.Join(strTemplateProjectPath, "AddNatvisFile.txt"), "")
        self.VariantConfiguration = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "VariantConfiguration.txt"))
        self.VariantPropertySheets = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "VariantPropertySheets.txt"))
        self.VariantPropertyGroups = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "VariantPropertyGroups.txt"))
        self.VariantCompilerSettings = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "VariantCompilerSettings.txt"))
        self.VariantCompilerSettings_1 = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "VariantCompilerSettings_1.txt"))
        self.VariantCompilerSettings_2 = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "VariantCompilerSettings_2.txt"))
        self.WindowsTargetPlatformVersion = self.SafeReadFile(IOUtil.Join(strTemplateProjectPath, "WindowsTargetPlatformVersion.txt"), "")
        externalFileToOutput = IOUtil.TryReadFile(IOUtil.Join(strTemplateProjectPath, "ExternalFileToOutput.txt"))
        self.ExternalFileToOutput = "" if externalFileToOutput is None else externalFileToOutput
        copyFileToFolders = IOUtil.TryReadFile(IOUtil.Join(strTemplateProjectPath, "CopyFileToFolders.txt"))
        self.CopyFileToFolders = ""
        self.CopyFileToFoldersCopyConditions = ""
        if copyFileToFolders is not None:
            self.CopyFileToFolders = copyFileToFolders
            self.CopyFileToFoldersCopyConditions = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "CopyFileToFolders_CopyConditions.txt"))
        self.Snippet9 = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "CustomBuildFiles.txt"))
        self.Snippet9_1 = IOUtil.ReadFile(IOUtil.Join(strTemplateProjectPath, "CustomBuildFiles_1.txt"))

        # Filter master file
        self.FilterMaster = IOUtil.TryReadFile(IOUtil.Join(strTemplateFilterPath, "master.txt"))
        self.FilterItemGroup = self.SafeReadFile(IOUtil.Join(strTemplateFilterPath, "itemgroup.txt"), "")
        self.FilterItemGroupNatvis = self.SafeReadFile(IOUtil.Join(strTemplateFilterPath, "itemgroup_natvis.txt"), "")
        self.FilterItemHeader = self.SafeReadFile(IOUtil.Join(strTemplateFilterPath, "item_header.txt"), "")
        self.FilterItemShader = self.SafeReadFile(IOUtil.Join(strTemplateFilterPath, "item_shader.txt"), "")
        self.FilterItemSource = self.SafeReadFile(IOUtil.Join(strTemplateFilterPath, "item_source.txt"), "")

        self.DebugOptimizations = {}  # type: Dict[int, TemplateOptimizationSetting]
        self.__LoadOptimization(self.DebugOptimizations, OptimizationType.Disabled, strVSPath, "DEBUG", "disabled")
        self.__LoadOptimization(self.DebugOptimizations, OptimizationType.Default, strVSPath, "DEBUG", "disabled")
        self.__LoadOptimization(self.DebugOptimizations, OptimizationType.Full, strVSPath, "DEBUG", "full")

        snippet3FileName = IOUtil.Join(strTemplateSolutionPath, "Snippet3.txt")
        if IOUtil.IsFile(snippet3FileName):
            self.SLNSnippet3 = IOUtil.ReadFile(snippet3FileName)
            self.SLNSnippet4 = IOUtil.ReadFile(IOUtil.Join(strTemplateSolutionPath, "Snippet4.txt"))
            self.SLNSnippet4_1 = IOUtil.ReadFile(IOUtil.Join(strTemplateSolutionPath, "Snippet4_1.txt"))
        else:
            self.SLNSnippet3 = ""
            self.SLNSnippet4 = ""
            self.SLNSnippet4_1 = ""