def __CreateVariantOption(self, variant: PackagePlatformVariant, option: PackagePlatformVariantOption, isLibrary: bool, isFirstOption: bool) -> str: strContent = "" if isFirstOption: strContent += "ifeq ($(%s),%s)\n" % (variant.Name, option.Name) else: strContent += "else ifeq ($(%s),%s)\n" % (variant.Name, option.Name) if len(option.DirectDefines) > 0: defines = Util.ExtractNames(option.DirectDefines) strDefines = MakeFileHelper.CreateList(defines) strContent += "CPP_DEFINE_FLAG_NAMES+=%s\n\n" % (strDefines) if len(option.ExternalDependencies) > 0: includes = self.__ExtractInclude(option.ExternalDependencies) if len(includes) > 0: includes.reverse() # to make GCC happy strIncludes = MakeFileHelper.CreateList(includes) strContent += "INCLUDE_DIRS+=%s\n\n" % (strIncludes) if not isLibrary and len(option.ExternalDependencies) > 0: extLibraryDependencies = Util.ExtractNames( option.ExternalDependencies) extLibraryDependencies.reverse() # to make GCC happy strExtLibraryDependencies = MakeFileHelper.CreateList( extLibraryDependencies) strContent += "USER_EXTLIB_DEPS+=%s\n\n" % ( strExtLibraryDependencies) return strContent
def PrintExecutableSkipReason(log: Log, fullPackageList: List[Package], filteredPackageList: List[Package]) -> None: for package in fullPackageList: if package.Type == PackageType.Executable: if package.ResolvedPlatformNotSupported: notSupported = LocalUtil.BuildListOfDirectlyNotSupported(package) notSupportedNames = Util.ExtractNames(notSupported) log.DoPrint("{0} was marked as not supported on this platform by package: {1}".format(package.Name, notSupportedNames))
def __ResolveAndGenerate(config: Config, errorHelpManager: ErrorHelpManager, platformGeneratorPlugin: GeneratorPlugin, packageLoader: PackageLoader, packageFilters: PackageFilters, isSDKBuild: bool, writeGraph: bool) -> List[Package]: generatorContext = GeneratorContext(config, errorHelpManager, packageFilters.RecipeFilterManager, config.ToolConfig.Experimental, platformGeneratorPlugin) process = PackageLoadAndResolveProcess(config, packageLoader, platformGeneratorPlugin, writeGraph=writeGraph) process.Resolve(generatorContext, packageFilters) if not isSDKBuild: for package in process.Packages: if not package.ResolvedPlatformSupported and package.Type != PackageType.TopLevel: notSupported = LocalUtil.BuildListOfDirectlyNotSupported( package) notSupportedNames = Util.ExtractNames(notSupported) config.DoPrintWarning( "{0} was marked as not supported on this platform by package: {1}" .format(package.Name, notSupportedNames)) return platformGeneratorPlugin.Generate(generatorContext, config, process.Packages)
def __LocateRootDir(self, basicConfig: BasicConfig, rootDirs: List[ToolConfigRootDirectory], entryName: str, projectRootDirectory: str) -> ToolConfigRootDirectory: if projectRootDirectory is None or not entryName.startswith( MagicStrings.ProjectRoot): for rootDir in rootDirs: if entryName.startswith(rootDir.Name): return rootDir else: # Lets try to locate a root directory which the project is based in, # then use it to dynamically add a new allowed root directory based on the project file location for rootDir in rootDirs: if projectRootDirectory == rootDir.ResolvedPath: return ToolConfigRootDirectory(basicConfig, None, rootDir.ProjectId, rootDir, MagicStrings.ProjectRoot, rootDir.DynamicName) elif projectRootDirectory.startswith(rootDir.ResolvedPathEx): dynamicRootDir = projectRootDirectory[len(rootDir. ResolvedPathEx):] dynamicRootDir = "{0}/{1}".format(rootDir.Name, dynamicRootDir) return ToolConfigRootDirectory(basicConfig, None, rootDir.ProjectId, rootDir, MagicStrings.ProjectRoot, dynamicRootDir) raise Exception( "Path '{0}' is not based on one of the valid root directories {1}". format(entryName, ", ".join(Util.ExtractNames(rootDirs))))
def __CreateVariantOptionEnd(self, variant: PackagePlatformVariant) -> str: name = variant.Name allOptions = ", ".join(Util.ExtractNames(variant.Options)) strContent = "else\n" strContent += "$(error Variant %s not configured expected one of these %s)\n" % ( name, allOptions) strContent += "endif\n" return strContent
def __init__(self, extendingPackage: Package, extendingVariant: PackagePlatformVariant, basePackage: Package, baseVariant: PackagePlatformVariant, newOptions: List[PackagePlatformVariantOption]) -> None: msg = "Package '{0}' variant: '{1}' can not extend the options defined by '{2}' with '{3}'".format( extendingPackage.Name, extendingVariant.Name, basePackage.Name, ", ".join(Util.ExtractNames(newOptions))) super().__init__(extendingPackage.XMLElement, msg)
def __FiltersPackagesBySupported(log: Log, packages: Union[List[Package], List[AppInfoPackage]]) -> List[T]: """ Remove packages that are marked as not supported by the platform """ packageList = [] for package in packages: if not package.ResolvedPlatformNotSupported: packageList.append(package) elif not package.Type == PackageType.TopLevel and log.IsVerbose and isinstance(package, Package): notSupported = LocalUtil.BuildListOfDirectlyNotSupported(package) notSupportedNames = Util.ExtractNames(notSupported) log.DoPrint("Skipping {0} since its marked as not supported on this platform by package: {1}".format(package.Name, notSupportedNames)) return cast(List[T], packageList)
def __GetExternalLibraryDependencies(self, package: Package) -> List[str]: libPaths = [] # type: List[str] # GCC apparently needs the list to be in reverse order buildOrder = list(package.ResolvedBuildOrder) buildOrder.reverse() for entry in buildOrder: externalList = Util.ExtractNames( Util.FilterByType(entry.ResolvedDirectExternalDependencies, [ ExternalDependencyType.StaticLib, ExternalDependencyType.DLL ])) externalList.reverse() if len(externalList) > 0: externalList = self.__ApplyExternalLibNameCorrection( externalList) libPaths += externalList return libPaths
def __GenerateBuildFile(self, config: Config, generatorName: str, package: Package, template: str, dstMakeFilename: str) -> None: if package.ShortName is None or package.Namespace is None or package.ResolvedMakeObjectPath is None or package.AbsolutePath is None: raise Exception("Invalid Package") name = GeneratorGNUmakefileUtil.GetTargetName(package) installPath = package.Namespace if package.Type == PackageType.Library: name = "lib" + name if package.ResolvedBuildSourceFiles is None or package.ResolvedBuildAllIncludeDirs is None or package.ResolvedBuildAllPrivateDefines is None or package.ResolvedBuildAllPublicDefines is None: raise Exception("Invalid Package") files = MakeFileHelper.CreateList(package.ResolvedBuildSourceFiles) includeDirs = MakeFileHelper.CreateList( package.ResolvedBuildAllIncludeDirs) localDefines = Util.ExtractNames( package.ResolvedBuildAllPrivateDefines) localDefines += Util.ExtractNames( package.ResolvedBuildAllPublicDefines) localDefineNames = MakeFileHelper.CreateList(localDefines) variantSection = self.__GetVariantSection(package) if package.ResolvedMakeVariantNameHint is None: raise InternalErrorException( "Package '{0}' ResolvedMakeVariantNameHint can not be None". format(package.Name)) variantName = package.ResolvedMakeVariantNameHint build = template build = build.replace("##PACKAGE_TARGET_NAME##", name) build = build.replace("##PACKAGE_TARGET_INSTALL_PATH##", installPath) build = build.replace("##PACKAGE_SOURCE_FILES##", files) build = build.replace("##PACKAGE_INCLUDE_DIRS##", includeDirs) build = build.replace("##PACKAGE_DEFINES##", localDefineNames) build = build.replace("##PACKAGE_VARIANT_SECTION##", variantSection) build = build.replace("##PACKAGE_OBJECT_PATH##", package.ResolvedMakeObjectPath) build = build.replace("##PACKAGE_VARIANT_NAME##", variantName) if package.Type == PackageType.Executable: libraryDependencies = self.__GetLibraryDependencies( config, package) strLibraryDependencies = MakeFileHelper.CreateList( libraryDependencies) build = build.replace("##PACKAGE_LIBRARY_DEPENDENCIES##", strLibraryDependencies) extLibraryDependencies = self.__GetExternalLibraryDependencies( package) strExtLibraryDependencies = MakeFileHelper.CreateList( extLibraryDependencies) build = build.replace("##PACKAGE_EXTERNAL_LIBRARY_DEPENDENCIES##", strExtLibraryDependencies) extLibraryPaths = self.__GetExternalLibraryPaths( package, [ExternalDependencyType.StaticLib, ExternalDependencyType.DLL]) strExtLibraryPaths = MakeFileHelper.CreateList(extLibraryPaths) build = build.replace("##PACKAGE_EXTERNAL_LIBRARY_PATHS##", strExtLibraryPaths) extDllPaths = self.__GetExternalLibraryPaths( package, [ExternalDependencyType.DLL]) strExtDllPaths = MakeFileHelper.CreateList(extDllPaths) build = build.replace("##PACKAGE_EXTERNAL_DLL_PATHS##", strExtDllPaths) executableReport = GeneratorGNUmakefileUtil.TryGenerateExecutableReport( config, generatorName, package) if executableReport is not None: variableReport = GeneratorGNUmakefileUtil.GenerateVariableReport( config, generatorName, package, self.ConfigVariantOptions) GitIgnoreHelper.AddFromBuildReport(self.GitIgnoreDict, package, executableReport, variableReport) dstFile = IOUtil.Join(package.AbsolutePath, dstMakeFilename) if not config.DisableWrite: IOUtil.WriteFileIfChanged(dstFile, build) GitIgnoreHelper.AddPathIfInPackageRoot(self.GitIgnoreDict, package, dstFile)
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)