def __init__(self, basicConfig: BasicConfig,
                 recipeFilterManager: RecipeFilterManager,
                 experimental: Optional[ToolConfigExperimental],
                 generator: GeneratorPlugin) -> None:
        cmakeGenerator = CMakeTypes.TryDetermineCMakeGenerator(generator)
        cmakeGeneratorShortName = None
        if cmakeGenerator is not None:
            cmakeGeneratorShortName = CMakeTypes.TryGetCompilerShortIdFromGeneratorName(
                cmakeGenerator)

        shortCompilerName = "NotDefined" if cmakeGeneratorShortName is None else cmakeGeneratorShortName
        if cmakeGeneratorShortName is None:
            if basicConfig.Verbosity >= 2:
                basicConfig.LogPrintWarning(
                    "No CMake short generator id has been defined, defaulting to '{0}'"
                    .format(shortCompilerName))

        recipeBuilderSetup = None
        allowDownloads = False
        if experimental is not None:
            targetLocation = ResolvedPath(
                experimental.DefaultThirdPartyInstallDirectory.DynamicName,
                experimental.DefaultThirdPartyInstallDirectory.ResolvedPath)
            installReadonlySource = experimental.DefaultThirdPartyInstallReadonlyCacheDirectory
            readonlyCachePath = None if installReadonlySource is None else installReadonlySource.ResolvedPath  # type: Optional[str]
            recipeBuilderSetup = RecipeBuilderSetup(targetLocation,
                                                    readonlyCachePath)
            if IOUtil.TryGetEnvironmentVariable(
                    experimental.DisableDownloadEnv) != None:
                allowDownloads = False
                basicConfig.LogPrint(
                    "Downloads disabled since the environment variable {0} was defined"
                    .format(experimental.DisableDownloadEnv))
            elif experimental.AllowDownloads:
                allowDownloads = True
            else:
                basicConfig.LogPrint(
                    "Downloads disabled since the project has it disabled by default"
                )

        super().__init__(basicConfig, generator.PlatformName,
                         generator.PlatformName, shortCompilerName,
                         recipeBuilderSetup)

        #allowDownload=True, disableDownloadEnv=None

        self.BasicConfig = basicConfig
        self.Generator = generator
        # for now the generator is also the platform and the existing code use that name so maintain compatibility for now
        self.Platform = generator
        self.AllowDownloads = allowDownloads
        self.RecipeFilterManager = recipeFilterManager
    def _GenerateConfigReport(
            log: Log, toolConfig: ToolConfig, generatorName: str,
            platformName: str, cmakeConfig: GeneratorCMakeConfig,
            topLevelPackage: Package) -> GeneratorConfigReport:
        if topLevelPackage.Type != PackageType.TopLevel:
            raise Exception("Package is not a top level package")

        # Top level package handling
        buildCommandArguments = []  # type: List[str]

        if cmakeConfig.InstallPrefix is not None:
            buildCommandArguments.append("-DCMAKE_INSTALL_PREFIX={0}".format(
                cmakeConfig.InstallPrefix))

        # Configuration (Debug, Release) for the configurations that support configure time configuration
        if CMakeTypes.GetGeneratorMultiConfigCapabilities(
                cmakeConfig.GeneratorName
        ) != CMakeTypes.CMakeGeneratorMultiConfigCapability.Yes:
            buildCommandArguments.append("-DCMAKE_BUILD_TYPE=${{{0}}}".format(
                LocalMagicBuildVariants.CMakeBuildConfig))

        # Normal variants
        for normalVariant in topLevelPackage.ResolvedNormalVariantNameList:
            buildCommandArguments.append(
                "-D{0}=${{{0}}}".format(normalVariant))

        # Set the generator name
        buildCommandArguments.append("-G")
        buildCommandArguments.append(cmakeConfig.GeneratorName)

        # Add additional arguments
        additionalGeneratorArguments = CMakeTypes.DetermineGeneratorArguments(
            cmakeConfig.GeneratorName, platformName)
        if len(additionalGeneratorArguments) > 0:
            buildCommandArguments += additionalGeneratorArguments

        # Add the path to the root cmake file
        topToolProjectContext = toolConfig.ProjectInfo.TopProjectContext
        projectAbsolutePath = topToolProjectContext.Location.ResolvedPath
        buildCommandArguments.append(projectAbsolutePath)

        # Set the build dir
        configCWD = cmakeConfig.BuildDir

        # FIX: See how the visual studio generator handles debug/release builds

        configCommand = "cmake"
        configCommandReport = GeneratorConfigCommandReport(
            configCommand, buildCommandArguments, configCWD)

        return GeneratorConfigReport(configCommandReport)
Beispiel #3
0
 def __ConfigureForPlatform(self, generatorContext: GeneratorContext,
                            buildThreads: int) -> None:
     self.CMakeCommand = CMakeTypes.DetermineCMakeCommand(
         generatorContext.Platform.Name)
     self.CMakeGeneratorName = CMakeTypes.DetermineCMakeGenerator(
         generatorContext.Platform)
     self.CompilerShortId = CMakeTypes.GetCompilerShortIdFromGeneratorName(
         self.CMakeGeneratorName)
     self.CMakeArguments = CMakeTypes.DeterminePlatformArguments(
         generatorContext.Platform.Name)
     self.Builder = self.__DetermineBuilder(self.CMakeGeneratorName,
                                            generatorContext, buildThreads)
     self.CMakeFinalGeneratorName = CMakeTypes.DetermineFinalCMakeGenerator(
         self.CMakeGeneratorName)
    def __init__(self, generatorContext: GeneratorContext, buildThreads: int) -> None:
        super().__init__(generatorContext, buildThreads, PlatformBuildTypeInfo.CMake)

        cmakeConfig = generatorContext.CMakeConfig
        if cmakeConfig.CMakeVersion < CMakeBuilderGeneric.MINIMUM_VERSION:
            raise Exception("The chosen CMake generator '{0}' requires cmake version {1} or newer".format(cmakeConfig.CMakeFinalGeneratorName, CMakeBuilderGeneric.MINIMUM_VERSION))

        # The cmake make files only support one configuration
        self.IsSingleConfiguration = (CMakeTypes.GetGeneratorMultiConfigCapabilities(cmakeConfig.CMakeFinalGeneratorName) != CMakeTypes.CMakeGeneratorMultiConfigCapability.Yes)
Beispiel #5
0
def BuildGeneratorCMakeConfig(
        platformName: str, userCMakeConfig: Optional[UserCMakeConfig],
        cmakeConfiguration: CMakeConfiguration,
        defaultCompilerVersion: int) -> GeneratorCMakeConfig:
    """
    Build the CMake config based on the supplied parameters and the default settings from the toolconfig
    """

    # Setup default configuration
    buildDir = cmakeConfiguration.DefaultBuildDir
    generatorName = ""
    installPrefix = cmakeConfiguration.DefaultInstallPrefix

    # Give the platform a chance to override the config
    platformConfig = cmakeConfiguration.TryGetPlatformConfig(platformName)
    if platformConfig is not None:
        if platformConfig.DefaultGeneratorName is not None:
            generatorName = platformConfig.DefaultGeneratorName
        if platformConfig.DefaultInstallPrefix is not None:
            installPrefix = platformConfig.DefaultInstallPrefix

    # Apply the commandline overrides (so the user gets the final say)
    if userCMakeConfig is not None:
        if userCMakeConfig.BuildDir is not None:
            buildDir = userCMakeConfig.BuildDir
        if userCMakeConfig.GeneratorName is not None:
            generatorName = userCMakeConfig.GeneratorName
        if userCMakeConfig.InstallPrefix is not None:
            installPrefix = userCMakeConfig.InstallPrefix

    # If we still dont have a generator name then try to select a good default
    if len(generatorName) <= 0:
        # Try to determine the default generator name for the platform
        generatorName = CMakeTypes.GetPlatformDefaultCMakeGenerator(
            platformName, defaultCompilerVersion)

    cmakeVersion = CMakeUtil.GetVersion()

    return GeneratorCMakeConfig(buildDir, generatorName, installPrefix,
                                cmakeVersion)
    def _TryGenerateBuildReport(
            log: Log, generatorConfig: GeneratorConfig, generatorName: str,
            cmakeConfig: GeneratorCMakeConfig, package: Package,
            isMasterBuild: bool) -> Optional[GeneratorBuildReport]:
        if package.IsVirtual and not isMasterBuild:
            return None

        # preBuildCommand = ['cmake', '-G', 'Visual Studio 15 2017 Win64'] + buildConfig.BuildArgs
        # buildCommand = ['cmake', '--build', '.', '--config', 'Debug'] + buildConfig.BuildArgs

        buildCommandArguments = ['--build', '.']  # type: List[str]
        buildCommandNativeArguments = []  # type: List[str]

        # Configuration (Debug, Release) for the configurations that support build time configuration switching
        if CMakeTypes.GetGeneratorMultiConfigCapabilities(
                cmakeConfig.GeneratorName
        ) != CMakeTypes.CMakeGeneratorMultiConfigCapability.No:
            buildCommandArguments.append("--config")
            buildCommandArguments.append("${{{0}}}".format(
                LocalMagicBuildVariants.CMakeBuildConfig))

        # Do a fallback solution for a few generators that we know how work
        nativeArguments = CMakeTypes.GetNativeBuildThreadArguments(
            cmakeConfig.GeneratorName, generatorConfig.NumBuildThreads)
        if len(nativeArguments) > 0:
            buildCommandNativeArguments += nativeArguments
        elif cmakeConfig.CMakeVersion.Major >= 3 and cmakeConfig.CMakeVersion.Minor >= 12:
            # Take advantage of the "--parallel" parameter available from 3.12 when possible
            # We use this as a fallback since testing has shown that even on 3.14 the parameter
            # doesn't always provide any benefits :(
            buildCommandArguments.append("--parallel")
            buildCommandArguments.append("{0}".format(
                generatorConfig.NumBuildThreads))
        elif isMasterBuild:
            log.LogPrintWarning(
                "BuildThreads not supported for generator '{0}' please upgrade to CMake 3.12+"
                .format(cmakeConfig.GeneratorName))

        # Add extra commands based on the build type
        if generatorConfig.BuildCommand == CommandType.Clean:
            buildCommandArguments.append("--target")
            buildCommandArguments.append("clean")
        elif generatorConfig.BuildCommand == CommandType.Install:
            buildCommandArguments.append("--target")
            buildCommandArguments.append("install")

        # set the package build dir
        buildCWD = cmakeConfig.BuildDir
        if not isMasterBuild:
            buildCWD = GeneratorCMake._GetPackageBuildDir(
                generatorConfig, cmakeConfig, package)

        buildCommand = "cmake"
        buildCommandReport = GeneratorCommandReport(
            True,
            buildCommand,
            buildCommandArguments,
            buildCommandNativeArguments,
            buildCWD,
            nativeArgumentSeparator="--")
        return GeneratorBuildReport(buildCommandReport)
    def __init__(self, toolVersion: Version, platformName: str,
                 buildVariantConfig: BuildVariantConfig, buildDir: str,
                 buildDirSetByUser: bool, checkDir: str, generatorName: str,
                 installPrefix: Optional[str], cmakeVersion: CMakeVersion,
                 additionalGlobalConfigArguments: List[str],
                 additionalAppConfigArguments: List[str],
                 allowFindPackage: bool) -> None:
        super().__init__()

        PathUtil.ValidateIsNormalizedPath(buildDir, "BuildDir")
        if installPrefix is not None:
            PathUtil.ValidateIsNormalizedPath(installPrefix,
                                              "DefaultInstallPrefix")

        finalGeneratorName = CMakeTypes.DetermineFinalCMakeGenerator(
            generatorName)
        # its important that we use the  generatorName for the GetCompilerShortIdFromGeneratorName to get the proper android name
        generatorShortName = CMakeTypes.GetCompilerShortIdFromGeneratorName(
            generatorName)

        # Check if we should use a 'build variant temp dir'
        if not buildDirSetByUser:
            buildDir = IOUtil.Join(buildDir, generatorShortName)
            if CMakeTypes.GetGeneratorMultiConfigCapabilities(
                    finalGeneratorName
            ) == CMakeTypes.CMakeGeneratorMultiConfigCapability.No:
                buildDir = IOUtil.Join(
                    buildDir, BuildVariantConfig.ToString(buildVariantConfig))

        self.BuildDir = buildDir
        # If this is true the user specified the directory
        self.BuildDirSetByUser = buildDirSetByUser
        self.CheckDir = checkDir

        # the active build variant
        self.BuildVariantConfig = buildVariantConfig
        self.GeneratorName = generatorName
        self.InstallPrefix = installPrefix
        self.CMakeVersion = cmakeVersion

        self.CMakeCommand = CMakeTypes.DetermineCMakeCommand(platformName)
        # The tool arguments
        self.CMakeInternalArguments = CMakeTypes.DetermineGeneratorArguments(
            finalGeneratorName, platformName)

        # This contains only the user arguments for both recipe and apps
        self.CMakeConfigUserGlobalArguments = additionalGlobalConfigArguments
        self.CMakeConfigUserAppArguments = additionalAppConfigArguments

        # The combined arguments that should be supplied to cmake
        self.CMakeConfigRecipeArguments = self.CMakeInternalArguments + additionalGlobalConfigArguments

        # The combined arguments that should be supplied to cmake
        self.CMakeConfigAppArguments = self.CMakeInternalArguments + additionalGlobalConfigArguments + additionalAppConfigArguments

        self.CMakeFinalGeneratorName = finalGeneratorName
        self.GeneratorShortName = generatorShortName
        self.GeneratorRecipeShortName = "{0}_{1}".format(
            generatorShortName,
            toolVersion.ToMajorMinorString().replace('.', '_'))
        self.AllowFindPackage = allowFindPackage
def BuildGeneratorCMakeConfig(
        log: Log, toolVersion: Version, platformName: str,
        buildVariantConfig: BuildVariantConfig,
        userCMakeConfig: Optional[UserCMakeConfig],
        cmakeConfiguration: CMakeConfiguration,
        defaultCompilerVersion: int) -> GeneratorCMakeConfig:
    """
    Build the CMake config based on the supplied parameters and the default settings from the toolconfig
    """

    # Setup default configuration
    buildDir = IOUtil.Join(cmakeConfiguration.DefaultBuildDir, platformName)
    checkDir = IOUtil.Join(buildDir, 'fsl')
    generatorName = ""
    installPrefix = cmakeConfiguration.DefaultInstallPrefix

    # Give the platform a chance to override the config
    platformConfig = cmakeConfiguration.TryGetPlatformConfig(platformName)
    allowFindPackage = True
    if platformConfig is not None:
        if platformConfig.DefaultGeneratorName is not None:
            generatorName = platformConfig.DefaultGeneratorName
        if platformConfig.DefaultInstallPrefix is not None:
            installPrefix = platformConfig.DefaultInstallPrefix
        if platformConfig.AllowFindPackage is not None:
            allowFindPackage = platformConfig.AllowFindPackage
            log.LogPrintVerbose(
                2, "project defined AllowFindPackage to {0}".format(
                    allowFindPackage))

    # Apply the commandline overrides (so the user gets the final say)
    buildDirSetByUser = False
    if userCMakeConfig is not None:
        if userCMakeConfig.BuildDir is not None:
            buildDir = userCMakeConfig.BuildDir
            buildDirSetByUser = True
        if userCMakeConfig.GeneratorName is not None:
            generatorName = userCMakeConfig.GeneratorName
        if userCMakeConfig.InstallPrefix is not None:
            installPrefix = userCMakeConfig.InstallPrefix
        if userCMakeConfig.AllowFindPackage is not None:
            allowFindPackage = userCMakeConfig.AllowFindPackage
            log.LogPrintVerbose(
                2, "Command line set AllowFindPackage to {0}".format(
                    allowFindPackage))

    # If we still dont have a generator name then try to select a good default
    if len(generatorName) <= 0:
        # Try to determine the default generator name for the platform
        generatorName = CMakeTypes.GetPlatformDefaultCMakeGenerator(
            platformName, defaultCompilerVersion)

    cmakeVersion = CMakeUtil.GetVersion()

    cmakeConfigGlobalArgs = [] if userCMakeConfig is None else shlex.split(
        userCMakeConfig.ConfigGlobalArgs)
    cmakeConfigAppArgs = [] if userCMakeConfig is None else shlex.split(
        userCMakeConfig.ConfigAppArgs)

    return GeneratorCMakeConfig(toolVersion, platformName, buildVariantConfig,
                                buildDir, buildDirSetByUser, checkDir,
                                generatorName, installPrefix, cmakeVersion,
                                cmakeConfigGlobalArgs, cmakeConfigAppArgs,
                                allowFindPackage)