def __RunToolMainForSanityCheck(self, currentDir: str, toolConfig: ToolConfig, localToolConfig: LocalToolConfig, templateDict: Dict[ str, List[XmlNewTemplateFile]], debugMode: bool) -> None: if localToolConfig.Template == '*': raise Exception("Usage error") localToolConfig.ProjectName = "{0}_{1}".format( GlobalStrings.SanityCheckProjectName, localToolConfig.Template) localToolConfig.Force = True try: if debugMode: generatedDir = IOUtil.Join(currentDir, localToolConfig.ProjectName) if IOUtil.IsDirectory(generatedDir): return print(("Sanity check of template '{0}' begin".format( localToolConfig.Template))) self.__ToolMainEx(currentDir, toolConfig, localToolConfig, templateDict, True) print(("Sanity check of template '{0}' ended successfully".format( localToolConfig.Template))) except: print(("Sanity check of template '{0}' failed".format( localToolConfig.Template))) raise finally: if not debugMode: projectDir = IOUtil.Join(currentDir, localToolConfig.ProjectName) if IOUtil.IsDirectory(projectDir): shutil.rmtree(projectDir)
def __GetEnvironmentVariable(self, name: str) -> str: # For cache entries we allow the variable to not be defined, but if it is defned we retrieve is as normal value = IOUtil.TryGetEnvironmentVariable(name) if value is None: raise EnvironmentError( "{0} environment variable not set".format(name)) value = IOUtil.NormalizePath(value) if value is None: raise EnvironmentError( "{0} environment variable not set".format(name)) if not IOUtil.IsAbsolutePath(value): raise EnvironmentError( "{0} environment path '{1}' is not absolute".format( name, value)) if value.endswith("/"): raise EnvironmentError( "{0} environment path '{1}' not allowed to end with '/' or '\'" .format(name, value)) # Create the directory if it didnt exist if not IOUtil.IsDirectory(value) and not IOUtil.Exists(value): self.__Log.LogPrint( "The directory '{0}' did not exist, creating it".format(value)) IOUtil.SafeMakeDirs(value) if not IOUtil.IsDirectory(value): raise EnvironmentError( "The {0} environment variable content '{1}' does not point to a valid directory" .format(name, value)) return value
def __RunToolMainForSanityCheck(self, currentDir: str, toolConfig: ToolConfig, localToolConfig: LocalToolConfig, templateDict: Dict[str, List[XmlNewTemplateFile]], debugMode: bool, templateList: List[str]) -> None: currentDir = IOUtil.Join(currentDir, GlobalStrings.SanityCheckDir) IOUtil.SafeMakeDirs(currentDir) if not IOUtil.IsDirectory(currentDir): raise Exception("could not create work directory: '{0}'".format(currentDir)) isBuilding = False try: for currentTemplateName in templateList: if currentTemplateName == '*' or currentTemplateName.startswith('/') or '..' in currentTemplateName: raise Exception("Usage error") localToolConfig.Template = currentTemplateName localToolConfig.ProjectName = "{0}_{1}".format(GlobalStrings.SanityCheckProjectName, localToolConfig.Template) localToolConfig.Force = True if debugMode: generatedDir = IOUtil.Join(currentDir, localToolConfig.ProjectName) if IOUtil.IsDirectory(generatedDir): continue print(("Generating sanity project for template '{0}' begin".format(localToolConfig.Template))) self.__ToolMainEx(currentDir, toolConfig, localToolConfig, templateDict, False) print(("Generating sanity project for template '{0}' ended successfully".format(localToolConfig.Template))) isBuilding = True config = Config(self.Log, toolConfig, 'sdk', localToolConfig.BuildVariantsDict, localToolConfig.AllowDevelopmentPlugins) print(("Building sanity projects for all template begin {0}".format(localToolConfig.Template))) self.__BuildNow(config, currentDir, True) print(("Building sanity project for template end {0}".format(localToolConfig.Template))) except: if not isBuilding: print("Sanity check of template '{0}' failed".format(localToolConfig.Template)) else: print("Sanity build of templates failed") raise finally: if not debugMode: for currentTemplateName in templateList: if currentTemplateName == '*' or currentTemplateName.startswith('/') or '..' in currentTemplateName: raise Exception("Usage error") projectName = "{0}_{1}".format(GlobalStrings.SanityCheckProjectName, currentTemplateName) projectDir = IOUtil.Join(currentDir, projectName) if IOUtil.IsDirectory(projectDir): shutil.rmtree(projectDir)
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
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)
def Build(log: Log, configBuildDir: str, configDisableWrite: bool, toolConfig: ToolConfig, packagePath: PackagePath, featureList: List[str], outputPath: Optional[str] = None) -> None: currentPath = packagePath.AbsoluteDirPath contentBuildDir = ToolSharedValues.CONTENT_BUILD_FOLDER_NAME contentBuildPath = IOUtil.Join(currentPath, contentBuildDir) contentOutputPath = GetContentOutputPath( packagePath) if outputPath is None else outputPath if not IOUtil.IsDirectory(contentBuildPath): log.LogPrintVerbose( 1, "No '{0}' directory present at '{1}' so there is no content to process." .format(contentBuildDir, currentPath)) return packageBuildPath = IOUtil.Join(currentPath, configBuildDir) if not configDisableWrite: IOUtil.SafeMakeDirs(packageBuildPath) contentProcessorManager = GetContentProcessorManager( log, toolConfig, featureList) Builder(log, configDisableWrite, toolConfig, packageBuildPath, contentBuildPath, contentOutputPath, contentProcessorManager)
def DoExecute(self) -> None: try: dstPath = self.Info.DstRootPath if not self.Info.AllowDownloads and not IOUtil.IsDirectory( dstPath): raise Exception( "Could not git clone {0} to {1} as downloads have been disabled. Enable downloads or clone it manually." .format(self.__SourceCommand.URL, dstPath)) remoteTag = self.__SourceCommand.Tag self.Task.RunGitClone(self.__SourceCommand.URL, remoteTag, dstPath) if len(remoteTag) <= 0 and self.__SourceCommand.Hash is not None: self.Task.RunGitCheckout(dstPath, self.__SourceCommand.Hash) # get the repo hash hashStr = self.Task.GetCurrentHash(dstPath) if self.__SourceCommand.Hash is None: if self.Log.Verbosity >= 1: self.Log.LogPrintWarning( "No hash value defined for repo {0} which has a hash value of {1}" .format(dstPath, hashStr)) elif hashStr != self.__SourceCommand.Hash: raise Exception( "The repo {0} has a hash of {1} which did not match the expected value of {2}" .format(dstPath, hashStr, self.__SourceCommand.Hash)) elif self.Log.Verbosity >= 2: self.LogPrint( "The cloned repo {0} hash was {1} as expected.".format( dstPath, hashStr)) except Exception: self.__DoSafeRemoveDirectoryTree(dstPath, 0) raise
def __GetFailedFileCheckExtraHelpString(self, sourcePath: str) -> str: directoryName = IOUtil.GetDirectoryName(sourcePath) if not directoryName or IOUtil.IsDirectory(directoryName): return "" #filename = IOUtil.GetDirectoryName(sourcePath) return " The parent directory '{0}' did not exist either.".format( directoryName)
def __DoValidateAddHeaders( self, rErrorRecordList: List[ErrorRecord], installationPath: Optional[str], command: XmlRecipeValidateCommandAddHeaders ) -> Tuple[bool, Optional[str]]: if self.__BasicConfig.Verbosity >= 4: self.__BasicConfig.LogPrint("ValidateAddHeaders '{0}'".format( command.Name)) result, path = self.__TryResolvePath(rErrorRecordList, installationPath, command.Name, False) 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.IsDirectory(path): rErrorRecordList.append( ErrorRecord( ErrorClassification.Critical, "Path '{0}' resolved to '{1}' which is not a directory.". format(command.Name, path))) return False, path return True, path
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 RunUnpack(self, packedFilePath: str, dstPath: str) -> None: if not IOUtil.IsDirectory(dstPath): self.__RunUnpack(packedFilePath, dstPath) else: self.LogPrint( "Unpacked directory found at '{0}', skipping unpack.".format( dstPath))
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))
def __CreateCommandGitClone( self, sourceCommand: XmlRecipePipelineFetchCommandGitClone, srcRootPath: str) -> PipelineCommand: if self.__SourcePackage is None or self.__SourceRecipe is None: raise Exception("Invalid state") readonlyCacheRootDir = self.__PathBuilder.ReadonlyCache_DownloadCacheRootPath if not readonlyCacheRootDir is None: cachePath = IOUtil.Join(readonlyCacheRootDir, self.__SourceRecipe.FullName) if IOUtil.IsDirectory(cachePath): info = PipelineInfo(self.PipelineTasks, self.__SourcePackage, self.__PathBuilder, cachePath, cachePath) return PipelineCommandNOP(self.__Log, sourceCommand, info) if self.__PathBuilder.DownloadCacheRootPath is None: raise Exception("Invalid State") dstPath = IOUtil.Join(self.__PathBuilder.DownloadCacheRootPath, self.__SourceRecipe.FullName) info = PipelineInfo(self.PipelineTasks, self.__SourcePackage, self.__PathBuilder, srcRootPath, dstPath, allowDownloads=self.__AllowDownloads) return PipelineCommandGitClone(self.__Log, sourceCommand, info)
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 __AddFiles(self, fileConfigs: List[FileConfig], sourcePath: str, projectSourcePath: str) -> None: if not IOUtil.IsDirectory(sourcePath): return files = IOUtil.GetFilesAt(sourcePath, False) newFiles = [] for file in files: if not self.__IsRegistered(fileConfigs, IOUtil.Join(sourcePath, file)): newFiles.append(file) for newFile in newFiles: self.Files.append(FileConfig(IOUtil.Join(sourcePath, newFile), IOUtil.Join(projectSourcePath, newFile)))
def __init__(self, log: Log, basedUponXML: Optional[XmlConfigFileAddRootDirectory], projectId: ProjectId, dynamicSourceRootDir: Union[ Optional[XmlConfigFileAddRootDirectory], Optional['ToolConfigRootDirectory']] = None, dynamicRootName: Optional[str] = None, dynamicPath: Optional[str] = None) -> None: super().__init__() dirMustExist = True self.ProjectId = projectId if basedUponXML is not None: self.BasedOn = basedUponXML # type: Union[XmlConfigFileAddRootDirectory, 'ToolConfigRootDirectory'] self.Name = basedUponXML.Name # type: str self.DynamicName = basedUponXML.Name # type: str dirMustExist = not basedUponXML.Create else: if dynamicSourceRootDir is None: raise Exception("dynamicSourceRootDir can not be none") if dynamicRootName is None: raise Exception("dynamicRootName can not be none") if dynamicPath is None: raise Exception("dynamicPath can not be none") self.BasedOn = dynamicSourceRootDir self.Name = dynamicRootName self.DynamicName = dynamicPath variableProcessor = VariableProcessor(log) # NOTE: workaround Union of tuples not being iterable bug in mypy https://github.com/python/mypy/issues/1575 tupleResult = variableProcessor.TryExtractLeadingEnvironmentVariableNameAndPath( self.DynamicName, dynamicSourceRootDir != None) env = tupleResult[0] remainingPath = tupleResult[1] if env is None: raise Exception( "Root dirs are expected to contain environment variables '{0}'" .format(self.DynamicName)) remainingPath = remainingPath if remainingPath is not None else "" resolvedPath = IOUtil.GetEnvironmentVariableForDirectory( env, dirMustExist) if not IOUtil.Exists(resolvedPath): IOUtil.SafeMakeDirs(resolvedPath) if not IOUtil.IsDirectory(resolvedPath): raise EnvironmentError( "The {0} environment variable content '{1}' does not point to a valid directory" .format(env, resolvedPath)) resolvedPath = resolvedPath + remainingPath self.BashName = '${0}{1}'.format(env, remainingPath) # type: str self.DosName = '%{0}%{1}'.format(env, remainingPath) # type: str self.ResolvedPath = IOUtil.ToUnixStylePath(resolvedPath) # type: str self.ResolvedPathEx = "{0}/".format(self.ResolvedPath) if len( self.ResolvedPath) > 0 else "" # type: str self.__EnvironmentVariableName = env # type: str
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 __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 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 __BuildCompilerFileDict(self, basePath: str) -> Dict[str, List[str]]: compilerDependentFilePath = IOUtil.Join(basePath, "CompilerId") if not IOUtil.IsDirectory(compilerDependentFilePath): return dict() foundDirs = IOUtil.GetDirectoriesAt(compilerDependentFilePath, False) if len(foundDirs) <= 0: return dict() result = dict() # type: Dict[str, List[str]] for dirName in foundDirs: absDirName = IOUtil.Join(compilerDependentFilePath, dirName) foundFiles = IOUtil.GetFilesAt(absDirName, True) if len(foundFiles) > 0: result[dirName] = foundFiles return result
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 __init__(self, log: Log, toolConfig: ToolConfig) -> None: super().__init__(log) if toolConfig is None: raise Exception("Missing param") sdkPath = IOUtil.GetEnvironmentVariableForDirectory(ToolEnvironmentVariableName.FSL_GRAPHICS_SDK) # type: str sdkPathAndroidProjectDir = IOUtil.GetEnvironmentVariableForAbsolutePath(ToolEnvironmentVariableName.FSL_GRAPHICS_SDK_ANDROID_PROJECT_DIR) # type: str dateNow = datetime.datetime.now() self.CurrentYearString = "{0}".format(dateNow.year) # type: str self.SDKPath = sdkPath # type: str self.SDKPathAndroidProjectDir = sdkPathAndroidProjectDir # type: str self.SDKConfigTemplatePath = toolConfig.TemplateFolder.ResolvedPath self.TemplateImportDirectories = toolConfig.TemplateImportDirectories self.ToolConfig = toolConfig # type: ToolConfig if not IOUtil.IsDirectory(self.SDKConfigTemplatePath): raise EnvironmentError("Config template path '{0}' does not point to a directory".format(self.SDKConfigTemplatePath))
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 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 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 __EarlyArgumentParser( allowStandaloneMode: bool) -> Optional[LowLevelToolConfig]: ### Parse the initial options this allows us to use the required debug and verbosity levels while ### creating the actual command line argumnets. debugEnabled = False try: parser = argparse.ArgumentParser(add_help=False) __AddDefaultOptions(parser, allowStandaloneMode) args, unknown = parser.parse_known_args() verbosityLevel = args.verbosity debugEnabled = True if args.debug else False allowDevelopmentPlugins = True if args.dev else False profilerEnabled = True if args.profile else False standaloneEnabled = False if not allowStandaloneMode else ( True if args.standalone else False) currentDir = IOUtil.NormalizePath( args.input) if args.input is not None else None if currentDir is None: currentDir = IOUtil.GetCurrentWorkingDirectory() elif not IOUtil.IsDirectory(currentDir): raise Exception( "Path '{0}' specified by --input is not a directory".format( currentDir)) elif verbosityLevel > 4: print("Using custom path from --input '{0}'".format(currentDir)) if args.version: print("V{0} Build {1}".format(CurrentVersionString, CurrentBuildString)) return LowLevelToolConfig(verbosityLevel, debugEnabled, allowDevelopmentPlugins, profilerEnabled, standaloneEnabled, currentDir) except (Exception) as ex: print("ERROR: {0}".format(str(ex))) if not debugEnabled: return None raise
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 CreateDirectory(self, path: str) -> None: if not IOUtil.IsDirectory(path): self.BasicConfig.LogPrint("Creating '{0}' as it was missing".format(path)) IOUtil.SafeMakeDirs(path)