Exemple #1
0
    def DoGenerate(self, platformContext: PlatformContext, config: Config,
                   packages: List[Package]) -> List[Package]:
        generator = None  # type: Optional[GeneratorBase]

        topLevelPackage = PackageListUtil.GetTopLevelPackage(packages)

        androidABIList = self.OptionAndroidABI_all
        if GEN_MAGIC_VARIANT_ANDROID_ABI in config.VariantsDict:
            androidABI = config.VariantsDict[GEN_MAGIC_VARIANT_ANDROID_ABI]
            if androidABI != 'all':
                if not androidABI in self.VariantAndroidABI.Options:
                    raise Exception(
                        "'{0}' is not a valid option expected one of these {1}"
                        .format(androidABI, self.VariantAndroidABI.Options))
                androidABIList = [androidABI]
        # remove unsupported ABI's if there are others available to build
        if self.__ContainsFeature(topLevelPackage.ResolvedAllUsedFeatures,
                                  "vulkan"):
            if len(
                    androidABIList
            ) > 1 and AndroidABIOption.DeprecatedArmeAbi in androidABIList:
                config.LogPrint(
                    "INFO: Vulkan does not support ANDROID_ABI '{0}' removing the ABI and building the rest"
                    .format(AndroidABIOption.DeprecatedArmeAbi))
                androidABIList.remove(AndroidABIOption.DeprecatedArmeAbi)

        generator = GeneratorAndroidGradleCMake(config, packages, self.Name,
                                                androidABIList)
        return self.GenerateDone(config, packages, self.Name, generator)
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()
    def __PreparePackages(self, log: Log, localToolConfig: LocalToolConfig,
                          packageProcess: Optional[
                              MainFlow.PackageLoadAndResolveProcess],
                          generatorContext: GeneratorContext,
                          packageFilters: PackageFilters, addExternals: bool,
                          packages: Optional[List[Package]], isSdkBuild: bool,
                          applyClangTidy: bool,
                          config: Config) -> Tuple[List[Package], Package]:
        if packages is None or packageProcess is None:
            raise Exception("Packages can not be None")
        if not packageProcess.IsFullResolve:
            # For now this requires a full resolve (but basically it only requires basic + files)
            packages = packageProcess.Resolve(generatorContext, packageFilters,
                                              addExternals, True)

        if applyClangTidy:
            if packages is None:
                raise Exception("Packages can not be None")
            ForceBuildExternals(config, generatorContext, packages)

        specifiedPackages = []  # type: List[Package]
        if isSdkBuild:
            specifiedPackages = list(packages)
        else:
            packageDict = {}
            for package in packages:
                packageDict[package.Name] = package
            for entry in packageProcess.FoundInputFiles:
                packageName = entry.PackageName
                if packageName in packageDict:
                    specifiedPackages.append(packageDict[packageName])
        topLevelPackage = PackageListUtil.GetTopLevelPackage(packages)
        return (ToolPackageFiltering.FilterPackages(
            self.Log, topLevelPackage, specifiedPackages,
            localToolConfig.ScanDependencies), topLevelPackage)
Exemple #4
0
    def __Filter(self, platformContext: PlatformContext,
                 packageFilters: PackageFilters,
                 autoAddRecipeExternals: bool,
                 sourceGenFiles: List[XmlGenFile]) -> List[XmlGenFile]:

        if not packageFilters.ContainsFilters():
            return sourceGenFiles

        self.Log.LogPrint("- Filtering")
        try:
            self.Log.PushIndent()
            packageResolver = PackageResolver(platformContext, self.Config, sourceGenFiles,
                                              autoAddRecipeExternals, False,
                                              self.MarkExternalLibFirstUse,
                                              packageFilters.RecipeFilterManager)
            packages = packageResolver.Packages

            topLevelPackage = PackageListUtil.GetTopLevelPackage(packages)
            requestedFiles = self.SourceFiles
            requestedPackages = PackageUtil.TryGetPackageListFromFilenames(topLevelPackage, requestedFiles, False)
            resolvedBuildOrder = PackageFilter.Filter(self.Log, topLevelPackage, requestedPackages, packageFilters)

            # Now do a lookup of package -> Genfile to provide a filtered gen file list
            genFileSet = set(sourceGenFiles)
            return [package.GenFile for package in resolvedBuildOrder if package.GenFile is not None and package.GenFile in genFileSet]
        finally:
            self.Log.PopIndent()
    def __ResolveAndGetTopLevelPackage(self, generatorContext: GeneratorContext, config: Config, currentDir: str,
                                       toolMiniConfig: ToolMinimalConfig, recursive: bool) -> Package:
        # Since we use this to discover filters, we just use a empty one
        noPackageFilters = PackageFilters()

        theFiles = MainFlow.DoGetFiles(config, toolMiniConfig, currentDir, recursive)
        packages = MainFlow.DoGetPackages(generatorContext, config, theFiles, noPackageFilters)
        return PackageListUtil.GetTopLevelPackage(packages)
Exemple #6
0
    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

        self.Log.PrintTitle()

        packageFilters = localToolConfig.BuildPackageFilters

        buildVariantConfig = BuildVariantConfigUtil.GetBuildVariantConfig(localToolConfig.BuildVariantsDict)
        generator = self.ToolAppContext.PluginConfigContext.GetGeneratorPluginById(localToolConfig.PlatformName, localToolConfig.Generator,
                                                                                   buildVariantConfig, config.ToolConfig.DefaultPackageLanguage,
                                                                                   config.ToolConfig.CMakeConfiguration,
                                                                                   localToolConfig.GetUserCMakeConfig(), False)

        theFiles = MainFlow.DoGetFiles(config, toolConfig.GetMinimalConfig(generator.CMakeConfig), currentDirPath, localToolConfig.Recursive)
        generatorContext = GeneratorContext(config, self.ErrorHelpManager, packageFilters.RecipeFilterManager, config.ToolConfig.Experimental, generator)
        packages = MainFlow.DoGetPackages(generatorContext, config, theFiles, packageFilters, autoAddRecipeExternals=False)

        topLevelPackage = PackageListUtil.GetTopLevelPackage(packages)
        requestedFiles = None if config.IsSDKBuild else theFiles

        if localToolConfig.SaveJson is not None:
            if localToolConfig.BuildPackageFilters.ExtensionNameList is None:
                raise Exception("Invalid config missing ExtensionNameList filters")
            config.LogPrint("Saving to json file '{0}'".format(localToolConfig.SaveJson))


            generatorConfig = GeneratorConfig(generator.PlatformName, config.SDKConfigTemplatePath, config.ToolConfig, 1, CommandType.Build)
            InfoSaver.SavePackageMetaDataToJson(generatorContext,
                                                generatorConfig,
                                                localToolConfig.SaveJson,
                                                config,
                                                topLevelPackage,
                                                localToolConfig.PackageTypeList,
                                                localToolConfig.IncludeGeneratorReport)

        if localToolConfig.ListFeatures:
            Builder.ShowFeatureList(self.Log, topLevelPackage, requestedFiles)
        if localToolConfig.ListVariants:
            requestedFiles = None if config.IsSDKBuild else theFiles
            Builder.ShowVariantList(self.Log, topLevelPackage, requestedFiles, generator)
        if localToolConfig.ListBuildVariants:
            Builder.ShowBuildVariantList(self.Log, generator)
        if localToolConfig.ListExtensions:
            Builder.ShowExtensionList(self.Log, topLevelPackage, requestedFiles)
        if localToolConfig.ListRequirements:
            Builder.ShowRequirementList(self.Log, topLevelPackage, requestedFiles)
        if localToolConfig.ListRecipes:
            RecipeInfo.ShowRecipeList(self.Log, topLevelPackage, requestedFiles)
        if localToolConfig.Stats:
            self.__ShowStats(topLevelPackage)
 def __DoShowList(
         self, packages: List[Package], requestedFiles: Optional[List[str]],
         listVariants: bool, listBuildVariants: bool,
         platformGeneratorPlugin: GeneratorPlugin.GeneratorPlugin) -> None:
     if listVariants:
         topLevelPackage = PackageListUtil.GetTopLevelPackage(packages)
         Builder.ShowVariantList(self.Log, topLevelPackage, requestedFiles,
                                 platformGeneratorPlugin)
     if listBuildVariants:
         Builder.ShowBuildVariantList(self.Log, platformGeneratorPlugin)
    def Filter(log: Log, topLevelPackage: Package,
               requestedPackages: Optional[List[Package]],
               packageFilters: PackageFilters) -> List[Package]:
        """ Filter the package list based
            - Required packages by the requested packages (if requestedPackages isnt None)
            - If there is executeables then chose those that implement the required features in requiredFeatureNameList
            - the available features from featureNameList
            - the available extensions from extensionNameList
            - if they are supported on the platform
        """
        resolvedBuildOrder = topLevelPackage.ResolvedBuildOrder
        requirements = RequirementFilter.GetRequirementList(
            topLevelPackage, None)
        requirementTree = RequirementTree(requirements)

        # Smart expand the input lists
        # - First we add all parent features automatically to ensure the feature list is complete
        useStrictFeatureWarning = requestedPackages is None or len(
            requestedPackages) <= 0
        featureNameList2 = PackageFilter.__AddParentFeatures(
            log, packageFilters.FeatureNameList, requirementTree,
            useStrictFeatureWarning)
        extensionNameList = packageFilters.ExtensionNameList
        if not packageFilters.ExtensionNameList.AllowAllExtensions:
            # Filter extensions by available features
            extensionNameList = PackageFilter.__FilterExtensionsByAvailableFeatures(
                log, featureNameList2, extensionNameList)
            requirementTree.SetExtensionSupport(log, extensionNameList)

        # Try to determine what the user is interested in building
        requestedPackagesInOrder = PackageFilter.__DetermineActualUserBuildRequest(
            resolvedBuildOrder, requestedPackages)

        # Remove recipe packages
        requestedPackagesInOrder = PackageFilter.__FiltersRecipePackages(
            log, requestedPackagesInOrder)

        # Remove packages based on the users required features request
        requestedPackagesInOrder = PackageFilter.__FiltersPackagesByRequiredFeature(
            log, requestedPackagesInOrder,
            packageFilters.RequiredFeatureNameList)
        # Remove packages based on the available features (remove all packages that can't be build due to missing features)
        requestedPackagesInOrder = PackageFilter.__FiltersPackagesByFeatures(
            log, requestedPackagesInOrder, featureNameList2)
        # Remove packages based on the available extensions (remove all packages that can't be build due missing extensions)
        requestedPackagesInOrder = PackageFilter.__FiltersPackagesByExtensions(
            log, requestedPackagesInOrder, extensionNameList, featureNameList2,
            requirementTree)
        # Remove packages that are not supported on this platform
        requestedPackagesInOrder = PackageFilter.__FiltersPackagesBySupported(
            log, requestedPackagesInOrder)
        # Now that we have a filtered list of desired packages, extend it to include all required packages
        return PackageListUtil.GetRequiredPackagesInSourcePackageListOrder(
            requestedPackagesInOrder, resolvedBuildOrder)
    def FilterNotSupported(log: Log,
                           topLevelPackage: Package,
                           requestedPackages: Optional[List[Package]]) -> List[Package]:
        """ Filter the package list based
            - if they are supported on the platform
        """
        resolvedBuildOrder = topLevelPackage.ResolvedBuildOrder

        # Try to determine what the user is interested in building
        requestedPackagesInOrder = PackageFilter.__DetermineActualUserBuildRequest(resolvedBuildOrder, requestedPackages)

        # remove all the unsupported packages
        requestedPackagesInOrder = PackageFilter.__FiltersPackagesBySupported(log, requestedPackagesInOrder)
        # Now that we have a filtered list of desired packages, extend it to include all required packages
        return PackageListUtil.GetRequiredPackagesInSourcePackageListOrder(requestedPackagesInOrder, resolvedBuildOrder)
    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)
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)
Exemple #12
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 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))
Exemple #14
0
    def Process(self, currentDirPath: str, toolConfig: ToolConfig, localToolConfig: LocalToolConfig) -> None:
        config = Config(self.Log, toolConfig, localToolConfig.PackageConfigurationType,
                        localToolConfig.BuildVariantsDict, localToolConfig.AllowDevelopmentPlugins)

        # Disable downloads and writes
        if config.ToolConfig.Experimental is not None:
            config.ToolConfig.Experimental.AllowDownloads = False
        config.ForceDisableAllWrite()
        if localToolConfig.IgnoreNotSupported:
            config.IgnoreNotSupported = True

        self.Log.PrintTitle()

        if not localToolConfig.ForceYes and not self.__AskYesNo("Delete all build directories"):
            return

        packageFilters = localToolConfig.BuildPackageFilters

        generator = PluginConfig.GetGeneratorPluginById(localToolConfig.PlatformName, False)

        theFiles = MainFlow.DoGetFiles(config, toolConfig.GetMinimalConfig(), currentDirPath, localToolConfig.Recursive)
        generatorContext = GeneratorContext(config, config.ToolConfig.Experimental, generator)
        packages = MainFlow.DoGetPackages(generatorContext, config, theFiles, packageFilters, autoAddRecipeExternals=False)

        topLevelPackage = PackageListUtil.GetTopLevelPackage(packages)
        requestedFiles = None if config.IsSDKBuild else theFiles

        self.Log.LogPrint("Deleting package build directories")
        for package in topLevelPackage.ResolvedBuildOrder:
            if package.AbsoluteBuildPath is not None:
                # While the path is most likely normalized we force it here
                removePath = IOUtil.NormalizePath(package.AbsoluteBuildPath)
                if IOUtil.IsDirectory(removePath):
                    self.Log.LogPrint("- Deleting '{0}'".format(removePath))
                    drive, tail = os.path.splitdrive(removePath)
                    driveId = IOUtil.NormalizePath(drive).lower()
                    removePathId = removePath.lower()
                    # some basic checks to prevent deletes of '/' or a drive letter.
                    if  ('../' in removePath or '/..' in removePath or removePath == '/' or removePath == '..' or
                         len(removePath) <= 0 or removePathId==driveId or removePath.endswith('/')):
                        raise Exception("Invalid path format '{0}'".format(removePath))
                    IOUtil.SafeRemoveDirectoryTree(removePath)
Exemple #15
0
    def Process(self, currentDirPath: str, toolConfig: ToolConfig, localToolConfig: LocalToolConfig) -> None:
        config = Config(self.Log, toolConfig, localToolConfig.PackageConfigurationType,
                        localToolConfig.BuildVariantsDict, localToolConfig.AllowDevelopmentPlugins)

        # Disable downloads and writes
        if config.ToolConfig.Experimental is not None:
            config.ToolConfig.Experimental.AllowDownloads = False
        config.ForceDisableAllWrite()
        if localToolConfig.IgnoreNotSupported:
            config.IgnoreNotSupported = True

        self.Log.PrintTitle()

        if not localToolConfig.ForceYes and not self.__AskYesNo("Delete all build directories"):
            return

        packageFilters = localToolConfig.BuildPackageFilters

        buildVariantConfig = BuildVariantConfigUtil.GetBuildVariantConfig(localToolConfig.BuildVariantsDict)
        generator = self.ToolAppContext.PluginConfigContext.GetGeneratorPluginById(localToolConfig.PlatformName, localToolConfig.Generator,
                                                                                   buildVariantConfig, config.ToolConfig.DefaultPackageLanguage,
                                                                                   config.ToolConfig.CMakeConfiguration,
                                                                                   localToolConfig.GetUserCMakeConfig(), False)

        theFiles = MainFlow.DoGetFiles(config, toolConfig.GetMinimalConfig(generator.CMakeConfig), currentDirPath, localToolConfig.Recursive)
        generatorContext = GeneratorContext(config, self.ErrorHelpManager, packageFilters.RecipeFilterManager, config.ToolConfig.Experimental, generator)
        packages = MainFlow.DoGetPackages(generatorContext, config, theFiles, packageFilters, autoAddRecipeExternals=False)

        topLevelPackage = PackageListUtil.GetTopLevelPackage(packages)
        #requestedFiles = None if config.IsSDKBuild else theFiles

        self.Log.LogPrint("Deleting package build directories")
        for package in topLevelPackage.ResolvedBuildOrder:
            if package.AbsoluteBuildPath is not None:
                # While the path is most likely normalized we force it here
                removePath = IOUtil.NormalizePath(package.AbsoluteBuildPath)
                if IOUtil.IsDirectory(removePath):
                    self.Log.LogPrint("- Deleting '{0}'".format(removePath))
                    if IOUtil.IsDriveRootPath(removePath):
                        raise Exception("Invalid path format '{0}'".format(removePath))
                    IOUtil.SafeRemoveDirectoryTree(removePath)
Exemple #16
0
    def TryCreateJsonBuildInfoRootDict(log: Log, cacheFilename: str, sourcePackage: Package, sourceRecipe: PackageExperimentalRecipe,
                                       recipePackageStateCache: RecipePackageStateCache,
                                       cachedContentState: Optional[JsonRecipePackageContentState] = None,
                                       cachedSourceState: Optional[JsonRecipePackageContentState] = None) -> Optional[JsonDictType]:
        try:
            if sourcePackage is None or sourceRecipe is None or sourceRecipe.ResolvedInstallPath is None:
                return None

            localSourceState = None
            if sourceRecipe.IsLocalSourceBuild and sourcePackage.AbsolutePath is not None:
                localSourceState = RecipePackageState(log, sourcePackage.Name, sourcePackage.AbsolutePath,
                                                      "fsl-cached-state", sourcePackage.SourceFileHash, cachedSourceState)


            # Generate the package state
            recipePackageState = RecipePackageState(log, sourcePackage.Name, sourceRecipe.ResolvedInstallPath,
                                                    cacheFilename, sourcePackage.SourceFileHash, cachedContentState)
            recipePackageStateCache.Set(recipePackageState)

            referencedPackageSet = PackageListUtil.BuildReferencedPackageSet([sourcePackage])
            referencedPackageSet.remove(sourcePackage)
            referencedPackageNameList = BuildInfoFile.CreateReferencedPackageNameList(referencedPackageSet, recipePackageStateCache)
            referencedPackageNameList.sort()

            recipeHash = sourcePackage.SourceFileHash

            jsonRootDict = {}  # type: JsonDictType
            jsonRootDict[BuildInfoFileElements.PackageName] = sourcePackage.Name
            jsonRootDict[BuildInfoFileElements.PackageDependencies] = referencedPackageNameList
            jsonRootDict[BuildInfoFileElements.FileFormatVersion] = BuildInfoFileElements.CURRENT_VERSION
            jsonRootDict[BuildInfoFileElements.RecipeHash] = recipeHash
            jsonRootDict[BuildInfoFileElements.ContentState] = recipePackageState.ContentState
            jsonRootDict[BuildInfoFileElements.ContentStateHash] = recipePackageState.ContentStateHash
            if localSourceState is not None:
                jsonRootDict[BuildInfoFileElements.SourceState] = localSourceState.ContentState
                jsonRootDict[BuildInfoFileElements.SourceStateHash] = localSourceState.ContentStateHash
            return jsonRootDict
        except Exception as ex:
            log.LogPrintWarning("TryCreateJsonBuildInfoRootDict failed {0}".format(ex))
            return None
    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)
Exemple #18
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)