def Process(self, currentDirPath: str, toolConfig: ToolConfig, localToolConfig: LocalToolConfig) -> None:
        # Check if a environment variable has been set to disable this tool
        # This is for example done by FslBuild to prevent multiple executions of content building.
        toolEnabled = IOUtil.TryGetEnvironmentVariable(CONFIG_FSLBUILDCONTENT_ENABLED)

        featureList = localToolConfig.BuildPackageFilters.FeatureNameList

        config = Config(self.Log, toolConfig, localToolConfig.PackageConfigurationType,
                        localToolConfig.BuildVariantsDict, localToolConfig.AllowDevelopmentPlugins)

        # Get the platform 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)
        generatorContext = GeneratorContext(config, self.ErrorHelpManager, localToolConfig.BuildPackageFilters.RecipeFilterManager, config.ToolConfig.Experimental, generator)

        config.LogPrint("Active platform: {0}".format(generator.PlatformName))

        discoverFeatureList = '*' in featureList
        topLevelPackage = None
        if discoverFeatureList or localToolConfig.Project is None:
            if discoverFeatureList:
                config.LogPrint("No features specified, so using package to determine them")
            topLevelPackage = self.__ResolveAndGetTopLevelPackage(generatorContext, config, currentDirPath, toolConfig.GetMinimalConfig(),
                                                                  localToolConfig.Recursive)
            if discoverFeatureList:
                featureList = [entry.Name for entry in topLevelPackage.ResolvedAllUsedFeatures]
            #if localToolConfig.Project is None:
            #    executeablePackage = PackageListUtil.FindFirstExecutablePackage(packages)
            #    localToolConfig.Project = executeablePackage.ShortName

        if localToolConfig.Validate:
            Validate.ValidatePlatform(config, localToolConfig.PlatformName, featureList)
            if topLevelPackage is None:
                topLevelPackage = self.__ResolveAndGetTopLevelPackage(generatorContext, config, currentDirPath, toolConfig.GetMinimalConfig(),
                                                                      localToolConfig.Recursive)
            RecipeBuilder.ValidateInstallationForPackages(config, generatorContext, topLevelPackage.ResolvedBuildOrder)

        if toolEnabled is not None and not ParseUtil.ParseBool(toolEnabled):
            if self.Log.Verbosity > 0:
                print("FslBuildContent has been disabled by environment variable {0} set to {1}".format(CONFIG_FSLBUILDCONTENT_ENABLED, toolEnabled))
            return

        locations = toolConfig.PackageConfiguration[localToolConfig.PackageConfigurationType].Locations
        if not localToolConfig.Recursive or topLevelPackage is None:
            location = self.__TryFindLocation(locations, currentDirPath)
            if location is None:
                raise Exception("Could not locate location for {0}".format(currentDirPath))
            packagePath = PackagePath(currentDirPath, location)
            ContentBuilder.Build(config, packagePath, featureList, localToolConfig.Output)
        else:
            # Location not found, but its ok since '-r' was specified and we have a top level package
            for foundPackage in topLevelPackage.ResolvedBuildOrder:
                if foundPackage.Type == PackageType.Executable:
                    foundFeatureList = [entry.Name for entry in foundPackage.ResolvedAllUsedFeatures]
                    if foundPackage.Path is None:
                        raise Exception("Invalid package")
                    ContentBuilder.Build(config, foundPackage.Path, foundFeatureList)
 def __DoBuildRecipes(self, config: Config,
                      generatorContext: GeneratorContext,
                      packages: List[Package], forceClaimInstallArea: bool,
                      buildThreads: int) -> None:
     builderConfig = BuilderConfig()
     builderConfig.Settings.ForceClaimInstallArea = forceClaimInstallArea
     builderConfig.Settings.BuildThreads = buildThreads
     RecipeBuilder.BuildPackages(config, generatorContext, builderConfig,
                                 packages)
Exemple #3
0
def ForceCheckBuildTools(configToolCheck: Config, generatorContext: GeneratorContext, toolPackageNames: List[str]) -> PackageRecipeResultManager:
    configToolCheck.LogPrint("BuildTools check");
    plugin = generatorContext.Platform
    filePathList = [] # type: List[str]
    packageFilters = PackageFilters()
    packages = MainFlow.DoGetPackages(generatorContext, configToolCheck, filePathList, packageFilters, forceImportPackageNames=toolPackageNames)

    packageRecipeResultManager = PackageRecipeResultManager(configToolCheck);
    builderConfig = BuilderConfig()
    builderConfig.Settings.CheckBuildCommands = True
    RecipeBuilder.BuildPackages(configToolCheck, generatorContext, builderConfig, packages, packageRecipeResultManager)
    return packageRecipeResultManager
Exemple #4
0
    def Process(self, currentDirPath: str, toolConfig: ToolConfig,
                localToolConfig: LocalToolConfig) -> None:
        config = Config(self.Log, toolConfig,
                        localToolConfig.PackageConfigurationType,
                        localToolConfig.BuildVariantsDict,
                        localToolConfig.AllowDevelopmentPlugins)

        packageFilters = localToolConfig.BuildPackageFilters

        buildVariantConfig = BuildVariantConfigUtil.GetBuildVariantConfig(
            localToolConfig.BuildVariantsDict)
        platform = self.ToolAppContext.PluginConfigContext.GetGeneratorPluginById(
            localToolConfig.PlatformName, localToolConfig.Generator,
            buildVariantConfig, config.ToolConfig.DefaultPackageLanguage,
            config.ToolConfig.CMakeConfiguration,
            localToolConfig.GetUserCMakeConfig(), False)
        theFiles = []  # type: List[str]
        if not localToolConfig.VoidBuild:
            theFiles = MainFlow.DoGetFiles(
                config, toolConfig.GetMinimalConfig(platform.CMakeConfig),
                currentDirPath, localToolConfig.Recursive)
        else:
            self.Log.LogPrintVerbose(1, "Doing a void build")
        generatorContext = GeneratorContext(config, self.ErrorHelpManager,
                                            packageFilters.RecipeFilterManager,
                                            config.ToolConfig.Experimental,
                                            platform)
        packages = MainFlow.DoGetPackages(generatorContext, config, theFiles,
                                          packageFilters)
        #packages = DoExperimentalGetRecipes(generatorContext, config, [])
        #topLevelPackage = PackageListUtil.GetTopLevelPackage(packages)

        builderConfig = BuilderConfig()
        builderConfig.Settings.PreDeleteBuild = localToolConfig.PreDeleteBuild
        builderConfig.Settings.PostDeleteBuild = localToolConfig.PostDeleteBuild
        builderConfig.Settings.CheckBuildCommands = localToolConfig.CheckBuildCommands
        builderConfig.Settings.ForceClaimInstallArea = localToolConfig.ForceClaimInstallArea
        builderConfig.Settings.BuildThreads = localToolConfig.BuildThreads

        RecipeBuilder.BuildPackages(self.Log, config.SDKPath, config.IsDryRun,
                                    config.ToolConfig, generatorContext,
                                    builderConfig, packages)
    def Process(self, currentDirPath: str, toolConfig: ToolConfig,
                localToolConfig: LocalToolConfig) -> None:
        config = Config(self.Log, toolConfig,
                        localToolConfig.PackageConfigurationType,
                        localToolConfig.BuildVariantsDict,
                        localToolConfig.AllowDevelopmentPlugins)

        # create a config we control and that can be used to just build the tool recipe's
        configToolCheck = Config(self.Log, toolConfig,
                                 PluginSharedValues.TYPE_DEFAULT,
                                 localToolConfig.BuildVariantsDict,
                                 localToolConfig.AllowDevelopmentPlugins)
        if localToolConfig.DryRun:
            config.ForceDisableAllWrite()
            configToolCheck.ForceDisableAllWrite()

        self.__CheckUserArgs(localToolConfig.ClangFormatArgs, "formatArgs")
        self.__CheckUserArgs(localToolConfig.ClangTidyArgs, "tidyArgs")
        self.__CheckUserArgs(localToolConfig.ClangTidyPostfixArgs,
                             "tidyPostfixArgs")

        applyClangFormat = toolConfig.ClangFormatConfiguration is not None and localToolConfig.ClangFormat
        applyClangTidy = toolConfig.ClangTidyConfiguration is not None and localToolConfig.ClangTidy

        if localToolConfig.IgnoreNotSupported or (
            (localToolConfig.ScanSource or applyClangFormat)
                and not applyClangTidy):
            config.IgnoreNotSupported = True
            configToolCheck.IgnoreNotSupported = True

        packageFilters = localToolConfig.BuildPackageFilters

        # Get the platform and see if its supported
        platform = PluginConfig.GetGeneratorPluginById(
            localToolConfig.PlatformName, False)
        PlatformUtil.CheckBuildPlatform(platform.Name)
        generatorContext = GeneratorContext(config,
                                            config.ToolConfig.Experimental,
                                            platform)

        config.LogPrint("Active platform: {0}".format(platform.Name))

        packageRecipeResultManager = None  # type: Optional[PackageRecipeResultManager]
        toolPackageNames = []
        if applyClangFormat or applyClangTidy:
            if applyClangFormat:
                if toolConfig.ClangFormatConfiguration is None:
                    raise Exception("internal error")
                toolPackageNames.append(
                    toolConfig.ClangFormatConfiguration.RecipePackageName)
            if applyClangTidy:
                if toolConfig.ClangTidyConfiguration is None:
                    raise Exception("internal error")
                toolPackageNames.append(
                    toolConfig.ClangTidyConfiguration.RecipePackageName)
            packageRecipeResultManager = ForceCheckBuildTools(
                configToolCheck, generatorContext, toolPackageNames)

        searchDir = currentDirPath
        if localToolConfig.File is not None and IOUtil.IsAbsolutePath(
                localToolConfig.File):
            searchDir = IOUtil.GetDirectoryName(localToolConfig.File)
        closestGenFilePath = FileFinder.TryFindClosestFileInRoot(
            config, toolConfig, searchDir, config.GenFileName)
        if closestGenFilePath is None:
            closestGenFilePath = searchDir

        if (self.Log.Verbosity >= 4):
            self.Log.LogPrint("Closest '{0}' file path: '{1}'".format(
                toolConfig.GenFileName, closestGenFilePath))

        packageProcess = None  # type: Optional[MainFlow.PackageLoadAndResolveProcess]
        packages = None
        discoverFeatureList = '*' in packageFilters.FeatureNameList
        if discoverFeatureList or localToolConfig.Project is None or localToolConfig.ScanSource or applyClangFormat or applyClangTidy:
            if discoverFeatureList:
                config.LogPrint(
                    "No features specified, so using package to determine them"
                )
            if localToolConfig.ScanSource or applyClangFormat or applyClangTidy or discoverFeatureList:
                packageProcess = self.__CreatePackageProcess(
                    config, toolConfig.GetMinimalConfig(), closestGenFilePath,
                    localToolConfig.Recursive, generatorContext.Platform,
                    toolPackageNames)
                packageProcess.Resolve(generatorContext, packageFilters,
                                       applyClangTidy, False)
                packages = packageProcess.Packages
                topLevelPackage = PackageListUtil.GetTopLevelPackage(packages)
                if discoverFeatureList:
                    packageFilters.FeatureNameList = [
                        entry.Name
                        for entry in topLevelPackage.ResolvedAllUsedFeatures
                    ]

        customPackageFileFilter = None  # type: Optional[CustomPackageFileFilter]
        if not localToolConfig.ScanSource and not applyClangFormat and not applyClangTidy:
            Validate.ValidatePlatform(config, localToolConfig.PlatformName,
                                      packageFilters.FeatureNameList)
            if packageProcess is None:
                packageProcess = self.__CreatePackageProcess(
                    config, toolConfig.GetMinimalConfig(), closestGenFilePath,
                    localToolConfig.Recursive, generatorContext.Platform,
                    toolPackageNames)
            if not packageProcess.IsFullResolve or packages is None:
                # For now this requires a full resolve (but basically it only requires basic + files)
                packages = packageProcess.Resolve(generatorContext,
                                                  packageFilters,
                                                  applyClangTidy, True)

            topLevelPackage = PackageListUtil.GetTopLevelPackage(packages)
            RecipeBuilder.ValidateInstallationForPackages(
                config, generatorContext, topLevelPackage.ResolvedBuildOrder)
        else:
            if localToolConfig.File is not None:
                # Delay extension validation
                customPackageFileFilter = CustomPackageFileFilter(
                    localToolConfig.File)

        theTopLevelPackage = None  # type: Optional[Package]
        filteredPackageList = []  # type: List[Package]
        if applyClangTidy or applyClangFormat or localToolConfig.ScanSource:
            addExternals = applyClangTidy
            filteredPackageList, theTopLevelPackage = self.__PreparePackages(
                self.Log, localToolConfig, packageProcess, generatorContext,
                packageFilters, addExternals, packages, config.IsSDKBuild,
                applyClangTidy, config)
            if len(filteredPackageList) <= 0:
                self.Log.DoPrint("No supported packages left to process")
                return

        if applyClangTidy:
            self.__ApplyClangTidy(self.Log, toolConfig, localToolConfig,
                                  packageRecipeResultManager,
                                  theTopLevelPackage, filteredPackageList,
                                  platform, config, generatorContext,
                                  customPackageFileFilter)

        if applyClangFormat:
            self.__ApplyClangFormat(self.Log, toolConfig, localToolConfig,
                                    packageRecipeResultManager,
                                    filteredPackageList,
                                    customPackageFileFilter)

        # Scan source after 'format' to ensure we dont warn about stuff that has been fixed
        if localToolConfig.ScanSource:
            self.__ApplyScanSource(self.Log, localToolConfig,
                                   config.IsSDKBuild, config.DisableWrite,
                                   filteredPackageList,
                                   customPackageFileFilter)
def ForceBuildExternals(config: Config, generatorContext: GeneratorContext,
                        packages: List[Package]) -> None:
    builderConfig = BuilderConfig()
    RecipeBuilder.BuildPackages(config, generatorContext, builderConfig,
                                packages)
    def Process(self, currentDirPath: str, toolConfig: ToolConfig,
                localToolConfig: LocalToolConfig) -> None:
        # Check if a environment variable has been set to disable this tool
        # This is for example done by FslBuild to prevent multiple executions of content building.
        toolEnabled = IOUtil.TryGetEnvironmentVariable(
            CONFIG_FSLBUILDCONTENT_ENABLED)

        featureList = localToolConfig.BuildPackageFilters.FeatureNameList

        config = Config(self.Log, toolConfig,
                        localToolConfig.PackageConfigurationType,
                        localToolConfig.BuildVariantsDict,
                        localToolConfig.AllowDevelopmentPlugins)

        # Get the platform and see if its supported
        platform = PluginConfig.GetGeneratorPluginById(
            localToolConfig.PlatformName, False)
        PlatformUtil.CheckBuildPlatform(platform.Name)
        generatorContext = GeneratorContext(config,
                                            config.ToolConfig.Experimental,
                                            platform)

        config.LogPrint("Active platform: {0}".format(platform.Name))

        discoverFeatureList = '*' in featureList
        topLevelPackage = None
        if discoverFeatureList or localToolConfig.Project is None:
            if discoverFeatureList:
                config.LogPrint(
                    "No features specified, so using package to determine them"
                )
            topLevelPackage = self.__ResolveAndGetTopLevelPackage(
                generatorContext, config, currentDirPath,
                toolConfig.GetMinimalConfig(), localToolConfig.Recursive)
            if discoverFeatureList:
                featureList = [
                    entry.Name
                    for entry in topLevelPackage.ResolvedAllUsedFeatures
                ]
            #if localToolConfig.Project is None:
            #    executeablePackage = PackageListUtil.FindFirstExecutablePackage(packages)
            #    localToolConfig.Project = executeablePackage.ShortName

        if localToolConfig.Validate:
            Validate.ValidatePlatform(config, localToolConfig.PlatformName,
                                      featureList)
            if topLevelPackage is None:
                topLevelPackage = self.__ResolveAndGetTopLevelPackage(
                    generatorContext, config, currentDirPath,
                    toolConfig.GetMinimalConfig(), localToolConfig.Recursive)
            RecipeBuilder.ValidateInstallationForPackages(
                config, generatorContext, topLevelPackage.ResolvedBuildOrder)

        if toolEnabled is not None and not ParseUtil.ParseBool(toolEnabled):
            if self.Log.Verbosity > 0:
                print(
                    "FslBuildContent has been disabled by environment variable %s set to %s"
                    % (CONFIG_FSLBUILDCONTENT_ENABLED, toolEnabled))
            return

        ContentBuilder.Build(config, currentDirPath, featureList)
    def __init__(self, generatorContext: GeneratorContext, config: Config,
                 topLevelPackage: Package, buildConfig: BuildConfigRecord,
                 enableContentBuilder: bool,
                 forceClaimInstallArea: bool) -> None:
        super().__init__()
        self.Log = config

        localPlatformBuildContext = LocalPlatformBuildContext(
            config, generatorContext.Generator.OriginalPlatformName,
            generatorContext.Generator.IsCMake, buildConfig.BuildThreads)

        # Do a final filter that removes all unsupported packages
        resolvedBuildOrder = topLevelPackage.ResolvedBuildOrder
        resolvedBuildOrder = PackageFilter.FilterNotSupported(
            self.Log, topLevelPackage, resolvedBuildOrder)
        if not PackageFilter.WasThisAExecutableBuildAndAreThereAnyLeft(
                topLevelPackage.ResolvedBuildOrder, resolvedBuildOrder):
            self.Log.DoPrint("No executables left, skipping all")
            return

        # Run the recipe builder on the packages we have left
        # We run the recipe builder on the resolvedBuildOrder since it all required packages, not just the ones we need to build as libs and executables
        builderSettings = BuilderSettings()
        builderSettings.ForceClaimInstallArea = forceClaimInstallArea
        builderSettings.BuildThreads = buildConfig.BuildThreads
        RecipeBuilder.BuildPackagesInOrder(config, generatorContext,
                                           resolvedBuildOrder, builderSettings)

        resolvedBuildOrderBuildable = PackageFilter.FilterBuildablePackages(
            resolvedBuildOrder)
        if len(resolvedBuildOrderBuildable) == 0:
            config.DoPrint("Nothing to build!")
            return

        generatorConfig = GeneratorConfig(
            generatorContext.PlatformName, config.SDKConfigTemplatePath,
            config.ToolConfig, localPlatformBuildContext.NumBuildThreads,
            buildConfig.BuildCommand)
        generatorConfigReport = generatorContext.Generator.TryGenerateConfigReport(
            self.Log, generatorConfig, topLevelPackage)

        packageCount = len(resolvedBuildOrderBuildable)

        resolvedBuildOrderBuildable = self.__ApplyPlatformOrderChanges(
            resolvedBuildOrderBuildable, buildConfig.PlatformName)
        originalBuildArgs = buildConfig.BuildArgs

        # Handle the configure step
        masterBuildReport = None  # type: Optional[GeneratorBuildReport]
        masterBuildVariableReport = None  # type: Optional[GeneratorVariableReport]
        if generatorConfigReport is not None:
            # Setup some extra variables for configure
            self.__AddCustomVariables(generatorConfigReport.VariableReport,
                                      config.ToolConfig.ProjectInfo)

            self.__ConfigureBuild(generatorConfigReport, buildConfig)
            masterBuildReport = generatorConfigReport.MasterBuildReport
            masterBuildVariableReport = generatorConfigReport.MasterBuildVariableReport
            if masterBuildVariableReport is not None:
                self.__AddCustomVariables(masterBuildVariableReport,
                                          config.ToolConfig.ProjectInfo)

        # Acquire information about the build step
        generatorReport = generatorContext.Generator.GenerateReport(
            self.Log, generatorConfig, resolvedBuildOrderBuildable)
        generatorReportDict = generatorReport.PackageReportDict
        for generatorEntry in generatorReportDict.values():
            if generatorEntry.VariableReport is not None:
                self.__AddCustomVariables(generatorEntry.VariableReport,
                                          config.ToolConfig.ProjectInfo)

        # Default content building for all platform (for those generators that don't add it to the build file)
        builderCanBuildContent = (generatorConfigReport is not None
                                  and generatorConfigReport.CanBuildContent)
        if enableContentBuilder and not builderCanBuildContent:
            for package in resolvedBuildOrderBuildable:
                if package.Type == PackageType.Executable:
                    featureList = [
                        entry.Name for entry in package.ResolvedAllUsedFeatures
                    ]
                    if package.Path is None:
                        raise Exception("Invalid package")
                    ContentBuilder.Build(config, package.Path, featureList)

        # Windows runs its validation checks slightly differently
        runValidationChecks = (buildConfig.PlatformName !=
                               PlatformNameString.WINDOWS)

        buildContext = LocalBuildContext(config, localPlatformBuildContext,
                                         generatorReportDict,
                                         generatorContext.GeneratorName)

        if masterBuildReport is not None:
            if masterBuildVariableReport is None:
                raise Exception("master-build must have a variable report")
            self.__BuildMaster(buildConfig, buildContext, masterBuildReport,
                               masterBuildVariableReport, topLevelPackage,
                               originalBuildArgs, builderCanBuildContent,
                               runValidationChecks, config.IsDryRun)

        # Build and run all the packages in the resolvedBuildOrderBuildable
        self.__BuildAndRunPackages(config, buildConfig, buildContext,
                                   resolvedBuildOrderBuildable,
                                   originalBuildArgs, builderCanBuildContent,
                                   runValidationChecks,
                                   masterBuildReport is None, config.IsDryRun,
                                   generatorConfig)

        if packageCount > 0:
            config.LogPrint("Build {0} packages".format(packageCount))
        else:
            config.DoPrint("Nothing build!")

        if generatorContext.Generator.IsCMake and buildConfig.BuildCommand == CommandType.Clean:
            self.Log.DoPrint(
                "*** To do a full cmake clean build delete the out of source build folder ***"
            )
        if not generatorContext.Generator.SupportCommandClean and buildConfig.BuildCommand == CommandType.Clean:
            self.Log.DoPrint("*** clean not supported by this builder ***")
        if not generatorContext.Generator.SupportCommandInstall and buildConfig.BuildCommand == CommandType.Install:
            self.Log.DoPrint("*** install not supported by this builder ***")
    def __init__(self, generatorContext: GeneratorContext, config: Config,
                 topLevelPackage: Package, buildConfig: BuildConfigRecord,
                 enableContentBuilder: bool,
                 forceClaimInstallArea: bool) -> None:
        super(Builder, self).__init__()
        self.Log = config

        localPlatformBuildContext = LocalPlatformBuildContext(
            config, generatorContext.Generator.OriginalName,
            buildConfig.BuildCommand, buildConfig.BuildThreads)

        # Do a final filter that removes all unsupported packages
        resolvedBuildOrder = topLevelPackage.ResolvedBuildOrder
        resolvedBuildOrder = PackageFilter.FilterNotSupported(
            self.Log, topLevelPackage, resolvedBuildOrder)
        if not PackageFilter.WasThisAExecutableBuildAndAreThereAnyLeft(
                topLevelPackage.ResolvedBuildOrder, resolvedBuildOrder):
            self.Log.DoPrint("No executables left, skipping all")
            return

        # Run the recipe builder on the packages we have left
        # We run the recipe builder on the resolvedBuildOrder since it all required packages, not just the ones we need to build as libs and executables
        builderSettings = BuilderSettings()
        builderSettings.ForceClaimInstallArea = forceClaimInstallArea
        builderSettings.BuildThreads = buildConfig.BuildThreads
        RecipeBuilder.BuildPackagesInOrder(config, generatorContext,
                                           resolvedBuildOrder, builderSettings)

        resolvedBuildOrderBuildable = PackageFilter.FilterBuildablePackages(
            resolvedBuildOrder)
        if len(resolvedBuildOrderBuildable) == 0:
            config.DoPrint("Nothing to build!")
            return

        generatorConfig = GeneratorConfig(config.SDKConfigTemplatePath,
                                          config.ToolConfig)
        generatorReportDict = generatorContext.Generator.GenerateReport(
            self.Log, generatorConfig, resolvedBuildOrderBuildable)

        packageCount = len(resolvedBuildOrderBuildable)

        resolvedBuildOrderBuildable = self.__ApplyPlatformOrderChanges(
            resolvedBuildOrderBuildable, buildConfig.PlatformName)

        originalBuildArgs = buildConfig.BuildArgs

        # Default content building for all platform (for those generators that don't add it to the build file)
        if enableContentBuilder:
            for package in resolvedBuildOrderBuildable:
                if package.Type == PackageType.Executable:
                    featureList = [
                        entry.Name for entry in package.ResolvedAllUsedFeatures
                    ]
                    if package.AbsolutePath is None:
                        raise Exception("Invalid package")
                    ContentBuilder.Build(config, package.AbsolutePath,
                                         featureList)

        # Windows runs its validation checks slightly differently
        runValidationChecks = (buildConfig.PlatformName !=
                               PlatformNameString.WINDOWS)

        buildContext = LocalBuildContext(config, localPlatformBuildContext,
                                         generatorReportDict,
                                         generatorContext.GeneratorName)
        for package in resolvedBuildOrderBuildable:
            config.LogPrint("Building package: {0}".format(package.Name))
            config.LogPrint("Package location: {0}".format(
                package.AbsolutePath))
            if not config.IsDryRun:
                buildEnv = os.environ.copy()  # type: Dict[str, str]
                buildEnv[CONFIG_FSLBUILDCONTENT_ENABLED] = "false"
                BuildVariantUtil.ExtendEnvironmentDictWithVariants(
                    config, buildEnv, package, buildConfig.VariantSettingsDict)
                buildConfig.BuildArgs = list(originalBuildArgs)
                if config.Verbosity > 4:
                    config.DoPrint("Package build arguments1: {0}".format(
                        buildConfig.BuildArgs))
                    config.DoPrint("General build arguments2: {0}".format(
                        originalBuildArgs))
                strRunCommands = buildConfig.RunCommand
                runCommands = None  # type: Optional[List[str]]
                if strRunCommands is not None:
                    userRunCommands = shlex.split(strRunCommands)
                    runCommands = self.__TryGenerateRunCommandForExecutable(
                        buildContext, package, buildConfig.VariantSettingsDict,
                        userRunCommands)
                if runValidationChecks:
                    featureList = [
                        entry.Name for entry in package.ResolvedAllUsedFeatures
                    ]
                    Validate.ValidatePlatform(config, buildConfig.PlatformName,
                                              featureList, 4)
                self.__BuildPackage(buildContext, package, buildConfig,
                                    buildEnv, runCommands)

        if packageCount > 0:
            config.LogPrint("Build {0} packages".format(packageCount))
        else:
            config.DoPrint("Nothing build!")
Exemple #10
0
    def Process(self, currentDirPath: str, toolConfig: ToolConfig,
                localToolConfig: LocalToolConfig) -> None:

        #self.Log.LogPrintVerbose(2, "*** Forcing the legacy clang tidy mode ***")
        #localToolConfig.Legacy = True

        config = Config(self.Log, toolConfig,
                        localToolConfig.PackageConfigurationType,
                        localToolConfig.BuildVariantsDict,
                        localToolConfig.AllowDevelopmentPlugins)

        # create a config we control and that can be used to just build the tool recipe's
        configToolCheck = Config(self.Log, toolConfig,
                                 PluginSharedValues.TYPE_DEFAULT,
                                 localToolConfig.BuildVariantsDict,
                                 localToolConfig.AllowDevelopmentPlugins)
        if localToolConfig.DryRun:
            config.ForceDisableAllWrite()
            configToolCheck.ForceDisableAllWrite()

        self.__CheckUserArgs(localToolConfig.ClangFormatArgs, "formatArgs")
        self.__CheckUserArgs(localToolConfig.ClangTidyArgs, "tidyArgs")
        self.__CheckUserArgs(localToolConfig.ClangTidyPostfixArgs,
                             "tidyPostfixArgs")

        applyClangFormat = toolConfig.ClangFormatConfiguration is not None and localToolConfig.ClangFormat
        applyClangTidy = toolConfig.ClangTidyConfiguration is not None and localToolConfig.ClangTidy

        if localToolConfig.IgnoreNotSupported or (
            (localToolConfig.ScanSource or applyClangFormat)
                and not applyClangTidy):
            config.IgnoreNotSupported = True
            configToolCheck.IgnoreNotSupported = True

        packageFilters = localToolConfig.BuildPackageFilters

        # Get the platform and see if its supported
        buildVariantConfig = BuildVariantConfigUtil.GetBuildVariantConfig(
            localToolConfig.BuildVariantsDict)
        if localToolConfig.Legacy and applyClangTidy and config.ToolConfig.CMakeConfiguration is not None:
            # For the LEGACY clangTidy implementation we disable allow find package for the build checks for now as we dont use cmake for those
            # We basically have to update the tidy pass to utilize ninja+cmake for the tidy pass so that find_package will work
            self.Log.LogPrintVerbose(2, "Force disabling 'AllowFindPackage'")
            config.ToolConfig.CMakeConfiguration.SetAllowFindPackage(False)

        cmakeUserConfig = localToolConfig.GetUserCMakeConfig()
        if not localToolConfig.Legacy and applyClangTidy:
            config.LogPrintVerbose(
                2, "Forcing the ninja generator for clang tidy")
            cmakeUserConfig.GeneratorName = "Ninja"

        generator = self.ToolAppContext.PluginConfigContext.GetGeneratorPluginById(
            localToolConfig.PlatformName, localToolConfig.Generator,
            buildVariantConfig, config.ToolConfig.DefaultPackageLanguage,
            config.ToolConfig.CMakeConfiguration, cmakeUserConfig, True)
        PlatformUtil.CheckBuildPlatform(generator.PlatformName)
        generatorContext = GeneratorContext(config, self.ErrorHelpManager,
                                            packageFilters.RecipeFilterManager,
                                            config.ToolConfig.Experimental,
                                            generator)

        self.Log.LogPrint("Active platform: {0}".format(
            generator.PlatformName))

        packageRecipeResultManager = None  # type: Optional[PackageRecipeResultManager]
        toolPackageNamesSet = set()
        toolPackageNames = []
        if applyClangFormat or applyClangTidy:
            if applyClangFormat:
                if toolConfig.ClangFormatConfiguration is None:
                    raise Exception("internal error")
                toolPackageNamesSet.add(
                    toolConfig.ClangFormatConfiguration.RecipePackageName)
                toolPackageNamesSet.add(
                    toolConfig.ClangFormatConfiguration.NinjaRecipePackageName)
            if applyClangTidy:
                if toolConfig.ClangTidyConfiguration is None:
                    raise Exception("internal error")
                toolPackageNamesSet.add(
                    toolConfig.ClangTidyConfiguration.ClangRecipePackageName)
                toolPackageNamesSet.add(toolConfig.ClangTidyConfiguration.
                                        ClangTidyRecipePackageName)
                toolPackageNamesSet.add(
                    toolConfig.ClangTidyConfiguration.NinjaRecipePackageName)
            toolPackageNames = list(toolPackageNamesSet)
            packageRecipeResultManager = ForceCheckBuildTools(
                configToolCheck, generatorContext, toolPackageNames)

        searchDir = currentDirPath
        if localToolConfig.File is not None:
            localToolConfig.File = IOUtil.NormalizePath(localToolConfig.File)
            if IOUtil.IsAbsolutePath(localToolConfig.File):
                searchDir = IOUtil.GetDirectoryName(localToolConfig.File)
        closestGenFilePath = FileFinder.TryFindClosestFileInRoot(
            config, toolConfig, searchDir, config.GenFileName)
        if closestGenFilePath is None:
            closestGenFilePath = searchDir

        if self.Log.Verbosity >= 4:
            self.Log.LogPrint("Closest '{0}' file path: '{1}'".format(
                toolConfig.GenFileName, closestGenFilePath))

        packageProcess = None  # type: Optional[MainFlow.PackageLoadAndResolveProcess]
        packages = None
        discoverFeatureList = '*' in packageFilters.FeatureNameList
        if discoverFeatureList or localToolConfig.Project is None or localToolConfig.ScanSource or applyClangFormat or applyClangTidy:
            if discoverFeatureList:
                config.LogPrint(
                    "No features specified, so using package to determine them"
                )
            if localToolConfig.ScanSource or applyClangFormat or applyClangTidy or discoverFeatureList:
                packageProcess = self.__CreatePackageProcess(
                    config, toolConfig.GetMinimalConfig(generator.CMakeConfig),
                    closestGenFilePath, localToolConfig.Recursive,
                    generatorContext.Platform, toolPackageNames)
                packageProcess.Resolve(generatorContext, packageFilters,
                                       applyClangTidy, False)
                packages = packageProcess.Packages
                topLevelPackage = PackageListUtil.GetTopLevelPackage(packages)
                if discoverFeatureList:
                    packageFilters.FeatureNameList = [
                        entry.Name
                        for entry in topLevelPackage.ResolvedAllUsedFeatures
                    ]

        customPackageFileFilter = None  # type: Optional[CustomPackageFileFilter]
        if not localToolConfig.ScanSource and not applyClangFormat and not applyClangTidy:
            Validate.ValidatePlatform(config, localToolConfig.PlatformName,
                                      packageFilters.FeatureNameList)
            if packageProcess is None:
                packageProcess = self.__CreatePackageProcess(
                    config, toolConfig.GetMinimalConfig(generator.CMakeConfig),
                    closestGenFilePath, localToolConfig.Recursive,
                    generatorContext.Platform, toolPackageNames)
            if not packageProcess.IsFullResolve or packages is None:
                # For now this requires a full resolve (but basically it only requires basic + files)
                packages = packageProcess.Resolve(generatorContext,
                                                  packageFilters,
                                                  applyClangTidy, True)

            topLevelPackage = PackageListUtil.GetTopLevelPackage(packages)
            RecipeBuilder.ValidateInstallationForPackages(
                config, config.SDKPath, generatorContext,
                topLevelPackage.ResolvedBuildOrder)
        else:
            if localToolConfig.File is not None:
                # Delay extension validation
                customPackageFileFilter = CustomPackageFileFilter(
                    localToolConfig.File)

        theTopLevelPackage = None  # type: Optional[Package]
        filteredPackageList = []  # type: List[Package]
        if applyClangTidy or applyClangFormat or localToolConfig.ScanSource:
            addExternals = applyClangTidy
            filteredPackageList, theTopLevelPackage = self.__PreparePackages(
                self.Log, localToolConfig, packageProcess, generatorContext,
                packageFilters, addExternals, packages, config.IsSDKBuild,
                applyClangTidy, config)
            if len(filteredPackageList) <= 0:
                self.Log.DoPrint("No supported packages left to process")
                return

        if applyClangTidy:
            self.__ApplyClangTidy(self.Log, toolConfig, localToolConfig,
                                  packageRecipeResultManager,
                                  theTopLevelPackage, filteredPackageList,
                                  generator, config, generatorContext,
                                  customPackageFileFilter)

        if applyClangFormat:
            self.__ApplyClangFormat(self.Log, toolConfig, localToolConfig,
                                    packageRecipeResultManager,
                                    filteredPackageList,
                                    customPackageFileFilter,
                                    generatorContext.CMakeConfig)

        # Scan source after 'format' to ensure we dont warn about stuff that has been fixed
        if localToolConfig.ScanSource:
            self.__ApplyScanSource(self.Log, localToolConfig,
                                   config.IsSDKBuild, config.DisableWrite,
                                   filteredPackageList,
                                   customPackageFileFilter)
Exemple #11
0
def ForceBuildExternals(config: Config, generatorContext: GeneratorContext,
                        packages: List[Package]) -> None:
    builderConfig = BuilderConfig()
    RecipeBuilder.BuildPackages(config, config.SDKPath, config.IsDryRun,
                                config.ToolConfig, generatorContext,
                                builderConfig, packages)