def __init__(self, log: Log, xmlElement: ET.Element, filename: str) -> None: super().__init__(log, xmlElement) #raise Exception("ExtendedProject not implemented"); self.Parent = self._ReadAttrib(xmlElement, 'Parent') # type: str self.ParentRoot = self._ReadAttrib(xmlElement, 'ParentRoot') # type: str configFilename = IOUtil.GetFileName(filename) # type: str self.ParentConfigFilename = IOUtil.Join(self.ParentRoot, configFilename) # type: str variableProcessor = VariableProcessor(log) self.AbsoluteParentConfigFilename = variableProcessor.ResolveAbsolutePathWithLeadingEnvironmentVariablePath( self.ParentConfigFilename) self.XmlPackageConfiguration = _LoadPackageConfigurations( log, xmlElement, filename) # type: List[XmlConfigPackageConfiguration] self.XmlRootDirectories = _LoadAddRootDirectory( log, xmlElement, filename) # type: List[XmlConfigFileAddRootDirectory] self.XmlNewProjectTemplatesRootDirectories = LoadUtil.LoadAddNewProjectTemplatesRootDirectory( log, xmlElement, filename) self.XmlBuildDocConfiguration = _LoadBuildDocConfiguration( log, xmlElement, filename) # type: List[XmlBuildDocConfiguration] self.XmlClangFormatConfiguration = _LoadClangFormatConfiguration( log, xmlElement, filename) # type: List[XmlClangFormatConfiguration] self.XmlClangTidyConfiguration = _LoadClangTidyConfiguration( log, xmlElement, filename) # type: List[XmlClangTidyConfiguration] self.XmlCompilerConfiguration = _LoadCompilerConfiguration( log, xmlElement, filename) # type: List[XmlConfigCompilerConfiguration] self.XmlExperimental = _TryLoadExperimental( log, xmlElement, filename) # type: Optional[XmlExperimental]
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 __init__(self, log: Log, filename: str) -> None: if not os.path.isfile(filename): raise FileNotFoundException("Could not locate config file %s", filename) tree = ET.parse(filename) elem = tree.getroot() if elem.tag == 'FslBuildGeneratorVSProjectTemplate': pass elif elem.tag == 'FslBuildNewVSProjectTemplate': log.LogPrintWarning("Template file '{0}' using legacy template FslBuildNewVSProjectTemplate update it to FslBuildGeneratorVSProjectTemplate".format(filename)) else: raise XmlInvalidRootElement("The file did not contain the expected root tag 'FslBuildGeneratorVSProjectTemplate'") super().__init__(log, elem) strVersion = self._ReadAttrib(elem, 'Version') if strVersion != "1": raise Exception("Unsupported version") xmlTemplate = self.__LoadTemplateConfiguration(log, elem) if len(xmlTemplate) != 1: raise XmlException("The file did not contain exactly one Template element") directoryName = IOUtil.GetDirectoryName(filename) self.Name = IOUtil.GetFileName(directoryName) self.Id = self.Name.lower() self.Version = 1 self.Template = xmlTemplate[0] self.Path = IOUtil.GetDirectoryName(filename) self.Prefix = ("%s_" % (self.Name)).upper() if self.Name != self.Template.Name: raise Exception("The parent template directory name '{0}' does not match the template name '{1}' {2}".format(self.Name, self.Template.Name, self.Path))
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 __ScanSubdirectories(self, scanPath: str, appInfoFilename: str) -> List[str]: filesFound = IOUtil.GetFilePaths(scanPath, appInfoFilename) return [ entry for entry in filesFound if IOUtil.GetFileName(entry) == appInfoFilename ]
def __TryAddAsCMakeLib(self, recipe: Optional[PackageExperimentalRecipe], package: Package) -> Optional[AndroidCMakeLib]: if recipe is None or recipe.ResolvedInstallPath is None or recipe.Pipeline is None: return None if not PackageRecipeUtil.CommandListContainsBuildCMake( recipe.Pipeline.CommandList): return None path = "{0}".format(recipe.ResolvedInstallPath) staticLibs = [] # type: List[AndroidCMakeLibRecord] if recipe.ValidateInstallation is not None and recipe.ValidateInstallation.CommandList is not None: for command in recipe.ValidateInstallation.CommandList: if command.CommandType == BuildRecipeValidateCommand.AddLib: commandEx = cast(XmlRecipeValidateCommandAddLib, command) libName = LibUtil.ToUnixLibName( IOUtil.GetFileName(commandEx.Name)) libPath = IOUtil.Join(path, "${ANDROID_ABI}") libPath = IOUtil.Join(libPath, commandEx.Name) staticLibs.append(AndroidCMakeLibRecord(libName, libPath)) # elif command.CommandType == BuildRecipeValidateCommand.AddDLL: # dynamicLibs.append(LibUtil.ToUnixLibName(IOUtil.GetFileName(command.Name))) return AndroidCMakeLib(path, staticLibs)
def CompilerSpecificFileDependencies(config: Config, package: Package, snippetPackageCompilerConditional: str, snippetPackageTargetSourceFiles: str, packageCompilerFileDict: Dict[str, List[str]]) -> str: if len(packageCompilerFileDict) <= 0: return "" targetName = package.Name finalContent = "" for key, conditionalFiles in packageCompilerFileDict.items(): content = [] # type: List[str] files = [] # type: List[str] for filename in conditionalFiles: inputFilename = GetSDKBasedPathUsingCMakeVariable(config, filename) outputFilename = IOUtil.GetFileName(filename) outputFilename = outputFilename.replace("__PACKAGE_TARGET_NAME__", targetName) content.append("configure_file({0} ${{CMAKE_CURRENT_BINARY_DIR}}/{1} COPYONLY)".format(inputFilename, outputFilename)) files.append(outputFilename) contentTargetSource = snippetPackageTargetSourceFiles contentTargetSource = contentTargetSource.replace("##PACKAGE_SOURCE_FILES##", "\n " + "\n ".join(files)) targetSource = contentTargetSource.split("\n") content += targetSource contentConfigureTargetSource = " " + "\n ".join(content) conditionalContent = snippetPackageCompilerConditional conditionalContent = conditionalContent.replace("##COMPILER_ID##", key) conditionalContent = conditionalContent.replace("##CONDITIONAL_SECTION##", contentConfigureTargetSource) finalContent += conditionalContent return finalContent
def __init__(self, filename: str, strPackageName: Optional[str], packageLocation: ToolConfigPackageLocation) -> None: super(PackageFile, self).__init__() if not IOUtil.IsAbsolutePath(filename): raise UsageErrorException() if not isinstance(packageLocation, ToolConfigPackageLocation): raise UsageErrorException() filename = IOUtil.NormalizePath(filename) if not filename.startswith(packageLocation.ResolvedPathEx): raise UsageErrorException( "The filename '{0}' does not belong to the supplied location '{1}'" .format(filename, packageLocation.ResolvedPathEx)) self.Filename = IOUtil.GetFileName(filename) self.RelativeFilePath = filename[ len(packageLocation.ResolvedPathEx ):] # The full relative path to the file self.RelativeDirPath = IOUtil.GetDirectoryName( self.RelativeFilePath) # The relative containing directory self.AbsoluteFilePath = filename # type: str self.AbsoluteDirPath = IOUtil.GetDirectoryName(filename) # type: str self.PackageRootLocation = packageLocation # type: ToolConfigPackageLocation self.PackageName = self.__DeterminePackageNameFromRelativeName( self.RelativeDirPath ) if strPackageName is None else strPackageName # type: str
def BuildInstallInstructions(onfig: Config, package: Package, templateInstallInstructions: str, templateInstallInstructionsTargets: str, templateInstallInstructionsHeaders: str, templateInstallInstructionsContent: str, templateInstallInstructionsDLL: str, templateInstallInstructionsAppInfo: str) -> str: hasIncludeDirectory = package.ResolvedBuildPublicIncludeFiles is not None and len( package.ResolvedBuildPublicIncludeFiles) > 0 installTargets = templateInstallInstructionsTargets includeHeadersContent = "" if (package.Type == PackageType.Library or package.Type == PackageType.HeaderLibrary) and hasIncludeDirectory: includeHeadersContent = templateInstallInstructionsHeaders includeHeadersContent = includeHeadersContent.replace( "##PACKAGE_INCLUDE_DIRECTORY##", package.BaseIncludePath) installContent = "" installDLL = "" installAppInfo = "" targetInstallDir = "" if (package.Type == PackageType.Executable): # Content if package.ContentPath is not None and ( len(package.ResolvedContentFiles) > 0 or len(package.ResolvedContentBuilderAllOuputFiles) > 0): packageContentFolderName = IOUtil.GetFileName( package.ContentPath.AbsoluteDirPath) installContent = templateInstallInstructionsContent installContent = installContent.replace("##PACKAGE_CONTENT_DIR##", packageContentFolderName) installContent = "\n" + installContent # Windows DLL's files = _GetDLLFileList(package) if len(files) > 0: installDLL = templateInstallInstructionsDLL installDLL = installDLL.replace("##FILES##", "\n " + "\n ".join(files)) installDLL = "\n" + installDLL # App info installAppInfo = templateInstallInstructionsAppInfo installAppInfo = "\n" + installAppInfo # target install dir targetInstallDir = "/" + package.Name.replace('.', '/') content = templateInstallInstructions content = content.replace("##PACKAGE_INSTALL_TARGETS##", installTargets) content = content.replace("##PACKAGE_INSTALL_HEADERS##", includeHeadersContent) content = content.replace("##PACKAGE_INSTALL_CONTENT##", installContent) content = content.replace("##PACKAGE_INSTALL_DLL##", installDLL) content = content.replace("##PACKAGE_INSTALL_APPINFO##", installAppInfo) content = content.replace("##PACKAGE_TARGET_INSTALL_PATH##", targetInstallDir) return content
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 __init__(self, filename: str, srcPath: str) -> None: super().__init__() self.FileName = IOUtil.GetFileName(filename) self.AbsoluteSourcePath = IOUtil.Join(srcPath, filename) if not filename.endswith(".__template__"): self.RelativeDestPath = filename else: self.RelativeDestPath = filename[:-len(".__template__")]
def __CreateFilenameLookupDict( self, filenameList: List[str]) -> Dict[str, List[str]]: """ Create a lookup dict that matches a filename to all full paths where that filename exist """ filenameDict = dict() # type: Dict[str,List[str]] for filepath in filenameList: filename = IOUtil.GetFileName(filepath) if not filename in filenameDict: filenameDict[filename] = [filepath] else: filenameDict[filename].append(filepath) return filenameDict
def __init__(self, userRequestedFNMatchPattern: str) -> None: super().__init__() userRequestedFNMatchPattern = IOUtil.NormalizePath( userRequestedFNMatchPattern) #self.FilterDirPath = IOUtil.NormalizePath(filterDirPath) self.UserRequestedFNMatchPattern = userRequestedFNMatchPattern self.IsAbsolutePattern = IOUtil.IsAbsolutePath( userRequestedFNMatchPattern) self.PatternFileName = IOUtil.GetFileName(userRequestedFNMatchPattern) patternDirectory = IOUtil.GetDirectoryName(userRequestedFNMatchPattern) if not self.IsAbsolutePattern and len( patternDirectory) > 0 and not patternDirectory.startswith('/'): patternDirectory = '/' + patternDirectory self.PatternDirectory = patternDirectory
def __init__(self, filename: str, strPackageName: Optional[str], packageLocation: ToolConfigPackageLocation) -> None: filename = IOUtil.NormalizePath(filename) if not IOUtil.IsAbsolutePath(filename): raise UsageErrorException() rootRelativePath = filename[len(packageLocation.ResolvedPathEx):] super().__init__(IOUtil.GetDirectoryName(rootRelativePath), packageLocation, False) self.Filename = IOUtil.GetFileName(filename) self.RootRelativeFilePath = rootRelativePath # The full root relative path to the file self.AbsoluteFilePath = filename # type: str self.PackageName = self.__DeterminePackageNameFromRelativeName( self.RootRelativeDirPath ) if strPackageName is None else strPackageName # type: str
def __init__(self, packagePath: str, packageRelativeFilePath: str) -> None: packagePath = IOUtil.NormalizePath(packagePath) packageRelativeFilePath = IOUtil.NormalizePath(packageRelativeFilePath) if not IOUtil.IsAbsolutePath(packagePath): raise Exception("packagePath must be absolute") if IOUtil.IsAbsolutePath(packageRelativeFilePath): raise Exception("packageRelativeFilePath can not be absolute") self.Filename = IOUtil.GetFileName(packageRelativeFilePath) absFilePath = IOUtil.Join(packagePath, packageRelativeFilePath) self.AbsoluteFilePath = absFilePath self.AbsoluteDirPath = IOUtil.GetDirectoryName(absFilePath) self.PackageRelativeFilePath = packageRelativeFilePath self.PackageRelativeDirPath = IOUtil.GetDirectoryName( packageRelativeFilePath)
def __init__(self, log: Log, filename: str) -> None: if not os.path.isfile(filename): raise FileNotFoundException("Could not locate config file %s", filename) tree = ET.parse(filename) elem = tree.getroot() if elem.tag != 'FslBuildNewTemplate': raise XmlInvalidRootElement("The file did not contain the expected root tag 'FslBuildGenConfig'") super().__init__(log, elem) fileVersion = self._ReadAttrib(elem, 'Version') if fileVersion != '1': raise Exception("The template file version was not correct") xmlTemplate = self.__LoadTemplateConfiguration(log, elem) if len(xmlTemplate) != 1: raise XmlException("The file did not contain exactly one Template element") self.Name = IOUtil.GetFileName(IOUtil.GetDirectoryName(filename)) self.Id = self.Name.lower() self.Version = int(fileVersion) # type: int self.Template = xmlTemplate[0] self.Path = IOUtil.GetDirectoryName(filename) self.Prefix = ("%s_" % (self.Name)).upper()
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
def __TryGenerateRunCommandForExecutable( self, buildContext: LocalBuildContext, package: Package, buildConfig: BuildConfigRecord, runCommands: Optional[List[str]], generatorConfig: GeneratorConfig) -> Optional[List[str]]: if package.Type != PackageType.Executable or runCommands is None or len( runCommands) <= 0: return None if package.ResolvedBuildPath is None or package.AbsolutePath is None: raise Exception("Invalid package") if package not in buildContext.GeneratorReportDict: raise Exception( "ForAllExe not supported by generator for package: {0}".format( package.Name)) generatorReport = buildContext.GeneratorReportDict[package] variableReport = generatorReport.VariableReport executableReport = generatorReport.ExecutableReport if executableReport is None: raise Exception( "ForAllExe not supported by generator for package {0} as it didnt contain a executable record" .format(package.Name)) foundVariantExePath = ReportVariableFormatter.Format( executableReport.ExeFormatString, variableReport, buildConfig.VariantSettingsDict, executableReport.EnvironmentVariableResolveMethod) if buildConfig.Generator is None: raise Exception("Generator is missing") buildExecutableInfo = buildConfig.Generator.TryGetBuildExecutableInfo( self.Log, generatorConfig, package, generatorReport, buildConfig.VariantSettingsDict) if buildExecutableInfo is not None: # Override the "install-type" path with the "development" exe path foundVariantExePath = buildExecutableInfo.BuildExePath packagePath = package.AbsolutePath fullPathExe = IOUtil.Join(packagePath, foundVariantExePath) exeName = IOUtil.GetFileName(foundVariantExePath) exePath = IOUtil.GetDirectoryName(fullPathExe) contentPath = IOUtil.Join(packagePath, ToolSharedValues.CONTENT_FOLDER_NAME) fullBuildDirPath = IOUtil.Join(packagePath, package.ResolvedBuildPath) fullBuildDirPath = buildContext.Config.ToCurrentOSPathDirectConversion( fullBuildDirPath) fullPathExe = buildContext.Config.ToCurrentOSPathDirectConversion( fullPathExe) exeName = buildContext.Config.ToCurrentOSPathDirectConversion(exeName) exePath = buildContext.Config.ToCurrentOSPathDirectConversion(exePath) packagePath = buildContext.Config.ToCurrentOSPathDirectConversion( packagePath) contentPath = buildContext.Config.ToCurrentOSPathDirectConversion( contentPath) commands = [] if executableReport.RunScript is not None: runScript = executableReport.RunScript if not executableReport.UseAsRelative: runScript = IOUtil.Join(packagePath, runScript) commands.append(runScript) for commandToRun in runCommands: command = commandToRun command = command.replace("(EXE)", fullPathExe) command = command.replace("(EXE_NAME)", exeName) command = command.replace("(EXE_PATH)", exePath) command = command.replace("(PACKAGE_NAME)", package.Name) command = command.replace("(PACKAGE_PATH)", packagePath) command = command.replace("(CONTENT_PATH)", contentPath) command = command.replace("(BUILD_PATH)", fullBuildDirPath) commands.append(command) return commands
def DetermineDirAndProjectName(currentDir: str, projectName: str) -> Tuple[str, str]: if projectName == '.': projectName = IOUtil.GetFileName(currentDir) currentDir = IOUtil.GetDirectoryName(currentDir) return currentDir, projectName
def __TryGenerateRunCommandForExecutable( self, buildContext: LocalBuildContext, package: Package, userVariantSettingDict: Dict[str, str], runCommands: Optional[List[str]]) -> Optional[List[str]]: if package.Type != PackageType.Executable or runCommands is None or len( runCommands) <= 0: return None if package.ResolvedBuildPath is None or package.AbsolutePath is None: raise Exception("Invalid package") if package not in buildContext.GeneratorReportDict: raise Exception( "ForAllExe not supported by generator for package: {0}".format( package.Name)) generatorReport = buildContext.GeneratorReportDict[package] variableReport = generatorReport.VariableReport executableReport = generatorReport.ExecutableReport if executableReport is None: raise Exception( "ForAllExe not supported by generator for package {0} as it didnt contain a executable record" .format(package.Name)) foundVariantExePath = ReportVariableFormatter.Format( executableReport.ExeFormatString, variableReport, userVariantSettingDict, executableReport.EnvironmentVariableResolveMethod) packagePath = package.AbsolutePath fullPathExe = IOUtil.Join(packagePath, foundVariantExePath) exeName = IOUtil.GetFileName(foundVariantExePath) exePath = IOUtil.GetDirectoryName(fullPathExe) contentPath = IOUtil.Join(packagePath, "Content") fullBuildDirPath = IOUtil.Join(packagePath, package.ResolvedBuildPath) fullBuildDirPath = buildContext.Config.ToCurrentOSPathDirectConversion( fullBuildDirPath) fullPathExe = buildContext.Config.ToCurrentOSPathDirectConversion( fullPathExe) exeName = buildContext.Config.ToCurrentOSPathDirectConversion(exeName) exePath = buildContext.Config.ToCurrentOSPathDirectConversion(exePath) packagePath = buildContext.Config.ToCurrentOSPathDirectConversion( packagePath) contentPath = buildContext.Config.ToCurrentOSPathDirectConversion( contentPath) commands = [] if executableReport.RunScript is not None: runScript = executableReport.RunScript if not executableReport.UseAsRelative: runScript = IOUtil.Join(packagePath, runScript) commands.append(runScript) for commandToRun in runCommands: command = commandToRun command = command.replace("(EXE)", fullPathExe) command = command.replace("(EXE_NAME)", exeName) command = command.replace("(EXE_PATH)", exePath) command = command.replace("(PACKAGE_NAME)", package.Name) command = command.replace("(PACKAGE_PATH)", packagePath) command = command.replace("(CONTENT_PATH)", contentPath) command = command.replace("(BUILD_PATH)", fullBuildDirPath) commands.append(command) return commands
def AddPathIfInPackageRoot(rGitIgnoreDict: Dict[str, Set[str]], package: Package, pathToFile: str) -> None: pathDir = IOUtil.GetDirectoryName(pathToFile) if pathDir == package.AbsolutePath: fileName = IOUtil.GetFileName(pathToFile) SafeAddEntry(rGitIgnoreDict, package, fileName)