def __ScanFiles(log: Log, package: Package, filteredFiles: Optional[List[str]], repairEnabled: bool, thirdpartyExceptionDir: Optional[str], checkType: int, disableWrite: bool) -> int: """ :param filteredFiles: a optional list of specifc files to scan in this package (if supplied the rest should be ignored) """ if not package.AllowCheck and checkType == CheckType.Normal: return 0 if package.AbsolutePath is None: log.DoPrintWarning("package did not contain a abs path") return 0 allowedFileSet = None if filteredFiles is None else set(filteredFiles) errorCount = 0 if package.ResolvedBuildAllIncludeFiles is not None: for fileName in package.ResolvedBuildAllIncludeFiles: fullPath = IOUtil.Join(package.AbsolutePath, fileName) # Only process files with the expected extension if allowedFileSet is None or fullPath in allowedFileSet: if __IsValidExtension(fileName, __g_includeExtensionList): if not __ProcessIncludeFile( log, package, fullPath, repairEnabled, thirdpartyExceptionDir, disableWrite): errorCount += 1 if package.ResolvedBuildSourceFiles is not None: for fileName in package.ResolvedBuildSourceFiles: fullPath = IOUtil.Join(package.AbsolutePath, fileName) if allowedFileSet is None or fullPath in allowedFileSet: if __IsValidExtension(fileName, __g_includeExtensionList): if not __ProcessIncludeFile( log, package, fullPath, repairEnabled, thirdpartyExceptionDir, disableWrite): errorCount += 1 elif __IsValidExtension(fileName, __g_sourceExtensionList): if not __ProcessSourceFile( log, package, fullPath, repairEnabled, thirdpartyExceptionDir, disableWrite): errorCount += 1 return errorCount
def Process(log: Log, toolConfig: ToolConfig, customPackageFileFilter: Optional[CustomPackageFileFilter], clangFormatConfiguration: ClangFormatConfiguration, cmakeConfig: GeneratorCMakeConfig, clangFormatExeInfo: ClangExeInfo, ninjaExeInfo: ClangExeInfo, sortedPackageList: List[Package], repairEnabled: bool, numBuildThreads: int) -> int: totalProcessedCount = 0 logOutput = False currentWorkingDirectory = BuildUtil.GetBuildDir( toolConfig.ProjectInfo, cmakeConfig.CheckDir) currentWorkingDirectory = IOUtil.Join(currentWorkingDirectory, "format") ninjaOutputFile = IOUtil.Join(currentWorkingDirectory, "build.ninja") toolVersionOutputFile = IOUtil.Join(currentWorkingDirectory, "ToolVersions.txt") IOUtil.SafeMakeDirs(currentWorkingDirectory) log.LogPrint("Using path: '{0}'".format(currentWorkingDirectory)) log.LogPrint("Storing tool versions.") PerformClangFormatHelper2.WriteToolVersionFile(log, toolVersionOutputFile, clangFormatExeInfo, ninjaExeInfo) log.LogPrint("Generating ninja format file.") #foundFixes = PerformClangTidyHelper2.FindFixes(log, clangTidyFixOutputFolder) #if len(foundFixes) > 0: # PerformClangTidyHelper2.DeleteFixes(log, clangTidyFixOutputFolder, foundFixes) totalProcessedCount = PerformClangFormatHelper2.GenerateNinjaTidyFile( log, toolConfig, ninjaOutputFile, currentWorkingDirectory, toolVersionOutputFile, clangFormatExeInfo, customPackageFileFilter, clangFormatConfiguration, sortedPackageList, repairEnabled) log.LogPrint("Executing ninja format file.") RunHelper.RunNinja(log, ninjaExeInfo, ninjaOutputFile, currentWorkingDirectory, numBuildThreads, logOutput) return totalProcessedCount
def Process(self, currentDirPath: str, toolConfig: ToolConfig, localToolConfig: LocalToolConfig) -> None: config = Config(self.Log, toolConfig, 'sdk', localToolConfig.BuildVariantsDict, localToolConfig.AllowDevelopmentPlugins) if localToolConfig.DryRun: config.ForceDisableAllWrite() if localToolConfig.ToCDepth < 1: localToolConfig.ToCDepth = 1 elif localToolConfig.ToCDepth > 4: localToolConfig.ToCDepth = 4 config.PrintTitle() # Get the generator and see if its supported buildVariantConfig = BuildVariantConfigUtil.GetBuildVariantConfig(localToolConfig.BuildVariantsDict) generator = self.ToolAppContext.PluginConfigContext.GetGeneratorPluginById(localToolConfig.PlatformName, localToolConfig.Generator, buildVariantConfig, False, config.ToolConfig.CMakeConfiguration, localToolConfig.GetUserCMakeConfig()) PlatformUtil.CheckBuildPlatform(generator.PlatformName) config.LogPrint("Active platform: {0}".format(generator.PlatformName)) packageFilters = localToolConfig.BuildPackageFilters theFiles = MainFlow.DoGetFiles(config, toolConfig.GetMinimalConfig(), currentDirPath, localToolConfig.Recursive) generatorContext = GeneratorContext(config, self.ErrorHelpManager, packageFilters.RecipeFilterManager, config.ToolConfig.Experimental, generator) packages = MainFlow.DoGetPackages(generatorContext, config, theFiles, packageFilters) #topLevelPackage = PackageListUtil.GetTopLevelPackage(packages) #featureList = [entry.Name for entry in topLevelPackage.ResolvedAllUsedFeatures] for projectContext in config.ToolConfig.ProjectInfo.Contexts: rootDir = self.__TryLocateRootDirectory(config.ToolConfig.RootDirectories, projectContext.Location) if rootDir is None: raise Exception("Root directory not found for location {0}".format(projectContext.Location)) readmePath = IOUtil.Join(rootDir.ResolvedPath, "README.md") packageReadMeLines = TryLoadReadMe(config, readmePath) result = ProcessPackages(self.ToolAppContext, config, packages, rootDir, localToolConfig.ExtractArguments, toolConfig.BuildDocConfiguration, currentDirPath) if packageReadMeLines is not None: projectCaption = "# {0} {1}".format(projectContext.ProjectName, projectContext.ProjectVersion) packageReadMeLinesNew = TryReplaceSection(config, packageReadMeLines, "AG_PROJECT_CAPTION", [projectCaption], readmePath) if packageReadMeLinesNew is not None: packageReadMeLines = packageReadMeLinesNew packageReadMeLinesNew = TryReplaceSection(config, packageReadMeLines, "AG_DEMOAPPS", result, readmePath) if packageReadMeLinesNew is not None: packageReadMeLines = packageReadMeLinesNew packageReadMeLinesNew = TryInsertTableOfContents(config, packageReadMeLines, localToolConfig.ToCDepth, readmePath) if packageReadMeLinesNew is not None: packageReadMeLines = packageReadMeLinesNew SaveReadMe(config, readmePath, packageReadMeLines) elif config.Verbosity > 2: config.LogPrintWarning("No README.md found in {0}".format(rootDir.ResolvedPath))
def GetOutputFileName(self, config: Config, contentOutputPath: str, contentFileRecord: PathRecord, removeExtension: bool = False) -> str: relativePathToContentFile = contentFileRecord.RelativePath if removeExtension: extension = IOUtil.GetFileNameExtension(relativePathToContentFile) relativePathToContentFile = relativePathToContentFile[:-len( extension)] return IOUtil.Join(contentOutputPath, relativePathToContentFile)
def __ResolvePathIncludeDir(self, config: Config, allowNoInclude: bool) -> None: packagePath = self.PackageFile if packagePath is None: raise Exception("PackageFile can not be None") self.IncludePath = PackagePath(IOUtil.Join(packagePath.AbsoluteDirPath, self.BaseIncludePath), packagePath.PackageRootLocation) includeDirExist = os.path.isdir(self.IncludePath.AbsoluteDirPath) if not includeDirExist and (os.path.exists(self.IncludePath.AbsoluteDirPath) or not (allowNoInclude or config.DisableIncludeDirCheck)): raise PackageMissingRequiredIncludeDirectoryException(self.IncludePath.AbsoluteDirPath) if not includeDirExist and allowNoInclude: self.IncludePath = None
def __init__(self, config: Config, packages: List[Package], dstMakeFilename: str, templateExe: str, templateLib: str, generatorName: str, configVariantOptions: List[str]) -> None: super(GeneratorGNUmakefile, self).__init__() self.ConfigVariantOptions = configVariantOptions self.BldTemplate = IOUtil.ReadFile( IOUtil.Join(config.SDKConfigTemplatePath, "build.sh")) self.ExeTemplate = IOUtil.ReadFile( IOUtil.Join(config.SDKConfigTemplatePath, templateExe)) self.LibTemplate = IOUtil.ReadFile( IOUtil.Join(config.SDKConfigTemplatePath, templateLib)) for package in packages: if not package.ResolvedPlatformNotSupported: if package.Type == PackageType.Library: self.__GenerateLibraryBuildFile(config, generatorName, package, dstMakeFilename) elif package.Type == PackageType.Executable: self.__GenerateExecutableBuildFile(config, generatorName, package, dstMakeFilename)
def __TryAddAsCMakeLib(self, recipe: Optional[PackageExperimentalRecipe], package: Package) -> Optional[AndroidCMakeLib]: if recipe is None or recipe.ResolvedInstallLocation is None or recipe.Pipeline is None: return None if not PackageRecipeUtil.CommandListContainsBuildCMake(recipe.Pipeline.CommandList): return None path = "{0}".format(recipe.ResolvedInstallLocation) 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 Build(config: Config, currentPath: str, featureList: List[str]) -> None: contentBuildDir = __CONTENT_BUILD_DIR contentOutputDir = __CONTENT_OUTPUT_DIR contentBuildPath = IOUtil.Join(currentPath, contentBuildDir) contentOutputPath = IOUtil.Join(currentPath, contentOutputDir) if not IOUtil.IsDirectory(contentBuildPath): config.LogPrintVerbose( 1, "No '{0}' directory present at '{1}' so there is no content to process." .format(contentBuildDir, currentPath)) return packageBuildPath = IOUtil.Join(currentPath, config.GetBuildDir()) if not config.DisableWrite: IOUtil.SafeMakeDirs(packageBuildPath) toolFinder = ToolFinder(config) features = Features(config, featureList) Builder(config, packageBuildPath, contentBuildPath, contentOutputPath, features, toolFinder)
def __ExpandPathAndJoin(self, config: Config, package: Package, srcList: Optional[List[str]]) -> str: if srcList is None or len(srcList) <= 0: return '' if package.AbsolutePath is None: raise Exception("Invalid package") expandedList = [ CMakeGeneratorUtil.GetSDKBasedPathUsingCMakeVariable( config, IOUtil.Join(package.AbsolutePath, entry)) for entry in srcList ] return "\n " + "\n ".join(expandedList)
def __GetStaticLibsPaths(self, config: Config, package: Package, relativePathBuildLib: str) -> List[str]: """ return list of unique directories for dependencies. folders are SDK-root based """ libDirs = [] # type: List[str] for entry in package.ResolvedBuildOrder: if entry.Type == PackageType.Library: if entry.AbsolutePath != package.AbsolutePath and entry.AbsolutePath is not None: #skip package own directory # FIX: for proper variant support use "package.ResolvedMakeObjectPath" instead of the line below fullPath = IOUtil.Join(entry.AbsolutePath, relativePathBuildLib) fullPathSDK = config.ToPath(fullPath) # convert to SDK-based path if fullPathSDK not in libDirs: #append only unique paths libDirs.append(fullPathSDK) return libDirs
def __TryValidateInstallation( basicConfig: BasicConfig, validationEngine: ValidationEngine, package: Package, packagesToBuild: List[Package], recipePackageStateCache: RecipePackageStateCache) -> bool: if package.ResolvedDirectExperimentalRecipe is None: raise Exception("Invalid package") sourceRecipe = package.ResolvedDirectExperimentalRecipe installPath = sourceRecipe.ResolvedInstallPath if installPath is not None and not IOUtil.IsDirectory(installPath): basicConfig.LogPrintVerbose( 2, "Installation directory not located: {0}".format(installPath)) return False elif basicConfig.Verbosity >= 2: basicConfig.LogPrint( "Installation directory located at '{0}'".format(installPath)) # 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, __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, __g_BuildPackageInformationFilename): basicConfig.LogPrintVerbose( 2, "Install validator failed to load build information") return False return True
def __RunCMakeAndBuild(self, sourcePackage: Package, toolFinder: PackageToolFinder, recipeVariants: List[str], sourcePath: str, installPath: str, tempBuildPath: str, target: int, cmakeProjectName: str, configurationList: List[int], cmakeOptionList: List[str], allowSkip: bool) -> None: installedDependencyList = self.__BuildDependencyPathList(sourcePackage, sourcePackage.ResolvedExperimentalRecipeBuildOrder) if len(recipeVariants) <= 0: installedDependencies = self.__BuildDependencyPathString(installedDependencyList) if installedDependencies is not None and len(installedDependencies) > 0: cmakeOptionList = list(cmakeOptionList) cmakeOptionList.append(installedDependencies) self.Task.RunCMakeAndBuild(toolFinder, sourcePath, installPath, tempBuildPath, target, cmakeProjectName, configurationList, cmakeOptionList, allowSkip) return for variant in recipeVariants: self.BasicConfig.LogPrint("Recipe variant: {0}".format(variant)) self.BasicConfig.PushIndent() try: cmakeOptionListCopy = list(cmakeOptionList) if len(installedDependencyList) > 0: installedDependencyListCopy = [IOUtil.Join(entry, variant) for entry in installedDependencyList] installedDependencies = self.__BuildDependencyPathString(installedDependencyListCopy) cmakeOptionListCopy.append(installedDependencies) if self._IsAndroid: # FIX: Set this depending on package type if not AndroidUtil.UseNDKCMakeToolchain(): optionList = ["-DCMAKE_SYSTEM_VERSION={0}".format(AndroidUtil.GetMinimumSDKVersion()), "-DCMAKE_ANDROID_ARCH_ABI={0}".format(variant)] else: optionList = ["-DANDROID_PLATFORM=android-{0}".format(AndroidUtil.GetMinimumSDKVersion()), "-DANDROID_ABI={0}".format(variant)] cmakeOptionListCopy += optionList installPathCopy = IOUtil.Join(installPath, variant) tempBuildPathCopy = IOUtil.Join(tempBuildPath, variant) IOUtil.SafeMakeDirs(tempBuildPathCopy) self.Task.RunCMakeAndBuild(toolFinder, sourcePath, installPathCopy, tempBuildPathCopy, target, cmakeProjectName, configurationList, cmakeOptionListCopy, allowSkip) finally: self.BasicConfig.PopIndent()
def __GetTempDirectoryName(self, sourceCommand: XmlRecipePipelineCommand) -> str: if self.__SourcePackage is None or self.__CommandList is None: raise Exception( "__GetTempDirectoryName called outside begin/end block") if self.__SourcePackage.ResolvedDirectExperimentalRecipe is None: raise Exception("Invalid package") rootPath = self.GetBuildPath( self.__SourcePackage.ResolvedDirectExperimentalRecipe) stepString = "{0:0>4}_{1}".format(len(self.__CommandList), sourceCommand.CommandName) return IOUtil.Join(rootPath, stepString)
def __init__(self, config: Config, packages: List[Package], platformName: str, activeGenerator: GeneratorBase) -> None: super(GeneratorGitIgnore, self).__init__() libTemplate = IOUtil.TryReadFile( IOUtil.Join(config.SDKConfigTemplatePath, "Template_gitignore_lib.txt")) exeTemplate = IOUtil.TryReadFile( IOUtil.Join(config.SDKConfigTemplatePath, "Template_gitignore_exe.txt")) generatorIgnoreDict = activeGenerator.GetPackageGitIgnoreDict() for package in packages: if package.Type == PackageType.Library: self.__GenerateLibraryBuildFile(config, package, platformName, libTemplate, generatorIgnoreDict) elif package.Type == PackageType.Executable: self.__GenerateLibraryBuildFile(config, package, platformName, exeTemplate, generatorIgnoreDict)
def GetAndroidProjectDir( self, config: Config, package: Package, appPackageTemplateInfo: Optional[ AndroidGeneratorUtil.AppPackageTemplateInfo] = None ) -> str: """ Get the android project dir of the package, this is the dir that the gradle build reside in """ appPackageTemplateInfo = AndroidGeneratorUtil.AppPackageTemplateInfo( package ) if appPackageTemplateInfo is None else appPackageTemplateInfo return IOUtil.Join(config.SDKPathAndroidProjectDir, appPackageTemplateInfo.ProjectPathName)
def _GetPackageBuildDir(generatorConfig: GeneratorConfig, cmakeConfig: GeneratorCMakeConfig, package: Package) -> str: buildPath = cmakeConfig.BuildDir if package.AbsolutePath is None: raise Exception("package.Absolute path is None") rootDir = generatorConfig.ToolConfig.TryFindRootDirectory( package.AbsolutePath) if rootDir is None: raise Exception("could not find root dir for package") relativePath = package.AbsolutePath[len(rootDir.ResolvedPathEx):] return IOUtil.Join(buildPath, relativePath)
def __init__(self, log: Log, variableProcessor: VariableProcessor, recipeBuilderSetup: Optional[RecipeBuilderSetup], platformName: str, cmakeConfig: GeneratorCMakeConfig) -> None: super().__init__() self.__Log = log # type: Log self.__VariableProcessor = variableProcessor # type: VariableProcessor self.IsEnabled = recipeBuilderSetup is not None # type: bool self.TargetLocation = None # Optional[ResolvedPath] self.DownloadCacheRootPath = None # Optional[str] self.__TempRootPath = None # Optional[str] self.__TempPipelineRootPath = None # Optional[str] self.InstallRootLocation = None # Optional[ResolvedPath] self.ReadonlyCache_DownloadCacheRootPath = None # Optional[str] if self.IsEnabled and recipeBuilderSetup is not None: targetLocation = recipeBuilderSetup.TargetLocation readonlyCachePath = recipeBuilderSetup.ReadonlyCachePath if not IOUtil.IsAbsolutePath(targetLocation.ResolvedPath): raise Exception("Install area path is not absolute: '{0}'".format(targetLocation.ResolvedPath)) if not readonlyCachePath is None and not IOUtil.IsAbsolutePath(readonlyCachePath): raise Exception("Install area readonly cache path is not absolute: '{0}'".format(readonlyCachePath)) self.TargetLocation = targetLocation self.DownloadCacheRootPath = IOUtil.Join(targetLocation.ResolvedPath, ".DownloadCache") self.__TempRootPath = IOUtil.Join(targetLocation.ResolvedPath, ".Temp") baseTempDirectory = IOUtil.Join(self.__TempRootPath, "pipeline") baseTempDirectory = IOUtil.Join(baseTempDirectory, platformName) self.__TempPipelineRootPath = IOUtil.Join(baseTempDirectory, cmakeConfig.GeneratorRecipeShortName) sourceBaseInstallDirectory = IOUtil.Join(targetLocation.SourcePath, platformName) sourceInstallRootPath = IOUtil.Join(sourceBaseInstallDirectory, cmakeConfig.GeneratorRecipeShortName) baseInstallDirectory = IOUtil.Join(targetLocation.ResolvedPath, platformName) installRootPath = IOUtil.Join(baseInstallDirectory, cmakeConfig.GeneratorRecipeShortName) self.InstallRootLocation = ResolvedPath(sourceInstallRootPath, installRootPath) self.ReadonlyCache_DownloadCacheRootPath = None if readonlyCachePath is None else IOUtil.Join(readonlyCachePath, ".DownloadCache")
def __init__(self, configSDKConfigTemplatePath: str, configDisableWrite: bool, packages: List[Package], platformName: str, activeGenerator: GeneratorBase) -> None: super().__init__() virtualTemplate = IOUtil.TryReadFile( IOUtil.Join(configSDKConfigTemplatePath, "Template_gitignore_virtual.txt")) headerLibTemplate = IOUtil.TryReadFile( IOUtil.Join(configSDKConfigTemplatePath, "Template_gitignore_headerlib.txt")) libTemplate = IOUtil.TryReadFile( IOUtil.Join(configSDKConfigTemplatePath, "Template_gitignore_lib.txt")) exeTemplate = IOUtil.TryReadFile( IOUtil.Join(configSDKConfigTemplatePath, "Template_gitignore_exe.txt")) generatorIgnoreDict = activeGenerator.GetPackageGitIgnoreDict() for package in packages: if package.Type == PackageType.Library: self.__GenerateLibraryBuildFile(configDisableWrite, package, platformName, libTemplate, generatorIgnoreDict) elif package.Type == PackageType.Executable: self.__GenerateLibraryBuildFile(configDisableWrite, package, platformName, exeTemplate, generatorIgnoreDict) elif package.Type == PackageType.HeaderLibrary: self.__GenerateLibraryBuildFile(configDisableWrite, package, platformName, headerLibTemplate, generatorIgnoreDict) else: self.__GenerateLibraryBuildFile(configDisableWrite, package, platformName, virtualTemplate, generatorIgnoreDict)
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 TryGenerateBuildReport(log: Log, generatorName: str, package: Package) -> Optional[GeneratorBuildReport]: if package.IsVirtual: return None if package.Type != PackageType.Executable: return GeneratorBuildReport(None) commandCWD = GeneratorAndroidGradleCMakeUtil.GetAndroidProjectDir(package) gradleBuildConfigVariable = "${{{0}}}".format(LocalMagicBuildVariants.GradleBuildConfig) buildCommandArguments = [gradleBuildConfigVariable] buildCommand = GeneratorAndroidGradleCMakeUtil.GetPlatformGradleCommand() buildCommand = IOUtil.Join(commandCWD, buildCommand) buildCommandReport = GeneratorCommandReport(False, buildCommand, buildCommandArguments, [], commandCWD) return GeneratorBuildReport(buildCommandReport)
def __init__(self, basicConfig: BasicConfig, sourceCommand: Optional[XmlRecipePipelineCommand], pipelineInfo: PipelineInfo) -> None: super().__init__(basicConfig, sourceCommand, pipelineInfo) self.Skip = False self.AutoCreateDstDirectory = True if sourceCommand is None or sourceCommand.OutputPath is None or len( sourceCommand.OutputPath) <= 0: self.FinalDstPath = self.Info.CombinedDstRootPath else: self.FinalDstPath = IOUtil.Join(self.Info.CombinedDstRootPath, sourceCommand.OutputPath) self.JoinCommandList = [] if sourceCommand is None else self.__CreateJoinCommandList( sourceCommand.JoinCommandList)
def __ResolvePaths(self, config: Config, packagePath: PackagePath, allowNoInclude: bool) -> None: rootRelativeDirPath = packagePath.RootRelativeDirPath if not self.IsVirtual: sourcePath = self.BaseSourcePath if self.PackageLanguage == PackageLanguage.CPP: self.__ResolvePathIncludeDir(config, allowNoInclude) elif self.PackageLanguage == PackageLanguage.CSharp: #sourcePath = self.Name pass else: raise UnsupportedException("Unsupported package language: {0}".format(self.PackageLanguage)) self.SourcePath = PackagePath(IOUtil.Join(rootRelativeDirPath, sourcePath), packagePath.PackageRootLocation) self.ContentPath = PackagePath(IOUtil.Join(rootRelativeDirPath, ToolSharedValues.CONTENT_FOLDER_NAME), packagePath.PackageRootLocation) self.ContentSourcePath = PackagePath(IOUtil.Join(rootRelativeDirPath, ToolSharedValues.CONTENT_BUILD_FOLDER_NAME), packagePath.PackageRootLocation) if not os.path.isdir(self.SourcePath.AbsoluteDirPath) and not config.DisableSourceDirCheck: raise PackageMissingRequiredSourceDirectoryException(self.SourcePath.AbsoluteDirPath) elif self.Type == PackageType.HeaderLibrary: if self.PackageLanguage == PackageLanguage.CPP: self.__ResolvePathIncludeDir(config, allowNoInclude) else: raise UsageErrorException("HeaderLibrary is only supported for C++")
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)
def __AppendFilesUsingWildcard(self, log: Log, rUniqueFiles: Dict[str, ContentFileRecord], rFiles: List[ContentFileRecord], sourceRoot: ContentRootRecord, sourceEntry: str, absolutePath: str, directory: str, filename: str) -> None: if not IOUtil.IsDirectory(directory): raise Exception("No directory named '{0}' found".format(directory)) candidateFiles = IOUtil.GetFilesAt(directory, False) for candidate in candidateFiles: if fnmatch.fnmatch(candidate, filename): absPath = IOUtil.Join(directory, candidate) self.__AppendFile(log, rUniqueFiles, rFiles, sourceRoot, sourceEntry, absPath)
def __init__(self, log: Log, package: Package, clangFormatConfiguration: ClangFormatConfiguration, filteredFiles: Optional[List[str]]) -> None: allFiles = [] # type: List[ResolvedPath] if package.ResolvedBuildAllIncludeFiles is not None and package.AllowCheck and not package.IsVirtual: if package.AbsolutePath is None or package.ResolvedBuildSourceFiles is None: raise Exception("Invalid package") if filteredFiles is None: for fileName in package.ResolvedBuildAllIncludeFiles: fullPath = IOUtil.Join(package.AbsolutePath, fileName) # Only process files with the expected extension if PerformClangUtil.IsValidExtension(fileName, clangFormatConfiguration.FileExtensions): allFiles.append(ResolvedPath(fileName, fullPath)) for fileName in package.ResolvedBuildSourceFiles: fullPath = IOUtil.Join(package.AbsolutePath, fileName) if PerformClangUtil.IsValidExtension(fileName, clangFormatConfiguration.FileExtensions): allFiles.append(ResolvedPath(fileName, fullPath)) if package.ResolvedContentFiles is not None: for resolvedPath in package.ResolvedContentFiles: if PerformClangUtil.IsValidExtension(resolvedPath.ResolvedPath, clangFormatConfiguration.FileExtensions): allFiles.append(self.__GetResolvedPath(package, resolvedPath)) if package.ResolvedContentBuilderSyncInputFiles is not None: for resolvedPath in package.ResolvedContentBuilderSyncInputFiles: if PerformClangUtil.IsValidExtension(resolvedPath.ResolvedPath, clangFormatConfiguration.FileExtensions): allFiles.append(self.__GetResolvedPath(package, resolvedPath)) if package.ResolvedContentBuilderBuildInputFiles is not None: for resolvedPath in package.ResolvedContentBuilderBuildInputFiles: if PerformClangUtil.IsValidExtension(resolvedPath.ResolvedPath, clangFormatConfiguration.FileExtensions): allFiles.append(self.__GetResolvedPath(package, resolvedPath)) else: for fileEntry in filteredFiles: allFiles.append(self.__GetResolvedPathFromAbsPath(package, fileEntry)) self.AllFiles = allFiles
def BuildTargetLinkLibrariesForDirectDependencies( config: Config, package: Package, templatePackageDependencyTargetLinkLibraries: str, ignoreLibs: Optional[List[str]] = None) -> str: if ignoreLibs is None: ignoreLibs = [] if package.ResolvedDirectDependencies is None: raise Exception("Invalid package") isExternalLibrary = package.Type == PackageType.ExternalLibrary deps = "" for entry1 in package.ResolvedDirectDependencies: if entry1.Package.Type != PackageType.ToolRecipe: deps += "\n {0} {1}".format( GetAccessTypeString(package, entry1.Access, False), GetPackageName(entry1.Package)) # deps += "\n {0} {1}".format(GetAccessTypeString(package, entry1.Access), GetAliasPackageName(entry1.Package)) # FIX: handle debug libraries for entry2 in package.ResolvedDirectExternalDependencies: libraryName = LibUtil.ToUnixLibName(entry2.Name) if libraryName not in ignoreLibs: if entry2.Type == ExternalDependencyType.StaticLib: location = entry2.Location if entry2.Location and not isExternalLibrary else "" fullPathLinkDir = Util.ChangeToCMakeEnvVariables( IOUtil.Join(location, libraryName)) deps += "\n {0} {1}".format( GetAccessTypeString(package, entry2.Access, False), fullPathLinkDir) if entry2.Type == ExternalDependencyType.Find: linkName = "${%s_LIBRARY}" % (libraryName) deps += "\n {0} {1}".format( GetAccessTypeString(package, entry2.Access, False), linkName) else: config.LogPrintVerbose( 2, "INFO: Force ignored '{0}'".format(libraryName)) if len(deps) <= 0: return "" content = templatePackageDependencyTargetLinkLibraries content = content.replace("##PACKAGE_DIRECT_DEPENDENCIES##", deps) return content
def DoExecute(self) -> None: sourcePackage = self.Info.SourcePackage recipeVariants = sourcePackage.ResolvedRecipeVariants packageToolFinder = PackageToolFinder(sourcePackage.ResolvedToolDependencyOrder) optionList = shlex.split(self.__SourceCommand.Options) optionList = self.__ApplyVariables(optionList) target = self.__SourceCommand.Target installPath = self.FinalDstPath sourcePath = self.Info.SrcRootPath if self.Source is not None: sourcePath = IOUtil.Join(sourcePath, self.Source) self.__RunCMakeAndBuild(sourcePackage, packageToolFinder, recipeVariants, sourcePath, installPath, self.Info.DstRootPath, target, self.__SourceCommand.Project, self.__SourceCommand.ConfigurationList, optionList, self.AllowSkip)
def __GenerateCommandList(self, log: Log, commandList: List[XmlRecipePipelineBuildCommand], pipelineInfo: PipelineInfo, sourceRecipeName: str) -> List[PipelineCommand]: theList = [] # type: List[PipelineCommand] commandIndex = 0 for command in commandList: dstSubDir = "{:04}".format(commandIndex) commandDstRootPath = IOUtil.Join(pipelineInfo.DstRootPath, dstSubDir) theList.append( self.__CreateCommand(log, command, pipelineInfo, commandDstRootPath, sourceRecipeName)) commandIndex = commandIndex + 1 return theList
def __ResolvePathIncludeDir(self, config: Config, allowNoInclude: bool) -> None: if self.AbsolutePath is None: raise Exception("AbsolutePath can not be None") self.AbsoluteIncludePath = IOUtil.NormalizePath( IOUtil.Join(self.AbsolutePath, self.BaseIncludePath)) includeDirExist = os.path.isdir(self.AbsoluteIncludePath) if not includeDirExist and ( os.path.exists(self.AbsoluteIncludePath) or not (allowNoInclude or config.DisableIncludeDirCheck)): raise PackageMissingRequiredIncludeDirectoryException( self.AbsoluteIncludePath) if not includeDirExist and allowNoInclude: self.AbsoluteIncludePath = None
def ResolvePathToAbsolute(self, pathName: str, tag: Optional[object] = None) -> str: """ Resolve a path to a absolute one The path can be relative to the ${PROJECT_ROOT} or It can start with a environment variable $() It can start with a variable ${} """ resultPath = self.__DoBasicPathResolve(pathName, pathName, tag) # type: str if not os.path.isabs(resultPath): absPath = IOUtil.Join(MagicStrings.ProjectRoot, pathName) resultPath = self.__DoBasicPathResolve(absPath, absPath, tag) if not os.path.isabs(resultPath): raise EnvironmentError("'{0}' could not be made absolute '{1}".format(pathName, resultPath)) return resultPath