def __RunPackage(self, buildContext: LocalBuildContext, package: Package, buildEnv: Dict[str, str], runCommands: Optional[List[str]]) -> None: if runCommands is None: return if package.AbsolutePath is None: raise Exception("Invalid package") try: # TODO: Allow the working directory for the run command to be changed too. For now use the original choice of absolute path for the package currentWorkingDirectory = package.AbsolutePath if self.Log.Verbosity >= 1: self.Log.LogPrint("Running run command '{0}' in '{1}'".format( self.__SafeJoinCommandArguments(runCommands), currentWorkingDirectory)) result = subprocess.call(runCommands, cwd=currentWorkingDirectory, env=buildEnv) if result != 0: self.Log.LogPrintWarning( "The run command '{0}' failed with '{1}'. It was run with CWD: '{2}'" .format(self.__SafeJoinCommandArguments(runCommands), result, currentWorkingDirectory)) raise ExitException(result) except FileNotFoundError: self.Log.LogPrintWarning( "The run command '{0}' failed with 'file not found'. It was run with CWD: '{1}'" .format(self.__SafeJoinCommandArguments(runCommands), currentWorkingDirectory)) raise
def _RunClangFormat(log: Log, toolConfig: ToolConfig, clangFormatConfiguration: ClangFormatConfiguration, clangExeInfo: ClangExeInfo, package: Package, filteredFiles: Optional[List[str]], repairEnabled: bool) -> None: if package.ResolvedBuildAllIncludeFiles is None or len( package.ResolvedBuildAllIncludeFiles ) <= 0 or not package.AllowCheck or package.IsVirtual: return if package.AbsolutePath is None or package.ResolvedBuildSourceFiles is None: raise Exception("Invalid package") formatPackageConfig = FormatPackageConfig(log, package, clangFormatConfiguration, filteredFiles) cmd = clangExeInfo.Command buildCommand = [cmd, '-style=file'] if repairEnabled: buildCommand.append('-i') if len(clangFormatConfiguration.AdditionalUserArguments) > 0: log.LogPrint("Adding user supplied arguments before '--' {0}".format( clangFormatConfiguration.AdditionalUserArguments)) buildCommand += clangFormatConfiguration.AdditionalUserArguments buildCommand += [ entry.ResolvedPath for entry in formatPackageConfig.AllFiles ] currentWorkingDirectory = package.AbsolutePath FileFinder.FindClosestFileInRoot(log, toolConfig, currentWorkingDirectory, clangFormatConfiguration.CustomFormatFile) try: # if verbose enabled we log the clang-format version if log.Verbosity >= 4: log.LogPrint("Running command '{0}' in cwd: {1}".format( buildCommand, currentWorkingDirectory)) result = subprocess.call(buildCommand, cwd=currentWorkingDirectory) if result != 0: log.LogPrintWarning( "The command '{0}' failed with '{1}'. It was run with CWD: '{2}'" .format(" ".join(buildCommand), result, currentWorkingDirectory)) raise ExitException(result) except FileNotFoundError: log.DoPrintWarning( "The command '{0}' failed with 'file not found'. It was run with CWD: '{1}'" .format(" ".join(buildCommand), currentWorkingDirectory)) raise
def __RunPackage(self, package: AppInfoPackage, userArgs: List[str], buildVariantsDict: Dict[str, str]) -> None: if package.GeneratorReport is None or package.GeneratorReport.ExecutableReport is None or package.GeneratorReport.VariableReport is None: raise Exception( "Could not run {0}, as we dont have the required information". format(package.Name)) self.Log.LogPrint("Running {0}".format(package.Name)) executableReport = package.GeneratorReport.ExecutableReport variableReport = package.GeneratorReport.VariableReport runCommandList = [] packagePath = package.AbsolutePath exePath = ReportVariableFormatter.Format( executableReport.ExeFormatString, variableReport, buildVariantsDict, executableReport.EnvironmentVariableResolveMethod) if not executableReport.UseAsRelative: exePath = IOUtil.Join(packagePath, exePath) runCommandList.append(exePath) if executableReport.RunScript is not None: runScript = executableReport.RunScript if not executableReport.UseAsRelative: runScript = IOUtil.Join(packagePath, runScript) runCommandList.insert(0, runScript) currentWorkingDirectory = package.AbsolutePath runCommandList = runCommandList + userArgs try: result = subprocess.call(runCommandList, cwd=currentWorkingDirectory) if result != 0: self.Log.LogPrintWarning( "The run command '{0}' failed with '{1}'. It was run with CWD: '{2}'" .format(" ".join(runCommandList), result, currentWorkingDirectory)) raise ExitException(result) except FileNotFoundError: self.Log.LogPrintWarning( "The run command '{0}' failed with 'file not found'. It was run with CWD: '{1}'" .format(" ".join(runCommandList), currentWorkingDirectory)) raise
def __RunVSCode(log: Log, buildPlatformType: BuildPlatformType, sourcePath: str) -> None: try: if log.Verbosity >= 1: log.LogPrint( "Opening visual studio code in '{0}'".format(sourcePath)) codeCmd = OpenProjectUtil.__GetCodeCmd(buildPlatformType) vsCodeCommand = [codeCmd, '.'] result = subprocess.call(vsCodeCommand, cwd=sourcePath) if result != 0: log.LogPrintWarning( "The open vscode command '{0}' failed with '{1}'. It was run with CWD: '{2}'" .format( OpenProjectUtil.__SafeJoinCommandArguments( vsCodeCommand), result, sourcePath)) raise ExitException(result) except FileNotFoundError: log.DoPrintWarning( "The open vscode command '{0}' failed with 'file not found'. It was run with CWD: '{1}'" .format( OpenProjectUtil.__SafeJoinCommandArguments(vsCodeCommand), sourcePath)) raise
def RunNinja(log: Log, ninjaExeInfo: ClangExeInfo, ninjaFile: str, currentWorkingDirectory: str, numBuildThreads: int, logOutput: bool) -> None: buildCommand = [ninjaExeInfo.Command, "-f", ninjaFile] #buildCommand += ["-d", "explain"] if numBuildThreads > 0: buildCommand += ["-j", str(numBuildThreads)] try: if log.Verbosity >= 4: log.LogPrint("Running command '{0}' in cwd: {1}".format( buildCommand, currentWorkingDirectory)) result = RunHelper.RunNow(log, buildCommand, currentWorkingDirectory, logOutput) if result != 0: log.LogPrintWarning( "The command '{0}' failed with '{1}'. It was run with CWD: '{2}'" .format(" ".join(buildCommand), result, currentWorkingDirectory)) raise ExitException(result) except FileNotFoundError: log.DoPrintWarning( "The command '{0}' failed with 'file not found'. It was run with CWD: '{1}'" .format(" ".join(buildCommand), currentWorkingDirectory)) raise
def _RunClangTidy( log: Log, toolConfig: ToolConfig, platformId: str, performClangTidyConfig: PerformClangTidyConfig, clangExeInfo: ClangExeInfo, package: Package, filteredFiles: Optional[List[str]], clangFormatFilename: Optional[str], localVariantInfo: LocalVariantInfo, virtualVariantEnvironmentCache: VirtualVariantEnvironmentCache, logOutput: bool = False) -> None: if package.ResolvedBuildAllIncludeFiles is None: raise Exception("invalid package") log.LogPrint("- {0}".format(package.Name)) clangTidyConfiguration = performClangTidyConfig.ClangTidyConfiguration if package.AbsolutePath is None or package.ResolvedBuildSourceFiles is None: raise Exception("Invalid package") allFiles = [] # type: List[str] 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, clangTidyConfiguration.FileExtensions): allFiles.append(fileName) for fileName in package.ResolvedBuildSourceFiles: fullPath = IOUtil.Join(package.AbsolutePath, fileName) if PerformClangUtil.IsValidExtension( fileName, clangTidyConfiguration.FileExtensions): allFiles.append(fileName) else: for fileName in filteredFiles: if PerformClangUtil.IsValidExtension( fileName, clangTidyConfiguration.FileExtensions): allFiles.append(fileName) # ensure we process the files in the same order every time allFiles.sort() platformCompilerFlags = [] # type: List[str] platformDefineCommands = [] # type: List[str] platformStrictChecks = [] # type: List[str] if platformId in clangTidyConfiguration.PlatformDict: clangPlatformConfig = clangTidyConfiguration.PlatformDict[platformId] platformCompilerFlags = clangPlatformConfig.Compiler.Flags for platformDefine in clangPlatformConfig.Defines.All: platformDefineCommands.append('-D') platformDefineCommands.append(platformDefine) # We default to release for now for platformDefine in clangPlatformConfig.Defines.Release: platformDefineCommands.append('-D') platformDefineCommands.append(platformDefine) for strictCheck in clangPlatformConfig.StrictChecks: platformStrictChecks.append(strictCheck) includePaths = __BuildClangTidyPackageIncludePaths( log, localVariantInfo, virtualVariantEnvironmentCache, package) packageDefineCommands = __BuildClangTidyPackageDefines( log, localVariantInfo, package) cmd = clangExeInfo.ClangCommand buildCommand = [cmd] if performClangTidyConfig.Repair: buildCommand.append('-fix') #buildCommand.append('-fix-errors') #buildCommand.append('-header-filter=.*') usingCheckCommand = False if len(performClangTidyConfig.OverrideChecks) > 0: newOverrideChecks = ",".join(performClangTidyConfig.OverrideChecks) log.LogPrintVerbose( 2, "Overriding checks checks '{0}'".format(newOverrideChecks)) if performClangTidyConfig.StrictChecks: log.DoPrintWarning( "Ignoreing strict checks because 'override' is enabled") buildCommand.append("--checks") buildCommand.append(newOverrideChecks) usingCheckCommand = True elif performClangTidyConfig.StrictChecks and len(platformStrictChecks) > 0: newStrictChecks = ",".join(platformStrictChecks) log.LogPrintVerbose( 2, "Adding strict checks '{0}'".format(newStrictChecks)) buildCommand.append("--checks") buildCommand.append(newStrictChecks) usingCheckCommand = True if len(performClangTidyConfig.AdditionalUserArguments) > 0: log.LogPrintVerbose( 2, "Adding user supplied arguments before '--' {0}".format( performClangTidyConfig.AdditionalUserArguments)) if usingCheckCommand and '--checks' in performClangTidyConfig.AdditionalUserArguments: log.DoPrintWarning( "another command is adding '--checks' so it could conflict with the user supplied argument" ) buildCommand += performClangTidyConfig.AdditionalUserArguments buildCommand += allFiles buildCommand.append('--') if len(platformCompilerFlags) > 0: buildCommand += __LookupEnvironmentVariables( platformCompilerFlags, virtualVariantEnvironmentCache) if len(platformDefineCommands) > 0: buildCommand += platformDefineCommands if len(includePaths) > 0: buildCommand += includePaths if len(packageDefineCommands) > 0: buildCommand += packageDefineCommands if len(performClangTidyConfig.PostfixArguments) > 0: log.LogPrintVerbose( 2, "Adding user supplied arguments after '--' {0}".format( performClangTidyConfig.PostfixArguments)) buildCommand += performClangTidyConfig.PostfixArguments currentWorkingDirectory = package.AbsolutePath if clangFormatFilename is not None: FileFinder.FindClosestFileInRoot(log, toolConfig, currentWorkingDirectory, clangFormatFilename) FileFinder.FindClosestFileInRoot(log, toolConfig, currentWorkingDirectory, clangTidyConfiguration.CustomTidyFile) try: if log.Verbosity >= 4: log.LogPrint("Running command '{0}' in cwd: {1}".format( buildCommand, currentWorkingDirectory)) result = __RunNow(log, buildCommand, currentWorkingDirectory, logOutput) if result != 0: log.LogPrintWarning( "The command '{0}' failed with '{1}'. It was run with CWD: '{2}'" .format(" ".join(buildCommand), result, currentWorkingDirectory)) raise ExitException(result) except FileNotFoundError: log.DoPrintWarning( "The command '{0}' failed with 'file not found'. It was run with CWD: '{1}'" .format(" ".join(buildCommand), currentWorkingDirectory)) raise
def __Build(self, buildContext: LocalBuildContext, buildConfig: BuildConfigRecord, buildEnv: Dict[str, str], buildReport: GeneratorBuildReport, variableReport: GeneratorVariableReport, currentWorkingDirectory: Optional[str], strHelpContext: str) -> None: buildCommandReport = buildReport.BuildCommandReport if buildCommandReport is None: if self.Log.Verbosity >= 5: self.Log.LogPrint( "Skipping {0} as its build command was None".format( strHelpContext)) return if buildCommandReport.CurrentWorkingDirectoryFormatString is not None: currentWorkingDirectory = ReportVariableFormatter.Format( buildCommandReport.CurrentWorkingDirectoryFormatString, variableReport, buildConfig.VariantSettingsDict) if currentWorkingDirectory is None: raise Exception("No current working directory supplied") buildCommandStr = ReportVariableFormatter.Format( buildCommandReport.CommandFormatString, variableReport, buildConfig.VariantSettingsDict) if not buildCommandReport.UseAsRelative: buildCommandStr = IOUtil.Join(currentWorkingDirectory, buildCommandStr) buildArgumentList = [] for buildArgument in buildCommandReport.Arguments: buildArgument = ReportVariableFormatter.Format( buildArgument, variableReport, buildConfig.VariantSettingsDict) buildArgumentList.append(buildArgument) nativeBuildArgumentList = [] for buildArgument in buildCommandReport.NativeArguments: buildArgument = ReportVariableFormatter.Format( buildArgument, variableReport, buildConfig.VariantSettingsDict) nativeBuildArgumentList.append(buildArgument) self.__AppendToRightArgumentList( buildArgumentList, nativeBuildArgumentList, buildCommandReport.NativeArgumentSeparator, buildConfig.BuildArgs) self.__AppendToRightArgumentList( buildArgumentList, nativeBuildArgumentList, buildCommandReport.NativeArgumentSeparator, buildContext.Platform.AdditionalBuildArguments) buildCommand = [buildCommandStr] + buildArgumentList if buildCommandReport.NativeArgumentSeparator is not None and len( nativeBuildArgumentList) > 0: buildCommand.append(buildCommandReport.NativeArgumentSeparator) buildCommand += nativeBuildArgumentList try: if self.Log.Verbosity >= 1: self.Log.LogPrint( "Running build command '{0}' in '{1}'".format( self.__SafeJoinCommandArguments(buildCommand), currentWorkingDirectory)) result = subprocess.call(buildCommand, cwd=currentWorkingDirectory, env=buildEnv) if result != 0: self.Log.LogPrintWarning( "The build command '{0}' failed with '{1}'. It was run with CWD: '{2}'" .format(self.__SafeJoinCommandArguments(buildCommand), result, currentWorkingDirectory)) raise ExitException(result) except FileNotFoundError: self.Log.DoPrintWarning( "The build command '{0}' failed with 'file not found'. It was run with CWD: '{1}'" .format(self.__SafeJoinCommandArguments(buildCommand), currentWorkingDirectory)) raise
def __ConfigureBuild(self, report: PackageGeneratorConfigReport, buildConfig: BuildConfigRecord, allowFindPackage: bool) -> None: configReport = report.ConfigReport.ConfigCommandReport variableReport = report.VariableReport buildArgumentList = [] for buildArgument in configReport.Arguments: buildArgument = ReportVariableFormatter.Format( buildArgument, variableReport, buildConfig.VariantSettingsDict) buildArgumentList.append(buildArgument) configCommandStr = ReportVariableFormatter.Format( configReport.CommandFormatString, variableReport, buildConfig.VariantSettingsDict) currentWorkingDirectory = ReportVariableFormatter.Format( configReport.CurrentWorkingDirectoryFormatString, variableReport, buildConfig.VariantSettingsDict) configCommand = [configCommandStr ] + buildArgumentList # + buildConfig.BuildConfigArgs #if len(buildContext.Platform.AdditionalBuildConfigArguments) > 0: # buildCommand += buildContext.Platform.AdditionalBuildConfigArguments try: IOUtil.SafeMakeDirs(currentWorkingDirectory) cacheFilename = IOUtil.Join(currentWorkingDirectory, '.FslConfigureCache.json') dirtyBuildConfigureCache = self.__CheckBuildConfigureModifications( cacheFilename, report.GeneratedFileSet, configCommand, buildConfig.PlatformName, buildConfig.ToolVersion.ToMajorMinorPacthString(), allowFindPackage) if dirtyBuildConfigureCache is None: self.Log.LogPrint( "Build configuration not modified, skipping configure") return self.Log.LogPrint("Build configuration modifed, running configure") if self.Log.Verbosity >= 1: self.Log.LogPrint( "Running build config command '{0}' in '{1}'".format( self.__SafeJoinCommandArguments(configCommand), currentWorkingDirectory)) result = subprocess.call(configCommand, cwd=currentWorkingDirectory) if result != 0: self.Log.LogPrintWarning( "The build config command '{0}' failed with '{1}'. It was run with CWD: '{2}'" .format(self.__SafeJoinCommandArguments(configCommand), result, currentWorkingDirectory)) raise ExitException(result) else: BuildConfigureCache.Save(self.Log, cacheFilename, dirtyBuildConfigureCache) except FileNotFoundError: self.Log.DoPrintWarning( "The build config command '{0}' failed with 'file not found'. It was run with CWD: '{1}'" .format(self.__SafeJoinCommandArguments(configCommand), currentWorkingDirectory)) raise