def RunCMakeAndBuild(self, toolFinder: PackageToolFinder, sourcePath: str, installPath: str, tempBuildPath: str, target: CMakeTargetType, cmakeProjectName: str, configurationList: List[BuildVariantConfig], cmakeOptionList: List[str], allowSkip: bool) -> None: if allowSkip and IOUtil.IsDirectory(installPath): self.LogPrint("Running cmake and build on source '{0}' and installing to '{1}' was skipped since install directory exist.".format(sourcePath, installPath)) return self.LogPrint("Running cmake and build on source '{0}' and installing to '{1}'".format(sourcePath, installPath)) try: self.CreateDirectory(tempBuildPath) # Add platform specific commands if len(self.CMakeConfig.CMakeConfigRecipeArguments) > 0: cmakeOptionList += self.CMakeConfig.CMakeConfigRecipeArguments buildEnv = os.environ.copy() # type: Dict[str, str] self.__ApplyPath(buildEnv, toolFinder.ToolPaths) self.__DoBuildNow(toolFinder, sourcePath, installPath, tempBuildPath, target, cmakeProjectName, configurationList, cmakeOptionList, buildEnv) except Exception: # A error occurred remove the install dir self.LogPrint("* A error occurred removing '{0}' to be safe.".format(installPath)) IOUtil.SafeRemoveDirectoryTree(installPath, True) raise
def RunGitClone(self, sourcePath: str, branch: str, targetPath: str) -> None: if IOUtil.IsDirectory(targetPath): self.LogPrint("Running git clone {0} {1}, skipped since it exist.".format(sourcePath, targetPath)) return self.DoPrint("Running git clone {0} {1}".format(sourcePath, targetPath)) try: self.__RunGitClone(sourcePath, targetPath, branch) except Exception: # A error occurred removing the targetPath self.LogPrint("* A error occurred removing '{0}' to be safe.".format(targetPath)) IOUtil.SafeRemoveDirectoryTree(targetPath, True) raise
def __DoSafeRemoveDirectoryTree(self, dstPath: str, retryCount: int) -> None: # A error occurred removing the targetPath if not IOUtil.IsDirectory(dstPath) or retryCount >= 2: return try: self.LogPrint("* A error occurred removing '{0}' to be safe.".format(dstPath)) IOUtil.SafeRemoveDirectoryTree(dstPath, False) except Exception: self.LogPrint("* Failed to remove '{0}', trying again in 1sec.".format(dstPath)) time.sleep(1) self.__DoSafeRemoveDirectoryTree(dstPath, retryCount + 1) raise
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 __RemoveInvalidInstallation( self, log: Log, sourceRecipe: PackageExperimentalRecipe) -> None: if sourceRecipe is None or sourceRecipe.ResolvedInstallPath is None or sourceRecipe.Pipeline is None: return # the external installs dont have a associated pipeline so this should be safe # but we check the build type as well just to be safe if IOUtil.IsDirectory(sourceRecipe.ResolvedInstallPath): if sourceRecipe.Type != RecipeType.Build: log.DoPrintWarning( "The sourceRecipe type was not of the expected type, aborting delete to be safe" ) return log.LogPrint("Removing invalid content at '{0}'".format( sourceRecipe.ResolvedInstallPath)) IOUtil.SafeRemoveDirectoryTree(sourceRecipe.ResolvedInstallPath)
def Process(self, currentDirPath: str, toolConfig: ToolConfig, localToolConfig: LocalToolConfig) -> None: config = Config(self.Log, toolConfig, localToolConfig.PackageConfigurationType, localToolConfig.BuildVariantsDict, localToolConfig.AllowDevelopmentPlugins) # Disable downloads and writes if config.ToolConfig.Experimental is not None: config.ToolConfig.Experimental.AllowDownloads = False config.ForceDisableAllWrite() if localToolConfig.IgnoreNotSupported: config.IgnoreNotSupported = True self.Log.PrintTitle() if not localToolConfig.ForceYes and not self.__AskYesNo("Delete all build directories"): return packageFilters = localToolConfig.BuildPackageFilters generator = PluginConfig.GetGeneratorPluginById(localToolConfig.PlatformName, False) theFiles = MainFlow.DoGetFiles(config, toolConfig.GetMinimalConfig(), currentDirPath, localToolConfig.Recursive) generatorContext = GeneratorContext(config, config.ToolConfig.Experimental, generator) packages = MainFlow.DoGetPackages(generatorContext, config, theFiles, packageFilters, autoAddRecipeExternals=False) topLevelPackage = PackageListUtil.GetTopLevelPackage(packages) requestedFiles = None if config.IsSDKBuild else theFiles self.Log.LogPrint("Deleting package build directories") for package in topLevelPackage.ResolvedBuildOrder: if package.AbsoluteBuildPath is not None: # While the path is most likely normalized we force it here removePath = IOUtil.NormalizePath(package.AbsoluteBuildPath) if IOUtil.IsDirectory(removePath): self.Log.LogPrint("- Deleting '{0}'".format(removePath)) drive, tail = os.path.splitdrive(removePath) driveId = IOUtil.NormalizePath(drive).lower() removePathId = removePath.lower() # some basic checks to prevent deletes of '/' or a drive letter. if ('../' in removePath or '/..' in removePath or removePath == '/' or removePath == '..' or len(removePath) <= 0 or removePathId==driveId or removePath.endswith('/')): raise Exception("Invalid path format '{0}'".format(removePath)) IOUtil.SafeRemoveDirectoryTree(removePath)
def Process(self, currentDirPath: str, toolConfig: ToolConfig, localToolConfig: LocalToolConfig) -> None: config = Config(self.Log, toolConfig, localToolConfig.PackageConfigurationType, localToolConfig.BuildVariantsDict, localToolConfig.AllowDevelopmentPlugins) # Disable downloads and writes if config.ToolConfig.Experimental is not None: config.ToolConfig.Experimental.AllowDownloads = False config.ForceDisableAllWrite() if localToolConfig.IgnoreNotSupported: config.IgnoreNotSupported = True self.Log.PrintTitle() if not localToolConfig.ForceYes and not self.__AskYesNo("Delete all build directories"): return packageFilters = localToolConfig.BuildPackageFilters buildVariantConfig = BuildVariantConfigUtil.GetBuildVariantConfig(localToolConfig.BuildVariantsDict) generator = self.ToolAppContext.PluginConfigContext.GetGeneratorPluginById(localToolConfig.PlatformName, localToolConfig.Generator, buildVariantConfig, config.ToolConfig.DefaultPackageLanguage, config.ToolConfig.CMakeConfiguration, localToolConfig.GetUserCMakeConfig(), False) theFiles = MainFlow.DoGetFiles(config, toolConfig.GetMinimalConfig(generator.CMakeConfig), currentDirPath, localToolConfig.Recursive) generatorContext = GeneratorContext(config, self.ErrorHelpManager, packageFilters.RecipeFilterManager, config.ToolConfig.Experimental, generator) packages = MainFlow.DoGetPackages(generatorContext, config, theFiles, packageFilters, autoAddRecipeExternals=False) topLevelPackage = PackageListUtil.GetTopLevelPackage(packages) #requestedFiles = None if config.IsSDKBuild else theFiles self.Log.LogPrint("Deleting package build directories") for package in topLevelPackage.ResolvedBuildOrder: if package.AbsoluteBuildPath is not None: # While the path is most likely normalized we force it here removePath = IOUtil.NormalizePath(package.AbsoluteBuildPath) if IOUtil.IsDirectory(removePath): self.Log.LogPrint("- Deleting '{0}'".format(removePath)) if IOUtil.IsDriveRootPath(removePath): raise Exception("Invalid path format '{0}'".format(removePath)) IOUtil.SafeRemoveDirectoryTree(removePath)
def __DoBuildPackagesInOrder( config: Config, generatorContext: GeneratorContext, resolvedBuildOrder: List[Package], builderSettings: BuilderSettings, packageRecipeResultManager: PackageRecipeResultManager) -> None: basicConfig = generatorContext.BasicConfig if not generatorContext.RecipePathBuilder.IsEnabled: basicConfig.LogPrintVerbose( 3, "External building has been disabled in the Project.gen file") return if generatorContext.RecipePathBuilder.TargetLocation is None: raise Exception("Invalid path builder") # Claim the 'package' install directory to prevent multiple builds from using the same # as it would give concurrency issues BuildAreaInfoFileUtil.ProcessInstallDirClaim( basicConfig, generatorContext.RecipePathBuilder.TargetLocation.ResolvedPath, config.SDKPath, builderSettings.ForceClaimInstallArea, __g_installAreaInformationFilename) if resolvedBuildOrder is None: basicConfig.LogPrintVerbose(2, "No recipes to build") return # Filter all packages that don't have a experimental recipe resolvedBuildOrder = [ entry for entry in resolvedBuildOrder if not entry.ResolvedDirectExperimentalRecipe is None ] if len(resolvedBuildOrder) == 0: basicConfig.LogPrintVerbose(2, "No recipes to build") return recipePackageStateCache = RecipePackageStateCache(basicConfig) validationEngine = ValidationEngine(basicConfig, generatorContext.VariableProcessor, packageRecipeResultManager) missingPackagesInBuildOrder = __FindMissingInstallations( basicConfig, validationEngine, resolvedBuildOrder, recipePackageStateCache) builder = PipelineCommandBuilder(generatorContext, builderSettings.CheckBuildCommands, builderSettings.BuildThreads) recipeRecords = __CreatePipelines(basicConfig, builder, missingPackagesInBuildOrder) for recipeRecord in recipeRecords: basicConfig.LogPrint("Package location: {0}".format( recipeRecord.SourcePackage.AbsolutePath)) try: basicConfig.PushIndent() if not recipeRecord.SourcePackage.ResolvedPlatformDirectSupported: raise Exception( "The package '{0}' is not supported on this platform". format(recipeRecord.SourcePackage.Name)) if not recipeRecord.Pipeline is None: basicConfig.DoPrint("Building package: {0}".format( recipeRecord.SourcePackage.Name)) if builderSettings.PreDeleteBuild: # We clear the build path to prepare for a new build IOUtil.SafeRemoveDirectoryTree( recipeRecord.Pipeline.BuildPath) for command in recipeRecord.Pipeline.CommandList: if not config.IsDryRun: command.Execute() # We finished building, so lets save some information about what we did BuildInfoFileUtil.SaveBuildInformation( basicConfig, recipeRecord, recipePackageStateCache, __g_BuildPackageInformationFilename) if builderSettings.PostDeleteBuild: # We clear the build path if a build is successfull IOUtil.SafeRemoveDirectoryTree( recipeRecord.Pipeline.BuildPath, True) else: # Since we are trying to build this it means that the installation validation failed earlier and # we apparently have no pipelines that could remedy it, so force the install validation to occur so # we fail early as 'dependent' pipes might fail to build due to this # generatorContext.RecipeFilterManager if generatorContext.RecipeFilterManager.AllRecipesEnabled or recipeRecord.SourcePackage.Name in generatorContext.RecipeFilterManager.ContentDict: basicConfig.DoPrintWarning( "Missing installation of package '{0}' and no recipe for solving it is available" .format(recipeRecord.SourcePackage.Name)) else: basicConfig.LogPrintVerbose( 4, "Package '{0}' recipe not enabled".format( recipeRecord.SourcePackage.Name)) validationEngine.Process(recipeRecord.SourcePackage) finally: basicConfig.PopIndent() validationEngine.Process(recipeRecord.SourcePackage) packageCount = len(recipeRecords) if packageCount > 0: basicConfig.LogPrint("Build {0} packages".format(packageCount)) else: basicConfig.LogPrintVerbose(2, "No recipe was build!")