def TryRun(log: Log, cmdList: List[str]) -> Optional[str]: """ Run the command and capture the output :return: the captured output on sucess, None if it failed """ try: if cmdList[0].endswith( '.py') and PlatformUtil.DetectBuildPlatformType( ) == BuildPlatformType.Windows: cmdList[0] = cmdList[0][:-3] + ".bat" with subprocess.Popen(cmdList, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, universal_newlines=True) as proc: output = proc.stdout.read().strip() proc.stdout.close() result = proc.wait() if result != 0: LocalUtil.DumpCapture(log, 4, output) log.LogPrintWarning( "The command '{0}' failed with '{1}'".format( " ".join(cmdList), result)) return None if isinstance(output, str): return output return None except FileNotFoundError: log.DoPrintWarning( "The command '{0}' failed with 'file not found'.".format( " ".join(cmdList))) return None
def GetDirectDependencies(self, platformName: str) -> List[XmlGenFileDependency]: directDependencies = self.GenFile.DirectDependencies if (self.Type == PackageType.ExternalLibrary and platformName == PlatformNameString.ANDROID and PlatformUtil.DetectBuildPlatformType() == BuildPlatformType.Windows and self.__TryGetExperimentaleRecipe(platformName) is not None): directDependencies += [ FakeXmlGenFileDependency(self._BasicConfig, "Recipe.BuildTool.ninja", AccessType.Public) ] if not platformName in self.Platforms: return directDependencies for basePackage in self.ProjectContext.BasePackages: if self.Name != basePackage.Name and not self.__ContainsDependency( directDependencies, basePackage.Name) and self.Type != PackageType.ToolRecipe: directDependencies += [ FakeXmlGenFileDependency(self._BasicConfig, basePackage.Name, AccessType.Public) ] return directDependencies + self.Platforms[ platformName].DirectDependencies
def GetDefaultConfigForTest( enableTestMode: bool = False, customUnitTestRoots: Optional[List[str]] = None) -> Config: strToolAppTitle = "UnitTest" log = Log(strToolAppTitle, 0) currentDir = IOUtil.GetEnvironmentVariableForDirectory( "FSL_GRAPHICS_INTERNAL") basicConfig = BasicConfig(log) localToolConfig = LowLevelToolConfig(log.Verbosity, False, False, False, False, currentDir) projectRootConfig = ToolAppMain.GetProjectRootConfig( localToolConfig, basicConfig, currentDir) buildPlatformType = PlatformUtil.DetectBuildPlatformType() toolConfig = ToolConfig(localToolConfig, buildPlatformType, Version(1, 3, 3, 7), basicConfig, projectRootConfig.ToolConfigFile, projectRootConfig) config = Config(log, toolConfig, PluginSharedValues.TYPE_UNIT_TEST, None, True) config.ForceDisableAllWrite() if enableTestMode: config.SetTestMode() if customUnitTestRoots is not None: TEST_AddPackageRoots(config, customUnitTestRoots, True) return config
def __ValidateAddTool(self, rErrorRecordList: List[ErrorRecord], installationPath: Optional[str], command: XmlRecipeValidateCommandAddTool, packageRecipeResult: PackageRecipeResult) -> bool: toolName = PlatformUtil.GetPlatformDependentExecuteableName( command.Name, PlatformUtil.DetectBuildPlatformType()) result, value = self.__DoValidateFile(rErrorRecordList, installationPath, toolName, False) if self.__Log.Verbosity >= 1: self.__Log.LogPrint("Validating AddTool '{0}': {1}".format( command.Name, result)) if self.__Log.Verbosity >= 2: self.__Log.LogPrint(" '{0}'".format(value)) if result and value is not None: foundVersion = [0] if result and value is not None and command.VersionCommand is not None: if command.VersionCommand is None or command.VersionRegEx is None: raise Exception("Internal error") foundVersion = self.__TryValidateCommandVersion( value, command.VersionCommand, command.VersionRegEx, command.MinVersion, []) result = len(foundVersion) > 0 exeRecord = PackageRecipeResultFoundExecutable( command.Name, command.Name, value, self.__ToVersion(foundVersion)) packageRecipeResult.AddFoundExecutable(exeRecord) return result
def GetVersion() -> CMakeVersion: exeName = PlatformUtil.GetPlatformDependentExecuteableName( "cmake", PlatformUtil.DetectBuildPlatformType()) path = IOUtil.TryFindExecutable(exeName) if path is None: raise Exception( "Could not locate cmake in path. Please install cmake 3.10.2+ (https://cmake.org/) as it is used to generate build files." ) cmd = [path, "--version"] version = CMakeUtil.RunCommand(cmd) versionString = "cmake version " if not version.startswith(versionString): raise Exception( "Failed to parse cmake version string '{0}'".format( versionString)) version = version[len(versionString):] indexEnd = version.find('\n') indexEnd = indexEnd if indexEnd >= 0 else len(version) version = version[0:indexEnd].strip() parsedVersion = version.split('.') if len(parsedVersion) < 3: raise Exception( "Failed to parse cmake version string: '{0}'".format(version)) while len(parsedVersion) < 3: parsedVersion.append("0") indexNonDigit = CMakeUtil._FindNonDigit(parsedVersion[2]) strBuild = parsedVersion[2][:indexNonDigit] return CMakeVersion(int(parsedVersion[0]), int(parsedVersion[1]), int(strBuild))
def GetSDKNDKId() -> str: sdkVersion = AndroidUtil.GetSDKVersion().replace('.', '_') ndkVersion = AndroidUtil.GetNDKVersion().replace('.', '_') hostType = "Win" if PlatformUtil.DetectBuildPlatformType( ) == BuildPlatformType.Windows else "Unix" return "S{0}N{1}{2}".format(sdkVersion, ndkVersion, hostType)
def __init__(self, generatorContext: GeneratorContext, buildThreads: int, useRecipe: bool = True) -> None: super().__init__(generatorContext, buildThreads, PlatformBuildTypeInfo.CMakeCustom) self.IsSingleConfiguration = True self.__CommandName = PlatformUtil.GetPlatformDependentExecuteableName( "ninja", PlatformUtil.DetectBuildPlatformType()) self.__UseRecipe = useRecipe
def __ValidateAddTool(self, rErrorRecordList: List[ErrorRecord], installationPath: Optional[str], command: XmlRecipeValidateCommandAddTool) -> bool: toolName = PlatformUtil.GetPlatformDependentExecuteableName(command.Name, PlatformUtil.DetectBuildPlatformType()) result, value = self.__DoValidateFile(rErrorRecordList, installationPath, toolName, False) if self.__BasicConfig.Verbosity >= 1: self.__BasicConfig.LogPrint("Validating AddTool '{0}': {1}".format(command.Name, result)) if self.__BasicConfig.Verbosity >= 2: self.__BasicConfig.LogPrint(" '{0}'".format(value)) return result
def __DetermineBuilder(self, generatorName: str, generatorContext: GeneratorContext, buildThreads: int) -> CMakeBuilder: if generatorName == CMakeTypes.CMakeGeneratorName.Android: if PlatformUtil.DetectBuildPlatformType() == BuildPlatformType.Windows: return CMakeBuilderNinja(generatorContext, buildThreads) return CMakeBuilderMake(generatorContext, buildThreads) if generatorContext.CMakeConfig.CMakeVersion < CMakeBuilderGeneric.MINIMUM_VERSION: if generatorName == CMakeTypes.CMakeGeneratorName.Ninja: return CMakeBuilderNinja(generatorContext, buildThreads, False) if generatorName == CMakeTypes.CMakeGeneratorName.UnixMakeFile: return CMakeBuilderMake(generatorContext, buildThreads) if generatorName == CMakeTypes.CMakeGeneratorName.VisualStudio2015_X64 or generatorName == CMakeTypes.CMakeGeneratorName.VisualStudio2017_X64 or generatorName == CMakeTypes.CMakeGeneratorName.VisualStudio2019_X64: return CMakeBuilderMSBuild(generatorContext, buildThreads) return CMakeBuilderGeneric(generatorContext, buildThreads)
def __DetermineBuilder(self, generatorName: str, generatorContext: GeneratorContext, buildThreads: int) -> CMakeBuilder: if generatorName == CMakeTypes.CMakeGeneratorName.UnixMakeFile: return CMakeBuilderMake(generatorContext, buildThreads) elif generatorName == CMakeTypes.CMakeGeneratorName.VisualStudio2015_X64 or generatorName == CMakeTypes.CMakeGeneratorName.VisualStudio2017_X64: return CMakeBuilderMSBuild(generatorContext, buildThreads) elif generatorName == CMakeTypes.CMakeGeneratorName.Android: if PlatformUtil.DetectBuildPlatformType( ) == BuildPlatformType.Windows: return CMakeBuilderNinja(generatorContext, buildThreads) else: return CMakeBuilderMake(generatorContext, buildThreads) raise Exception( "No Builder defined for the cmake generator '{0}' on platform '{1}'" .format(generatorName, generatorContext.PlatformName))
def __init__(self, log: Log, toolConfig: ToolConfig, srcType: str, variantsDict: Optional[Dict[str, str]], allowDevelopmentPlugins: bool) -> None: super().__init__(log, toolConfig) self.IsTestMode = False self.Type = srcType #self.SDKConfigPath = IOUtil.Join(sdkPath, ".Config") self.IsQuery = True if srcType == 'query' else False # type: bool self.IsSDKBuild = True if srcType == 'sdk' or self.IsQuery else False # type: bool self.TestPath = toolConfig.UnitTestPath self.DisableWrite = self.IsQuery self.DisableQueryWrite = False # type: bool self.SubPackageSupport = SubPackageSupport.Enabled #SubPackageSupport.ExecutableOnly if toolConfig.DefaultPackageLanguage != PackageLanguage.CSharp else SubPackageSupport.Enabled self.GroupException = True # type: bool # Variant extension is getting closer to working, so lets enable it self.AllowVariantExtension = True # type: bool self.GenFileName = toolConfig.GenFileName self.AllowDevelopmentPlugins = allowDevelopmentPlugins self.DisableIncludeDirCheck = False # type: bool self.DisableSourceDirCheck = False # type: bool self.IgnoreNotSupported = False # type: bool self.IsDryRun = False # type: bool self.VariantsDict = variantsDict if variantsDict else {} if self.IsQuery: self.Type = "sdk" #if not os.path.isdir(self.SDKConfigPath): # raise EnvironmentError("Config path '%s' does not point to a directory" % (self.SDKConfigPath)) buildPlatformType = PlatformUtil.DetectBuildPlatformType() if buildPlatformType == BuildPlatformType.Windows: self.__ResolvedLegacyToCurrentOSPathMethod = self.TryLegacyToDosPath self.__ResolvedLegacyToCurrentOSPathDirectConversionMethod = self.TryLegacyToDosPathDirectConversion self.__ResolvedToCurrentOSPathMethod = self.ToDosPath self.__ResolvedToCurrentOSPathDirectConversionMethod = self.ToDosPathDirectConversion else: self.__ResolvedLegacyToCurrentOSPathMethod = self.TryLegacyToBashPath self.__ResolvedLegacyToCurrentOSPathDirectConversionMethod = self.TryLegacyToBashPathDirectConversion self.__ResolvedToCurrentOSPathMethod = self.ToBashPath self.__ResolvedToCurrentOSPathDirectConversionMethod = self.ToBashPathDirectConversion
def Run(log: Log, createInfo: OpenProjectCreateInfo) -> None: log.LogPrintVerbose( 1, "Configuring and launching Visual Studio Code for path '{0}'". format(createInfo.SourcePath)) buildPlatformType = PlatformUtil.DetectBuildPlatformType() vsCodeConfigPath = IOUtil.Join(createInfo.SourcePath, ".vscode") launchFilePath = IOUtil.Join(vsCodeConfigPath, "launch.json") settingsFilePath = IOUtil.Join(vsCodeConfigPath, "settings.json") IOUtil.SafeMakeDirs(vsCodeConfigPath) log.LogPrintVerbose( 1, "- Patching settings at '{0}'".format(settingsFilePath)) log.PushIndent() try: VSCodeSettingsJsonUtil.Patch(log, settingsFilePath, createInfo.CMakeInfo) finally: log.PopIndent() exeInfo = createInfo.ExeInfo if exeInfo is not None: if log.Verbosity >= 1: log.LogPrint("- Patching launch settings at '{0}'".format( launchFilePath)) log.LogPrint(" - Exe: '{0}'".format(exeInfo.Executable)) log.LogPrint(" - Cwd: '{0}'".format( exeInfo.CurrentWorkingDirectory)) if not VSCodeLaunchJsonUtil.TryPatch( launchFilePath, buildPlatformType, exeInfo.Executable, exeInfo.CurrentWorkingDirectory): log.LogPrintVerbose( 1, "WARNING Failed to patch launch file '{0}'".format( launchFilePath)) else: log.LogPrintVerbose(1, "- Launch: No executable information found") log.PushIndent() try: OpenProjectUtil.__RunVSCode(log, buildPlatformType, createInfo.SourcePath) finally: log.PopIndent()
def GetVersion() -> CMakeVersion: exeName = PlatformUtil.GetPlatformDependentExecuteableName( "cmake", PlatformUtil.DetectBuildPlatformType()) path = IOUtil.TryFindExecutable(exeName) if path is None: raise Exception("Could not locate cmake in path") cmd = [path, "--version"] version = RunCommand(cmd) versionString = "cmake version " if not version.startswith(versionString): raise Exception( "Failed to parse cmake version string '{0}'".format( versionString)) version = version[len(versionString):] indexEnd = version.find('\n') indexEnd = indexEnd if indexEnd >= 0 else len(version) version = version[0:indexEnd] indexEndMajor = version.index('.') indexEndMinor = version.index('.', indexEndMajor + 1) versionMajor = version[0:indexEndMajor] versionMinor = version[indexEndMajor + 1:indexEndMinor] return CMakeVersion(int(versionMajor), int(versionMinor))
def __CreateFactoryCreateContext(log: Log, toolConfig: ToolConfig, generatorInfo: GeneratorInfo) -> FactoryCreateContext: ninjaRecipePackageName = UnresolvedPackageName(toolConfig.CMakeConfiguration.NinjaRecipePackageName) isWindows = PlatformUtil.DetectBuildPlatformType() == BuildPlatformType.Windows return FactoryCreateContext(log, generatorInfo, ninjaRecipePackageName, isWindows)
def __DetermineHostPlatformName(self, platformName: str) -> str: if platformName != PlatformNameString.ANDROID: return platformName if PlatformUtil.DetectBuildPlatformType() == BuildPlatformType.Windows: return PlatformNameString.WINDOWS return PlatformNameString.UBUNTU
def __Run(appFlowFactory: AToolAppFlowFactory, strToolAppTitle: str, toolCommonArgConfig: ToolCommonArgConfig, lowLevelToolConfig: LowLevelToolConfig, allowStandaloneMode: bool) -> None: log = Log(strToolAppTitle, lowLevelToolConfig.VerbosityLevel, showAppTitleIfVerbose=True) pluginConfigContext = PluginConfig.InitPluginConfigContext( log, CurrentVersion, lowLevelToolConfig.AllowDevelopmentPlugins) generatorIds = __PrepareGeneratorPlugins(pluginConfigContext, lowLevelToolConfig, toolCommonArgConfig) try: defaultPlatform = DetectBuildPlatform() except (Exception) as ex: print("ERROR: {0}".format(ex)) if lowLevelToolConfig.DebugEnabled: raise sys.exit(1) ### Do the actual command line parsing parser = __CreateParser(toolCommonArgConfig, allowStandaloneMode) if toolCommonArgConfig.AddPlatformArg: parser.add_argument('-p', '--platform', default=defaultPlatform, help='Select build platform: {0}'.format( ", ".join(generatorIds))) if toolCommonArgConfig.AllowForceClaimInstallArea: parser.add_argument( '--ForceClaimInstallArea', action='store_true', help= 'Override the security checks on the install area allowing us to use it even though its not empty. This means the existing content can be lost.' ) #parser.add_argument('--NativeGen', action='store_true', help='Force use the native build generator') toolConfig = None baseConfig = None try: basicConfig = BasicConfig(log) currentDir = lowLevelToolConfig.CurrentDir # Try to locate a project root configuration file projectRootConfig = GetProjectRootConfig(lowLevelToolConfig, basicConfig, currentDir) toolConfigFile = projectRootConfig.ToolConfigFile # Get the path to the toolconfig file if necessary and load the tool config file buildPlatformType = PlatformUtil.DetectBuildPlatformType() toolConfigPath = __GetToolConfigPath(toolConfigFile) toolConfig = ToolConfig(lowLevelToolConfig, buildPlatformType, CurrentVersion, basicConfig, toolConfigPath, projectRootConfig) baseConfig = BaseConfig(log, toolConfig) except (Exception) as ex: print("ERROR: {0}".format(ex)) if lowLevelToolConfig.DebugEnabled: raise sys.exit(1) buildTiming = None errorHelpManager = ErrorHelpManager() try: defaultVSVersion = toolConfig.GetVisualStudioDefaultVersion() #if toolCommonArgConfig.AllowVSVersion: parser.add_argument( '--VSVersion', default=str(defaultVSVersion), help= 'Choose a specific visual studio version (2015,2017), This project defaults to: {0}' .format(defaultVSVersion)) userTag = appFlowFactory.CreateUserTag(baseConfig) appFlowFactory.AddCustomArguments(parser, toolConfig, userTag) args = parser.parse_args() #if toolCommonArgConfig.AllowVSVersion: pluginConfigContext.SetVSVersion(args.VSVersion) #if toolCommonArgConfig.AddPlatformArg and args.platform.lower() != PluginSharedValues.PLATFORM_ID_ALL: #PluginConfig.SetForceUseNativeGenerator(True) #PluginConfig.SetForceUseNativeGenerator(args.NativeGen) if toolCommonArgConfig.ProcessRemainingArgs: args.RemainingArgs = __ProcessRemainingArgs(args.RemainingArgs) if toolCommonArgConfig.SupportBuildTime and args.BuildTime: buildTiming = BuildTimer() if toolCommonArgConfig.AddBuildFiltering and args.Recipes == DefaultValue.Recipes: if projectRootConfig.XmlExperimental is not None: tmpResult = projectRootConfig.XmlExperimental.TryGetRecipesDefaultValue( defaultPlatform) if tmpResult is not None: args.Recipes = "[{0}]".format(tmpResult) toolAppConfig = __CreateToolAppConfig(args, defaultPlatform, toolCommonArgConfig, defaultVSVersion) toolAppContext = ToolAppContext(log, errorHelpManager, lowLevelToolConfig, toolAppConfig, pluginConfigContext) toolAppFlow = appFlowFactory.Create(toolAppContext) toolAppFlow.ProcessFromCommandLine(args, currentDir, toolConfig, userTag) if buildTiming: PrintBuildTiming(buildTiming) except GroupedException as ex: __OnErrorInfo(buildTiming, errorHelpManager) for entry in ex.ExceptionList: print("ERROR: {0}".format(entry)) if lowLevelToolConfig.DebugEnabled: raise for entry in ex.ExceptionList: if isinstance(entry, ExitException): sys.exit(entry.ExitCode) sys.exit(1) except AggregateException as ex: __OnErrorInfo(buildTiming, errorHelpManager) for entry in ex.ExceptionList: print("ERROR: {0}".format(entry)) if lowLevelToolConfig.DebugEnabled: if len(ex.ExceptionList) > 0: raise ex.ExceptionList[0] raise for entry in ex.ExceptionList: if isinstance(entry, ExitException): sys.exit(entry.ExitCode) sys.exit(1) except ExitException as ex: __OnErrorInfo(buildTiming, errorHelpManager) sys.exit(ex.ExitCode) except Exception as ex: __OnErrorInfo(buildTiming, errorHelpManager) print("ERROR: {0}".format(ex)) if lowLevelToolConfig.DebugEnabled: raise sys.exit(1)
def DetermineFinalCMakeGenerator(generatorName: str) -> str: if generatorName != CMakeGeneratorName.Android: return generatorName if PlatformUtil.DetectBuildPlatformType() == BuildPlatformType.Windows: return CMakeGeneratorName.Ninja return CMakeGeneratorName.UnixMakeFile
def __init__(self, generatorContext: GeneratorContext, buildThreads: int) -> None: super().__init__(generatorContext, buildThreads) self.IsSingleConfiguration = True self.__CommandName = PlatformUtil.GetPlatformDependentExecuteableName( "ninja", PlatformUtil.DetectBuildPlatformType())
def __init__(self, log: Log) -> None: super().__init__() self.BuildPlatform = PlatformUtil.DetectBuildPlatformType() self.VulkanShaderCompiler = self.GetPlatformDependentExecuteableName( "glslangValidator")
def __ValidateFindExecutableFileInPath( self, rErrorRecordList: List[ErrorRecord], installationPath: Optional[str], command: XmlRecipeValidateCommandFindExecutableFileInPath, packageRecipeResult: PackageRecipeResult) -> bool: # Patch filename with the platform dependent name alternatives = [command.Name] if len(command.Alternatives) > 0: alternatives += command.Alternatives retry = True currentCommandName = "" newErrors = [] # type: List[ErrorRecord] while retry and len(alternatives) > 0: currentCommandName = alternatives[0] retry = False platformFilename = PlatformUtil.GetPlatformDependentExecuteableName( currentCommandName, PlatformUtil.DetectBuildPlatformType()) result, value = self.__TryFindFileInPath(newErrors, installationPath, platformFilename, command.ExpectedPath) if result and value is not None and command.MinVersion is not None: if command.VersionCommand is None or command.VersionRegEx is None or command.MinVersion is None: raise Exception("Internal error") result = self.__TryValidateCommandVersion( value, command.VersionCommand, command.VersionRegEx, command.MinVersion) # Cache information about what we discovered if result and value is not None: exeRecord = PackageRecipeResultFoundExecutable( command.Name, currentCommandName, value) packageRecipeResult.AddFoundExecutable(exeRecord) elif len(alternatives) > 0: alternatives = alternatives[1:] retry = True if self.__BasicConfig.Verbosity >= 1: # On failure we show the 'most' common name if result or (len(command.Alternatives) < 0): if command.ExpectedPath is None: self.__BasicConfig.LogPrint( "Validating executable file '{0}' is in path: {1}". format(currentCommandName, result)) else: self.__BasicConfig.LogPrint( "Validating executable file '{0}' is in path at '{1}': {2}" .format(currentCommandName, command.ExpectedPath, result)) else: allAlternatives = [command.Name] if command.Alternatives is not None: allAlternatives += command.Alternatives if command.ExpectedPath is None: self.__BasicConfig.LogPrint( "Validating one of these executable files '{0}' is in path: {1}" .format(", ".join(allAlternatives), result)) else: self.__BasicConfig.LogPrint( "Validating one of these executable files '{0}' is in path at '{1}': {2}" .format(", ".join(allAlternatives), command.ExpectedPath, result)) if not value is None and self.__BasicConfig.Verbosity >= 2: self.__BasicConfig.LogPrint(" '{0}'".format(value)) if not result: rErrorRecordList += newErrors return result