Beispiel #1
0
    def __GenerateCMakeFile(self, config: Config, package: Package,
                            platformName: str,
                            template: CMakeGeneratorUtil.CodeTemplateCMake,
                            androidProjectDir: str,
                            androidProjectCMakeDir: str) -> None:

        toolConfig = config.ToolConfig

        pathType = CMakeGeneratorUtil.CMakePathType.Relative

        packageName = CMakeGeneratorUtil.GetPackageName(package)

        # this ignore is a workaround allowing us to build using the same info as the old Android builder
        ignoreLibs = ["android_native_app_glue"]

        aliasPackageName = CMakeGeneratorUtil.GetAliasName(
            packageName, package.ProjectContext.ProjectName)
        targetIncludeDirectories = CMakeGeneratorUtil.BuildTargetIncludeDirectories(
            toolConfig, package, template.PackageTargetIncludeDirectories,
            template.PackageTargetIncludeDirEntry,
            template.PackageTargetIncludeDirVirtualEntry, pathType)
        targetIncludeDirectories = targetIncludeDirectories.replace(
            Variable.RecipeVariant, "${ANDROID_ABI}")

        publicIncludeFiles = CMakeGeneratorUtil.ExpandPathAndJoin(
            toolConfig, package, package.ResolvedBuildPublicIncludeFiles)
        privateIncludeFiles = CMakeGeneratorUtil.ExpandPathAndJoin(
            toolConfig, package, package.ResolvedBuildPrivateIncludeFiles)
        includeFiles = CMakeGeneratorUtil.ExpandPathAndJoin(
            toolConfig, package, package.ResolvedBuildAllIncludeFiles)
        sourceFiles = CMakeGeneratorUtil.ExpandPathAndJoin(
            toolConfig, package, package.ResolvedBuildSourceFiles)
        linkLibrariesDirectDependencies = CMakeGeneratorUtil.BuildTargetLinkLibrariesForDirectDependencies(
            config, package, template.PackageDependencyTargetLinkLibraries,
            template.PackageDependencyFindPackage, ignoreLibs)
        linkLibrariesDirectDependencies = linkLibrariesDirectDependencies.replace(
            Variable.RecipeVariant, "${ANDROID_ABI}")
        directDefinitions = CMakeGeneratorUtil.BuildDirectDefinitions(
            config, package,
            template.PackageDependencyTargetCompileDefinitions)
        findDirectExternalDependencies = CMakeGeneratorUtil.BuildFindDirectExternalDependencies(
            config, package, template.PackageDependencyFindPackage)
        installInstructions = CMakeGeneratorUtil.BuildInstallInstructions(
            config, package, template.PackageInstall,
            template.PackageInstallTargets, template.PackageInstallHeaders,
            template.PackageInstallContent, template.PackageInstallDLL,
            template.PackageInstallAppInfo)
        targetCompileFeatures = CMakeGeneratorUtil.BuildCompileFeatures(
            config, package, template.SnippetTargetCompileFeaturesDefault,
            template.SnippetTargetCompileFeaturesInterface)
        targetCompileOptions = CMakeGeneratorUtil.BuildCompileOptions(
            config, package, template.SnippetTargetCompileOptionsDefault)

        buildCMakeFile = template.Master

        if package.Type == PackageType.Executable:
            if package.ContentPath is None or package.AbsolutePath is None:
                raise Exception("Invalid package")
            packagePath = CMakeGeneratorUtil.GetSDKBasedPathUsingCMakeVariable(
                toolConfig, package.AbsolutePath)
            packageContentPath = CMakeGeneratorUtil.GetSDKBasedPathUsingCMakeVariable(
                toolConfig, package.ContentPath.AbsoluteDirPath)
            buildCMakeFile = buildCMakeFile.replace("##PACKAGE_PATH##",
                                                    packagePath)
            buildCMakeFile = buildCMakeFile.replace("##PACKAGE_CONTENT_PATH##",
                                                    packageContentPath)
            buildCMakeFile = buildCMakeFile.replace(
                "##PACKAGE_ANDROID_PROJECT_PATH##", androidProjectDir)
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_INCLUDE_FILES##",
                                                includeFiles)
        buildCMakeFile = buildCMakeFile.replace(
            "##PACKAGE_PUBLIC_INCLUDE_FILES##", publicIncludeFiles)
        buildCMakeFile = buildCMakeFile.replace(
            "##PACKAGE_PRIVATE_INCLUDE_FILES##", privateIncludeFiles)
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_SOURCE_FILES##",
                                                sourceFiles)
        buildCMakeFile = buildCMakeFile.replace(
            "##TARGET_INCLUDE_DIRECTORIES##", targetIncludeDirectories)
        buildCMakeFile = buildCMakeFile.replace(
            "##PACKAGE_DIRECT_DEPENDENCIES_TARGET_LINK_LIBRARIES##",
            linkLibrariesDirectDependencies)
        buildCMakeFile = buildCMakeFile.replace(
            "##PACKAGE_DIRECT_DEPENDENCIES_TARGET_COMPILE_DEFINITIONS##",
            directDefinitions)
        buildCMakeFile = buildCMakeFile.replace(
            "##PACKAGES_FIND_DIRECT_EXTERNAL_DEPENDENCIES##",
            findDirectExternalDependencies)
        buildCMakeFile = buildCMakeFile.replace(
            "##SNIPPET_DEFAULT_TARGET_COMPILE_OPTIONS##", targetCompileOptions)
        buildCMakeFile = buildCMakeFile.replace(
            "##SNIPPET_DEFAULT_TARGET_COMPILE_FEATURES##",
            template.SnippetTargetCompileFeaturesDefault)
        buildCMakeFile = buildCMakeFile.replace(
            "##PACKAGE_GENERATE_INSTALL_INSTRUCTIONS##", installInstructions)
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_NAME!##",
                                                packageName.upper())
        buildCMakeFile = buildCMakeFile.replace("##PACKAGE_NAME##",
                                                packageName)
        buildCMakeFile = buildCMakeFile.replace("##ALIAS_PACKAGE_NAME##",
                                                aliasPackageName)
        buildCMakeFile = buildCMakeFile.replace(
            "##PROJECT_NAME##", package.ProjectContext.ProjectName)
        buildCMakeFile = buildCMakeFile.replace(
            "##PROJECT_VERSION##", package.ProjectContext.ProjectVersion)

        if not config.DisableWrite:
            # We store all cmake build files in their own dir inside the 'android' exe-project's folder
            # to prevent collision with other more generic CMake builders
            packageCMakeDir = self.__GetPackageCMakeDir(
                androidProjectCMakeDir, package)
            IOUtil.SafeMakeDirs(packageCMakeDir)
            dstFileCMakeFile = self.__GetPackageCMakeFileName(
                androidProjectCMakeDir, package)
            IOUtil.WriteFileIfChanged(dstFileCMakeFile, buildCMakeFile)
    def __RunToolMainForSanityCheck(self, currentDir: str,
                                    toolConfig: ToolConfig,
                                    localToolConfig: LocalToolConfig,
                                    templateDict: Dict[
                                        str, List[XmlNewTemplateFile]],
                                    debugMode: bool,
                                    templateList: List[str]) -> None:

        currentDir = IOUtil.Join(currentDir, GlobalStrings.SanityCheckDir)
        IOUtil.SafeMakeDirs(currentDir)
        if not IOUtil.IsDirectory(currentDir):
            raise Exception(
                "could not create work directory: '{0}'".format(currentDir))

        isBuilding = False
        try:
            for currentTemplateName in templateList:
                if currentTemplateName == '*' or currentTemplateName.startswith(
                        '/') or '..' in currentTemplateName:
                    raise Exception("Usage error")

                localToolConfig.Template = currentTemplateName

                localToolConfig.ProjectName = "{0}_{1}".format(
                    GlobalStrings.SanityCheckProjectName,
                    localToolConfig.Template)
                localToolConfig.Force = True

                if debugMode:
                    generatedDir = IOUtil.Join(currentDir,
                                               localToolConfig.ProjectName)
                    if IOUtil.IsDirectory(generatedDir):
                        continue

                print(("Generating sanity project for template '{0}' begin".
                       format(localToolConfig.Template)))
                self.__ToolMainEx(currentDir, toolConfig, localToolConfig,
                                  templateDict, False)
                print((
                    "Generating sanity project for template '{0}' ended successfully"
                    .format(localToolConfig.Template)))

            isBuilding = True
            config = Config(self.Log, toolConfig, 'sdk',
                            localToolConfig.BuildVariantsDict,
                            localToolConfig.AllowDevelopmentPlugins)
            print(
                ("Building sanity projects for all template begin {0}".format(
                    localToolConfig.Template)))
            self.__BuildNow(config, currentDir, True)
            print(("Building sanity project for template end {0}".format(
                localToolConfig.Template)))
        except:
            if not isBuilding:
                print("Sanity check of template '{0}' failed".format(
                    localToolConfig.Template))
            else:
                print("Sanity build of templates failed")
            raise
        finally:
            if not debugMode:
                for currentTemplateName in templateList:
                    if currentTemplateName == '*' or currentTemplateName.startswith(
                            '/') or '..' in currentTemplateName:
                        raise Exception("Usage error")
                    projectName = "{0}_{1}".format(
                        GlobalStrings.SanityCheckProjectName,
                        currentTemplateName)

                    projectDir = IOUtil.Join(currentDir, projectName)
                    if IOUtil.IsDirectory(projectDir):
                        shutil.rmtree(projectDir)
Beispiel #3
0
    def __ConfigureBuild(self, report: PackageGeneratorConfigReport,
                         buildConfig: BuildConfigRecord) -> None:
        configReport = report.ConfigReport.ConfigCommandReport
        variableReport = report.VariableReport

        buildArgumentList = []
        for buildArgument in configReport.Arguments:
            buildArgument = ReportVariableFormatter.Format(
                buildArgument, variableReport, buildConfig.VariantSettingsDict)
            buildArgumentList.append(buildArgument)

        configCommandStr = ReportVariableFormatter.Format(
            configReport.CommandFormatString, variableReport,
            buildConfig.VariantSettingsDict)

        currentWorkingDirectory = ReportVariableFormatter.Format(
            configReport.CurrentWorkingDirectoryFormatString, variableReport,
            buildConfig.VariantSettingsDict)

        configCommand = [configCommandStr
                         ] + buildArgumentList  # + buildConfig.BuildConfigArgs
        #if len(buildContext.Platform.AdditionalBuildConfigArguments) > 0:
        #    buildCommand += buildContext.Platform.AdditionalBuildConfigArguments

        try:
            IOUtil.SafeMakeDirs(currentWorkingDirectory)

            cacheFilename = IOUtil.Join(currentWorkingDirectory,
                                        '.FslConfigureCache.json')

            dirtyBuildConfigureCache = self.__CheckBuildConfigureModifications(
                cacheFilename, report.GeneratedFileSet, configCommand,
                buildConfig.PlatformName)
            if dirtyBuildConfigureCache is None:
                self.Log.LogPrint(
                    "Build configuration not modified, skipping configure")
                return
            self.Log.LogPrint("Build configuration modifed, running configure")

            if self.Log.Verbosity >= 1:
                self.Log.LogPrint(
                    "Running build config command '{0}' in '{1}'".format(
                        self.__SafeJoinCommandArguments(configCommand),
                        currentWorkingDirectory))

            result = subprocess.call(configCommand,
                                     cwd=currentWorkingDirectory)
            if result != 0:
                self.Log.LogPrintWarning(
                    "The build config command '{0}' failed with '{1}'. It was run with CWD: '{2}'"
                    .format(self.__SafeJoinCommandArguments(configCommand),
                            result, currentWorkingDirectory))
                sys.exit(result)
            else:
                BuildConfigureCache.Save(self.Log, cacheFilename,
                                         dirtyBuildConfigureCache)
        except FileNotFoundError:
            self.Log.DoPrintWarning(
                "The build config command '{0}' failed with 'file not found'. It was run with CWD: '{1}'"
                .format(self.__SafeJoinCommandArguments(configCommand),
                        currentWorkingDirectory))
            raise
Beispiel #4
0
 def EnsureDirectoryExist(self, config: Config,
                          outputFileName: str) -> None:
     outputDirectory = IOUtil.GetDirectoryName(outputFileName)
     if not config.DisableWrite:
         IOUtil.SafeMakeDirs(outputDirectory)
    def __GenerateFolderStructure(self, config: Config, package: Package) -> None:
        #don't generate anything for unsuported packages
        if package.ResolvedPlatformNotSupported:
            return
        if (package.AbsolutePath is None or package.ResolvedBuildPath is None or
            package.ResolvedBuildAllIncludeDirs is None or
            package.ResolvedBuildSourceFiles is None or package.ShortName is None):
           raise Exception("Invalid package")

        # Use a standard build path
        buildBasePath = IOUtil.Join(package.AbsolutePath, package.ResolvedBuildPath)
        newDir = "arm"
        relativePathBuildArm = IOUtil.Join(package.ResolvedBuildPath, newDir)
        buildArmPath = IOUtil.Join(buildBasePath, newDir)
        buildPath = buildBasePath
        #relativePathBuild = ""

        newDir = "a-le-v7"
        relativePathBuildLib = IOUtil.Join(relativePathBuildArm, newDir)
        buildPathLib = IOUtil.Join(buildArmPath, newDir)

        #check package type and prepare folder name
        if package.Type == PackageType.Library:
            relativePathBuild = relativePathBuildLib
            buildPath = buildPathLib
        elif package.Type == PackageType.Executable:
            newDir = "o-le-v7"
            relativePathBuild = IOUtil.Join(relativePathBuildArm, newDir)
            buildPath = IOUtil.Join(buildArmPath, newDir)
        else:
            raise InternalErrorException("Unknown package type: {0}".format(package.Name))

        if not config.DisableWrite:
            # create folder structure
            IOUtil.SafeMakeDirs(buildPath)

            #copy make files that are not modified
            IOUtil.CopySmallFile(IOUtil.Join(config.SDKConfigTemplatePath, ".qnx_internal.mk"), IOUtil.Join(buildBasePath, ".qnx_internal.mk"))

            dstFile = IOUtil.Join(buildBasePath, "Makefile")
            content = self.TemplateMakefileCPU
            IOUtil.WriteFileIfChanged(dstFile, content)

            dstFile = IOUtil.Join(buildArmPath, "Makefile")
            content = self.TemplateMakefileVariant
            IOUtil.WriteFileIfChanged(dstFile, content)

            dstFile = IOUtil.Join(buildPath, "Makefile")
            content = self.TemplateMakefileTop
            IOUtil.WriteFileIfChanged(dstFile, content)

        #create common.mk with package-specific content
        dstFile = IOUtil.Join(buildBasePath, "common.mk")
        content = self.TemplateCommonMk

        #add "$(project_root)/" to local includes like "include", keep others as they are ("$(FSL_GRAPHICS_SDK)/a/b/")
        updatedIncludedirs = []
        for includeDir in package.ResolvedBuildAllIncludeDirs:
            if not os.path.dirname(includeDir):
                updatedIncludedirs.append("$(project_root)/" + includeDir)
            else:
                updatedIncludedirs.append(includeDir)
        includes = self.__FormatListToString("EXTRA_INCVPATH += ", updatedIncludedirs)
        content = content.replace("##EXTRA_INCVPATHS##", includes)

        srcDirsList = self.__ExtractUniqueDirectoriesFromList(package.ResolvedBuildSourceFiles)
        srcDirs = self.__FormatListToString("EXTRA_SRCVPATH += $(project_root)/", srcDirsList)
        content = content.replace("##EXTRA_SRCVPATHS##", srcDirs)

        # QNX takes all sources in folder, just like this generator, so there is no need to
        # list all files in makefile.
        #sourceObjs = []
        #for sourceFile in package.ResolvedBuildSourceFiles:
        #    sourceObjs.append(os.path.splitext(sourceFile)[0] + ".o")
        #sourceObjsString = self.__FormatListToString("SOURCE_OBJECTS += $(project_root)/", sourceObjs)
        #content = content.replace("##EXTRA_SOURCE_OBJS##", sourceObjsString)
        content = content.replace("##EXTRA_SOURCE_OBJS##", "")

        libDirsList = self.__GetStaticLibsPaths(config, package, relativePathBuildLib)
        extLibraryDependencies = self.__GetExternalLibraryDependencies(package)
        libsExtern = ""
        for lib in extLibraryDependencies:
            libsExtern = libsExtern + lib[0] + " "
            if lib[1] is not None and lib[1] not in libDirsList:
                libDirsList.append(lib[1])
        if libsExtern:
            libsExtern = "LIBS += " + libsExtern + "\n"
        content = content.replace("##PACKAGE_EXTERNAL_LIBRARY_DEPENDENCIES##", libsExtern)

        libDirs = self.__FormatListToString("EXTRA_LIBVPATH += ", libDirsList)
        content = content.replace("##EXTRA_LIBVPATHS##", libDirs)

        sl = self.__GetStaticLibs(package)
        content = content.replace("##STATIC_LIBS##", sl)

        name = package.ShortName if package.Type == PackageType.Executable else package.Name
        content = content.replace("##PINFO_DESC##", name)
        content = content.replace("##NAME##", name)

        # Local CPP defines
        localDefines = Util.ExtractNames(package.ResolvedBuildAllPrivateDefines)
        localDefines += Util.ExtractNames(package.ResolvedBuildAllPublicDefines)
        localDefineNames = MakeFileHelper.CreateList(localDefines)

        content = content.replace("##PACKAGE_DEFINES##", localDefineNames)

        #if package.Type == PackageType.Executable:
        #libraryDependencies = self.__GetLibraryDependencies(config, package)
        #libraryDependencies = MakeFileHelper.CreateList(libraryDependencies)
        #build = build.replace("##PACKAGE_LIBRARY_DEPENDENCIES##", libraryDependencies)

        if not config.DisableWrite:
            IOUtil.WriteFileIfChanged(dstFile, content)

        #remove this if statement if build scripts are required also for libraries
        if package.Type == PackageType.Executable:
            self.__GenerateBuildScript(config, package, self.BldTemplate, buildBasePath)
Beispiel #6
0
 def _CreateDirectory(self, path: str) -> None:
     if not IOUtil.IsDirectory(path):
         self.LogPrint("- Creating '{0}' as it was missing".format(path))
         IOUtil.SafeMakeDirs(path)
    def __RunCMakeAndBuild(self, sourcePackage: Package,
                           toolFinder: PackageToolFinder,
                           recipeVariants: List[str], sourcePath: str,
                           installPath: str, tempBuildPath: str,
                           target: CMakeTargetType, cmakeProjectName: str,
                           configurationList: List[BuildVariantConfig],
                           cmakeOptionList: List[str],
                           allowSkip: bool) -> None:
        installedDependencyList = self.__BuildDependencyPathList(
            sourcePackage, sourcePackage.ResolvedExperimentalRecipeBuildOrder)
        if len(recipeVariants) <= 0:
            installedDependencies = self.__BuildDependencyPathString(
                installedDependencyList)
            if installedDependencies is not None and len(
                    installedDependencies) > 0:
                cmakeOptionList = list(cmakeOptionList)
                cmakeOptionList.append(installedDependencies)

            self.Task.RunCMakeAndBuild(toolFinder, sourcePath, installPath,
                                       tempBuildPath, target, cmakeProjectName,
                                       configurationList, cmakeOptionList,
                                       allowSkip)
            return

        for variant in recipeVariants:
            self.BasicConfig.LogPrint("Recipe variant: {0}".format(variant))
            self.BasicConfig.PushIndent()
            try:
                cmakeOptionListCopy = list(cmakeOptionList)
                if len(installedDependencyList) > 0:
                    installedDependencyListCopy = [
                        IOUtil.Join(entry, variant)
                        for entry in installedDependencyList
                    ]
                    installedDependencies = self.__BuildDependencyPathString(
                        installedDependencyListCopy)
                    cmakeOptionListCopy.append(installedDependencies)

                if self._IsAndroid:
                    # FIX: Set this depending on package type
                    if not AndroidUtil.UseNDKCMakeToolchain():
                        optionList = [
                            "-DCMAKE_SYSTEM_VERSION={0}".format(
                                AndroidUtil.GetMinimumSDKVersion()),
                            "-DCMAKE_ANDROID_ARCH_ABI={0}".format(variant)
                        ]
                    else:
                        optionList = [
                            "-DANDROID_PLATFORM=android-{0}".format(
                                AndroidUtil.GetMinimumSDKVersion()),
                            "-DANDROID_ABI={0}".format(variant)
                        ]
                    cmakeOptionListCopy += optionList

                installPathCopy = IOUtil.Join(installPath, variant)
                tempBuildPathCopy = IOUtil.Join(tempBuildPath, variant)
                IOUtil.SafeMakeDirs(tempBuildPathCopy)

                self.Task.RunCMakeAndBuild(toolFinder, sourcePath,
                                           installPathCopy, tempBuildPathCopy,
                                           target, cmakeProjectName,
                                           configurationList,
                                           cmakeOptionListCopy, allowSkip)
            finally:
                self.BasicConfig.PopIndent()