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 BuildPackages(
    config: Config,
    generatorContext: GeneratorContext,
    builderConfig: BuilderConfig,
    packages: List[Package],
    packageRecipeResultManager: Optional[PackageRecipeResultManager] = None
) -> None:
    if packageRecipeResultManager is None:
        packageRecipeResultManager = PackageRecipeResultManager(config)

    PlatformUtil.CheckBuildPlatform(generatorContext.Platform.PlatformName)
    topLevelPackage = PackageListUtil.GetTopLevelPackage(packages)

    buildConfig = BuildConfigRecord(config.ToolConfig.ToolVersion,
                                    generatorContext.Platform.PlatformName, {},
                                    CommandType.Build, [], None, None, 0)

    basicConfig = generatorContext.BasicConfig
    try:
        basicConfig.LogPrint("- Building recipe packages")
        basicConfig.PushIndent()
        __BuildNow(config, generatorContext, builderConfig, topLevelPackage,
                   buildConfig, packageRecipeResultManager)
    finally:
        basicConfig.PopIndent()
Exemplo n.º 3
0
    def Process(self, currentDirPath: str, toolConfig: ToolConfig,
                localToolConfig: LocalToolConfig) -> None:
        config = Config(self.Log, toolConfig, 'sdk',
                        localToolConfig.BuildVariantsDict,
                        localToolConfig.AllowDevelopmentPlugins)
        if localToolConfig.DryRun:
            config.ForceDisableAllWrite()

        if localToolConfig.ToCDepth < 1:
            localToolConfig.ToCDepth = 1
        elif localToolConfig.ToCDepth > 4:
            localToolConfig.ToCDepth = 4

        config.PrintTitle()

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

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

        packageFilters = localToolConfig.BuildPackageFilters

        theFiles = MainFlow.DoGetFiles(config, toolConfig.GetMinimalConfig(),
                                       currentDirPath,
                                       localToolConfig.Recursive)
        generatorContext = GeneratorContext(config,
                                            config.ToolConfig.Experimental,
                                            platform)
        packages = MainFlow.DoGetPackages(generatorContext, config, theFiles,
                                          packageFilters)
        #topLevelPackage = PackageListUtil.GetTopLevelPackage(packages)
        #featureList = [entry.Name for entry in topLevelPackage.ResolvedAllUsedFeatures]

        for rootDir in config.ToolConfig.RootDirectories:
            readmePath = IOUtil.Join(rootDir.ResolvedPath, "README.md")
            packageReadMeLines = TryLoadReadMe(config, readmePath)
            result = ProcessPackages(self.ToolAppContext, config, packages,
                                     rootDir, localToolConfig.ExtractArguments,
                                     toolConfig.BuildDocConfiguration)
            if packageReadMeLines is not None:
                packageReadMeLinesNew = TryReplaceSection(
                    config, packageReadMeLines, "AG_DEMOAPPS", result,
                    readmePath)
                if packageReadMeLinesNew is not None:
                    packageReadMeLines = packageReadMeLinesNew

                packageReadMeLinesNew = TryInsertTableOfContents(
                    config, packageReadMeLines, localToolConfig.ToCDepth,
                    readmePath)
                if packageReadMeLinesNew is not None:
                    packageReadMeLines = packageReadMeLinesNew

                SaveReadMe(config, readmePath, packageReadMeLines)
            elif config.Verbosity > 2:
                config.LogPrintWarning("No README.md found in {0}".format(
                    rootDir.ResolvedPath))
Exemplo n.º 4
0
    def Process(self, currentDirPath: str, toolConfig: ToolConfig, localToolConfig: LocalToolConfig) -> None:
        config = Config(self.Log, toolConfig, 'sdk', localToolConfig.BuildVariantsDict, localToolConfig.AllowDevelopmentPlugins)
        if localToolConfig.DryRun:
            config.ForceDisableAllWrite()

        if localToolConfig.ToCDepth < 1:
            localToolConfig.ToCDepth = 1
        elif localToolConfig.ToCDepth > 4:
            localToolConfig.ToCDepth = 4

        config.PrintTitle()

        # Get the generator 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)

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

        packageFilters = localToolConfig.BuildPackageFilters

        theFiles = MainFlow.DoGetFiles(config, toolConfig.GetMinimalConfig(), currentDirPath, localToolConfig.Recursive)
        generatorContext = GeneratorContext(config, self.ErrorHelpManager, packageFilters.RecipeFilterManager, config.ToolConfig.Experimental, generator)
        packages = MainFlow.DoGetPackages(generatorContext, config, theFiles, packageFilters)
        #topLevelPackage = PackageListUtil.GetTopLevelPackage(packages)
        #featureList = [entry.Name for entry in topLevelPackage.ResolvedAllUsedFeatures]

        for projectContext in config.ToolConfig.ProjectInfo.Contexts:
            rootDir = self.__TryLocateRootDirectory(config.ToolConfig.RootDirectories, projectContext.Location)
            if rootDir is None:
                raise Exception("Root directory not found for location {0}".format(projectContext.Location))
            readmePath = IOUtil.Join(rootDir.ResolvedPath, "README.md")
            packageReadMeLines = TryLoadReadMe(config, readmePath)
            result = ProcessPackages(self.ToolAppContext, config, packages, rootDir, localToolConfig.ExtractArguments,
                                     toolConfig.BuildDocConfiguration, currentDirPath)
            if packageReadMeLines is not None:
                projectCaption = "# {0} {1}".format(projectContext.ProjectName, projectContext.ProjectVersion)
                packageReadMeLinesNew = TryReplaceSection(config, packageReadMeLines, "AG_PROJECT_CAPTION", [projectCaption], readmePath)
                if packageReadMeLinesNew is not None:
                    packageReadMeLines = packageReadMeLinesNew

                packageReadMeLinesNew = TryReplaceSection(config, packageReadMeLines, "AG_DEMOAPPS", result, readmePath)
                if packageReadMeLinesNew is not None:
                    packageReadMeLines = packageReadMeLinesNew

                packageReadMeLinesNew = TryInsertTableOfContents(config, packageReadMeLines, localToolConfig.ToCDepth, readmePath)
                if packageReadMeLinesNew is not None:
                    packageReadMeLines = packageReadMeLinesNew

                SaveReadMe(config, readmePath, packageReadMeLines)
            elif config.Verbosity > 2:
                config.LogPrintWarning("No README.md found in {0}".format(rootDir.ResolvedPath))
    def Process(self, currentDirPath: str, toolConfig: ToolConfig, localToolConfig: LocalToolConfig) -> None:
        config = Config(self.Log, toolConfig, localToolConfig.PackageConfigurationType,
                        localToolConfig.BuildVariantsDict, localToolConfig.AllowDevelopmentPlugins)

        if localToolConfig.DryRun:
            config.ForceDisableAllWrite()
        if localToolConfig.IgnoreNotSupported:
            config.IgnoreNotSupported = True

        # Get the platform and see if its supported
        platformGeneratorPlugin = PluginConfig.GetGeneratorPluginById(localToolConfig.PlatformName, localToolConfig.Generator, False,
                                                                      config.ToolConfig.CMakeConfiguration, localToolConfig.GetUserCMakeConfig())
        PlatformUtil.CheckBuildPlatform(platformGeneratorPlugin.PlatformName)

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

        theFiles = MainFlow.DoGetFiles(config, toolConfig.GetMinimalConfig(), currentDirPath, localToolConfig.Recursive)

        generatorContext = GeneratorContext(config, localToolConfig.BuildPackageFilters.RecipeFilterManager, config.ToolConfig.Experimental, platformGeneratorPlugin)
        PluginConfig.SetLegacyGeneratorType(localToolConfig.GenType)

        packageFilters = localToolConfig.BuildPackageFilters
        packages = MainFlow.DoGenerateBuildFilesNoAll(config, theFiles, platformGeneratorPlugin, packageFilters)

        topLevelPackage = PackageListUtil.GetTopLevelPackage(packages)

        requestedFiles = None if config.IsSDKBuild else theFiles

        # We need the generator to be able to examine its support

        if localToolConfig.ListFeatures or localToolConfig.ListVariants or localToolConfig.ListExtensions or localToolConfig.ListRequirements:
            if localToolConfig.ListFeatures:
                Builder.ShowFeatureList(self.Log, config, topLevelPackage, requestedFiles)
            if localToolConfig.ListVariants:
                Builder.ShowVariantList(self.Log, topLevelPackage, requestedFiles, platformGeneratorPlugin)
            if localToolConfig.ListExtensions:
                Builder.ShowExtensionList(self.Log, topLevelPackage, requestedFiles)
            if localToolConfig.ListRequirements:
                Builder.ShowRequirementList(self.Log, config, topLevelPackage, requestedFiles)
        else:
            if localToolConfig.BuildPackageFilters is None or localToolConfig.BuildPackageFilters.ExtensionNameList is None:
                raise Exception("localToolConfig.BuildPackageFilters.ExtensionNameList not set")
            Builder.BuildPackages(generatorContext, config, packages,
                                  localToolConfig.BuildVariantsDict, localToolConfig.RemainingArgs, localToolConfig.ForAllExe,
                                  platformGeneratorPlugin, localToolConfig.EnableContentBuilder, localToolConfig.ForceClaimInstallArea,
                                  localToolConfig.BuildThreads, localToolConfig.Command)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
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))
Exemplo n.º 8
0
def BuildPackages(log: Log, configSDKPath: str, configIsDryRun: bool, toolConfig: ToolConfig,
                  generatorContext: GeneratorContext,
                  builderConfig: BuilderConfig,
                  packages: List[Package],
                  packageRecipeResultManager: Optional[PackageRecipeResultManager] = None) -> None:
    if packageRecipeResultManager is None:
        packageRecipeResultManager = PackageRecipeResultManager(log)

    PlatformUtil.CheckBuildPlatform(generatorContext.Platform.PlatformName)
    topLevelPackage = PackageListUtil.GetTopLevelPackage(packages)

    buildConfig = BuildConfigRecord(toolConfig.ToolVersion, generatorContext.Platform.PlatformName, {}, CommandType.Build, [], None, None, 0)

    try:
        log.LogPrint("- Building recipe packages")
        log.PushIndent()
        __BuildNow(log, configSDKPath, configIsDryRun, generatorContext, builderConfig, topLevelPackage, buildConfig, packageRecipeResultManager)
    finally:
        log.PopIndent()
    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)
Exemplo n.º 10
0
    def __ToolMainEx(self,
                     currentDir: str,
                     toolConfig: ToolConfig,
                     localToolConfig: LocalToolConfig,
                     templateDict: Dict[str, List[XmlNewTemplateFile]],
                     performSanityCheck: bool = False) -> None:

        config = Config(self.Log, toolConfig, 'sdk',
                        localToolConfig.BuildVariantsDict,
                        localToolConfig.AllowDevelopmentPlugins)
        #config.ForceDisableAllWrite()

        config.PrintTitle()

        packageFilters = localToolConfig.BuildPackageFilters

        reservedProjectNames = set()  # type: Set[str]
        packages = None  # type: Optional[List[Package]]
        if not localToolConfig.NoParse:
            # Get the generator and see if its supported on this platform
            buildVariantConfig = BuildVariantConfigUtil.GetBuildVariantConfig(
                localToolConfig.BuildVariantsDict)
            generator = self.ToolAppContext.PluginConfigContext.GetGeneratorPluginById(
                localToolConfig.PlatformName, localToolConfig.Generator,
                buildVariantConfig, config.ToolConfig.DefaultPackageLanguage,
                config.ToolConfig.CMakeConfiguration,
                localToolConfig.GetUserCMakeConfig(), False)
            PlatformUtil.CheckBuildPlatform(generator.PlatformName)
            config.LogPrint("Active platform: {0}".format(
                generator.PlatformName))
            generatorContext = GeneratorContext(
                config, self.ErrorHelpManager,
                packageFilters.RecipeFilterManager,
                config.ToolConfig.Experimental, generator)
            packages = ParsePackages(
                generatorContext, config,
                toolConfig.GetMinimalConfig(generator.CMakeConfig), currentDir,
                packageFilters)

        # Reserve the name of all packages
        if not packages is None:
            for package in packages:
                reservedProjectNames.add(package.Name)

        currentDir, projectName = DetermineDirAndProjectName(
            currentDir, localToolConfig.ProjectName)
        localConfig = LocalConfig(config, currentDir, projectName,
                                  localToolConfig.Template,
                                  localToolConfig.Force, templateDict,
                                  reservedProjectNames,
                                  localToolConfig.Language)
        configVariant = localConfig.ConfigVariant

        if not localToolConfig.AllowOverwrite:
            if os.path.isdir(configVariant.ProjectPath):
                raise EnvironmentError(
                    "The project directory already exist: '{0}', you can use '{1}' to overwrite it."
                    .format(configVariant.ProjectPath, g_allowOverwriteOption))
            elif os.path.exists(configVariant.ProjectPath):
                raise EnvironmentError(
                    "A file named '{0}' already exist, you can use '{1}' to overwrite it."
                    .format(configVariant.ProjectPath, g_allowOverwriteOption))

        visualStudioGUID = localToolConfig.VisualStudioGUID
        if packages:
            visualStudioGUID = GeneratorVCUtil.GenerateGUID(
                config, packages, visualStudioGUID)

        GenerateProject(config, localConfig, configVariant, visualStudioGUID,
                        localToolConfig.GenFileOnly)

        if not localToolConfig.NoBuildGen:
            config.DoPrint("Generating build files")
            projectConfig = Config(self.Log, toolConfig,
                                   PluginSharedValues.TYPE_DEFAULT,
                                   localToolConfig.BuildVariantsDict,
                                   localToolConfig.AllowDevelopmentPlugins)

            theFiles = MainFlow.DoGetFiles(
                projectConfig,
                toolConfig.GetMinimalConfig(generator.CMakeConfig),
                configVariant.ProjectPath)
            buildVariantConfig = BuildVariantConfigUtil.GetBuildVariantConfig(
                localToolConfig.BuildVariantsDict)
            platformGeneratorPlugin = self.ToolAppContext.PluginConfigContext.GetGeneratorPluginById(
                localToolConfig.PlatformName, localToolConfig.Generator,
                buildVariantConfig, config.ToolConfig.DefaultPackageLanguage,
                config.ToolConfig.CMakeConfiguration,
                localToolConfig.GetUserCMakeConfig(), False)
            MainFlow.DoGenerateBuildFiles(
                self.ToolAppContext.PluginConfigContext, projectConfig,
                self.ErrorHelpManager, theFiles, platformGeneratorPlugin,
                packageFilters)

            if performSanityCheck:
                self.__PerformSanityCheck(config, currentDir,
                                          localConfig.ProjectName,
                                          localConfig.Template)
    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)
Exemplo n.º 12
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)