def BuildPackages(generatorContext: GeneratorContext, config: Config,
                  packages: List[Package], variantSettingsDict: Dict[str, str],
                  buildArgs: List[str], buildForAllExe: Optional[str],
                  generator: GeneratorPluginBase2, enableContentBuilder: bool,
                  forceClaimInstallArea: bool, buildThreads: int,
                  buildCommand: int) -> None:
    PlatformUtil.CheckBuildPlatform(generatorContext.PlatformName)
    topLevelPackage = PackageListUtil.GetTopLevelPackage(packages)

    BuildVariantUtil.ValidateUserVariantSettings(config, topLevelPackage,
                                                 variantSettingsDict)
    BuildVariantUtil.LogVariantSettings(config, variantSettingsDict)

    buildConfig = BuildConfigRecord(generatorContext.PlatformName,
                                    variantSettingsDict, buildCommand,
                                    buildArgs, buildForAllExe, generator,
                                    buildThreads)
    Builder(generatorContext, config, topLevelPackage, buildConfig,
            enableContentBuilder, forceClaimInstallArea)
    def __CreateBuildEnv(self, log: Log, buildConfig: BuildConfigRecord,
                         buildContext: LocalBuildContext, package: Package,
                         builderCanBuildContent: bool) -> Dict[str, str]:
        buildEnv = os.environ.copy()  # type: Dict[str, str]
        if not builderCanBuildContent:
            buildEnv[CONFIG_FSLBUILDCONTENT_ENABLED] = "false"

        BuildVariantUtil.ExtendEnvironmentDictWithVariants(
            log, buildEnv, package, buildConfig.VariantSettingsDict)
        return buildEnv
def BuildPackages(generatorContext: GeneratorContext,
                  config: Config,
                  packages: List[Package],
                  variantSettingsDict: Dict[str, str],
                  buildArgs: List[str],
                  buildForAllExe: Optional[str],
                  generator: GeneratorPluginBase2,
                  enableContentBuilder: bool,
                  forceClaimInstallArea: bool,
                  buildThreads: int,
                  buildCommand: CommandType,
                  printPathIfCMake: bool = False) -> None:
    PlatformUtil.CheckBuildPlatform(generatorContext.PlatformName)
    topLevelPackage = PackageListUtil.GetTopLevelPackage(packages)

    BuildVariantUtil.ValidateUserVariantSettings(config, topLevelPackage,
                                                 variantSettingsDict)
    BuildVariantUtil.LogVariantSettings(config, variantSettingsDict)

    buildConfig = BuildConfigRecord(config.ToolConfig.ToolVersion,
                                    generatorContext.PlatformName,
                                    variantSettingsDict, buildCommand,
                                    buildArgs, buildForAllExe, generator,
                                    buildThreads)
    builder = Builder(generatorContext, config, topLevelPackage, buildConfig,
                      enableContentBuilder, forceClaimInstallArea)

    # Print executable paths if enabled and its a cmake type build
    if printPathIfCMake and generatorContext.Generator.IsCMake and buildCommand == CommandType.Build and topLevelPackage is not None:
        for depPackage in topLevelPackage.ResolvedAllDependencies:
            package = depPackage.Package
            if package.Type == PackageType.Executable and builder.UsedBuildContext is not None and builder.UsedGeneratorConfig is not None:
                if not package.ResolvedPlatformNotSupported:
                    runCommand = builder.TryGenerateRunCommandForExecutable(
                        builder.UsedBuildContext, package, buildConfig,
                        ["(EXE)"], builder.UsedGeneratorConfig)
                    if runCommand is not None:
                        config.DoPrint("Executable at: '{0}'".format(
                            runCommand[0]))
                else:
                    config.LogPrint(
                        "Package '{0}' was not supported on this platform".
                        format(package.Name))
def ShowVariantList(log: Log, topLevelPackage: Package,
                    requestedFiles: Optional[List[str]],
                    generator: GeneratorPluginBase2) -> None:

    variantDict = BuildVariantUtil.BuildCompleteVariantDict(topLevelPackage)

    # This is kind of a hack to list this here (its also not a real variant inside our model)
    generatorVariants = generator.GetVariants()
    if len(variantDict) <= 0 and len(generatorVariants) <= 0:
        log.DoPrint("Variants: None")
        return

    # Pretty print useful information
    log.DoPrint("Variants:")

    generatorVariants.sort(key=lambda s: s.Name.lower())
    for variantInfo in generatorVariants:
        if variantInfo.Type == BuildVariantType.Static:
            log.DoPrint(
                "  {0}={1} (Introduced by native build system generator)".
                format(variantInfo.Name, variantInfo.Description))
        else:
            log.DoPrint("  {0}={1} (Introduced by native build system)".format(
                variantInfo.Name, variantInfo.Description))

    variantNames = list(variantDict.keys())
    variantNames.sort()
    for variantName in variantNames:
        variant = variantDict[variantName]
        optionNames = list(variant.OptionDict.keys())
        optionNames.sort()
        if variant.Type == VariantType.Virtual:
            log.DoPrint(
                "  {0}={1} *Virtual* (Introduced by package: {2})".format(
                    variant.PurifiedName, ', '.join(optionNames),
                    variant.IntroducedByPackageName))
        else:
            log.DoPrint(("  {0}={1} (Introduced by package: {2})".format(
                variant.PurifiedName, ', '.join(optionNames),
                variant.IntroducedByPackageName)))
    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!")
    def Run(log: Log, toolConfig: ToolConfig, platformId: str,
            topLevelPackage: Package, tidyPackageList: List[Package],
            userBuildVariantsDict: Dict[str, str], pythonScriptRoot: str,
            generatorContext: GeneratorContext, sdkConfigTemplatePath: str,
            packageRecipeResultManager: PackageRecipeResultManager,
            performClangTidyConfig: PerformClangTidyConfig,
            customPackageFileFilter: Optional[CustomPackageFileFilter],
            clangFormatFilename: Optional[str], buildThreads: int) -> None:
        """
        RunClangTidy on a package at a time
        :param topLevelPackage: the top level system package
        :param tidyPackageList: the packages to 'tidy'
        :param userBuildVariantsDict: the variant configuration supplied by the user
        :param performClangTidyConfig:
        :param customPackageFileFilter:
        :param clangFormatFilename:
        :param repairEnabled:
        """

        # Lookup the recommended build threads using the standard build algorithm
        buildThreads = PlatformBuildUtil.GetRecommendedBuildThreads(
            buildThreads)

        clangExeInfo = PerformClangUtil.LookupRecipeResults(
            packageRecipeResultManager,
            performClangTidyConfig.ClangTidyConfiguration.RecipePackageName,
            MagicValues.ClangTidyCommand)

        BuildVariantUtil.ValidateUserVariantSettings(log, topLevelPackage,
                                                     userBuildVariantsDict)
        BuildVariantUtil.LogVariantSettings(log, userBuildVariantsDict)
        resolvedVariantSettingsDict = BuildVariantUtil.CreateCompleteStaticVariantSettings(
            topLevelPackage.ResolvedAllVariantDict, userBuildVariantsDict)

        if log.Verbosity >= 1:
            PerformClangUtil.ShowVersion(log, clangExeInfo)
        log.LogPrint("Running clang-tidy")

        # Filter the package list so it only contains things we can process
        finalPackageList = [
            package for package in tidyPackageList
            if PerformClangUtil.CanProcessPackage(package)
        ]

        generatorConfig = GeneratorConfig(sdkConfigTemplatePath, toolConfig)
        generatorReportDict = generatorContext.Generator.GenerateReport(
            log, generatorConfig, finalPackageList)

        # Validate report dict
        for package in finalPackageList:
            if package not in generatorReportDict:
                raise Exception(
                    "Generator report is missing information for package '{0}'"
                    .format(package.Name))

        localVariantInfo = LocalVariantInfo(resolvedVariantSettingsDict,
                                            generatorReportDict,
                                            pythonScriptRoot)

        count = PerformClangTidyHelper.ProcessAllPackages(
            log, toolConfig, platformId, pythonScriptRoot,
            performClangTidyConfig, clangExeInfo, finalPackageList,
            customPackageFileFilter, localVariantInfo, buildThreads)
        if count == 0:
            if customPackageFileFilter is None:
                log.DoPrintWarning("No files processed")
            else:
                log.DoPrintWarning(
                    "No files processed, could not find a package that matches {0}"
                    .format(customPackageFileFilter))