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 __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!")