Source code for gdeps.ide

#!python3

# Copyright 2007-2017 Gemr. All Rights Reserved.
# Licensed to MIT see LICENSE.txt

import os

import gdeps as GDeps

__author__ = 'Suryavarman (http://sourceforge.net/u/suryavarman/profile/)'


[docs]class Ide(GDeps.Config, GDeps.Reporting): """ Define the IDE base class """ def __init__(self, inConfigFile, inSectionName, inTypeName, inCompilers=[], inCompilersAlias=[]): """ Constructor :param inConfigFile: the config file it's a GDeps.ConfigFile :param inSectionName: name of the section config where it can be find the m_Dir value. :param inTypeName: the type string ex : "CodeBlocks" :param inCompilersAlias: Compilers alias to be add at m_Compilers :param inCompilers: Compilers list """ GDeps.Config.__init__(self, inConfigFile, inSectionName) GDeps.Reporting.__init__(self) self.m_TypeName = inTypeName self.m_Compilers = inCompilers self.m_CompilersAlias = inCompilersAlias self.Load()
[docs] def read(self, inSection): """ Read the IDE config file section """ self.m_Dir = inSection["dir"] assert os.path.exists(self.m_Dir), "This directory doesn't exist : " + self.m_Dir self.m_Compilers.extend(GDeps.getCompilers(self.m_ConfigFile, self.m_CompilersAlias))
[docs] def write(self): """ Write the IDE config file section """ aSection = GDeps.Config.write(self) aSection["dir"] = self.m_Dir for aCompiler in self.m_Compilers: aCompiler.write() return aSection
[docs] def build(self, inProjectPath, inProjectName, inCompiler, inTargetName, inLogFilePath, inWildCard, inRebuildAll=True, inIdeParams={}, inCompilerArgs={}): """ Build the project or the solution file from the current directory. Keywords arguments : :param inProjectPath: The project path :type inProjectPath: str :param inProjectName: The project or the solution name :type inProjectName: str :param inCompiler: allow the ide to know witch compiler it has to call, like to define the address model :type inCompiler: Gdeps.Compiler :param inTargetName: depend of your maker generally it can be all, release or debug. :type inTargetName: str :param inLogFilePath: define the output file log :type inLogFilePath: str :param inWildCard: the projection or solution extension :type inWildCard: str :param inRebuildAll: by default we rebuild all. This is a chronophage but cleaner. default( True ) :type inRebuildAll: bool :param inIdeParams: For each IDE you can add some parameters here :type inIdeParams: dict :param inCompilerArgs: Send the associate compilers arguments. :type inCompilerArgs: dict { str : array of str } """ pass
@staticmethod
[docs] def getBuildType(inTargetType): """ :return: The associate build target Id. Here it's a default implementation. :rtype: str """ aResult = '' if inTargetType == GDeps.Target.release_static or inTargetType == GDeps.Target.release_dynamic: aResult = "Release" if inTargetType == GDeps.Target.debug_static or inTargetType == GDeps.Target.debug_dynamic: aResult = "Debug" assert aResult, "BuildType : NOT FOUND" return aResult
[docs] def getBuildName(self, inCompiler, inTargetType): """ return a name to identify within the current ide builds. """ return self.m_TypeName + '_' + inCompiler.m_TypeName + '_' + str(inCompiler.m_AdressModel) + '_' + self.getBuildType(inTargetType)
[docs]class IdeBuilder: """ without a maker build a Project or a Workspace/Solution with a IDE """ def __init__(self, inIde, inSolutionName, inWildCard, inTargets, inFolderDir, inArgs, inLogFileOutPutDir='', inOverrideBuildType=''): """ :param inIde: a ide :type inIde: dict :param inSolutionName: the separator between each key-value :type inSolutionName: str :param inWildCard: the project/solution extension :members: GDeps.Keys.ms_IdeWildcard :type inWildCard: str :param inTargets: the targets configuration list :type inTargets: array of GDeps.TargetArgs :param inFolderDir: :members: GDeps.Keys.ms_FolderDir :type inFolderDir: str :param inArgs: :members: GDeps.Keys.ms_IdeArgs :type inArgs: str :param inLogFileOutPutDir: Log file output :type inLogFileOutPutDir: str :param inOverrideBuildType: If it's not empty the build target name will be use in any case. :members: GDeps.Keys.ms_IdeTargetName :type inOverrideBuildType: str """ self.m_Ide = inIde self.m_SolutionName = inSolutionName self.m_WildCard = inWildCard self.m_Targets = inTargets self.m_FolderDir = inFolderDir self.m_Args = inArgs self.m_LogFileOutPutDir = inLogFileOutPutDir if inLogFileOutPutDir else os.path.normpath(self.m_FolderDir) self.m_OverrideBuildType = inOverrideBuildType
[docs] def go(self): """ return a GDeps.MacroReporting """ aMacroReporting = GDeps.MacroReporting() if os.path.isdir(self.m_FolderDir): aCurrentDir = os.getcwd() os.chdir(self.m_FolderDir) if not self.m_Ide.m_Compilers: print(self.m_Ide.m_TypeName + " ERROR : There are no compiler") for aCompiler in self.m_Ide.m_Compilers: aCompiler.setvars() if not self.m_Targets: print(self.m_Ide.m_TypeName + " ERROR : There are no targets") for aTargetArgs in self.m_Targets: aBuildType = self.m_OverrideBuildType if self.m_OverrideBuildType else self.m_Ide.getBuildType(aTargetArgs.m_TargetType) aLogFilePath = self.getLogFilePath(aTargetArgs.m_TargetType, aCompiler) aCompilersArgs = aTargetArgs.joinArgs(aCompiler) # Build self.m_Ide.build(inProjectPath = self.m_FolderDir, inProjectName = self.m_SolutionName, inCompiler = aCompiler, inTargetName = aBuildType, inLogFilePath = aLogFilePath, inWildCard = self.m_WildCard, inRebuildAll = True, inIdeParams = self.m_Args, inCompilerArgs = aCompilersArgs) # Report aReportId = self.m_Ide.getBuildName(aCompiler, aTargetArgs.m_TargetType) + " " + self.m_SolutionName aMacroReporting.append(self.m_Ide, aReportId, aLogFilePath, False) os.chdir(aCurrentDir) else: print("ERROR : " + self.m_FolderDir + " not found or is not a directory.") return aMacroReporting
[docs] def getLogFilePath(self, inTargetType, inCompiler): """ return the log file path function of the build type and the model address """ aBuildType = self.m_Ide.getBuildType(inTargetType) aCompilerType = self.m_Ide.getBuildName(inCompiler, inTargetType) aLogFilePath = os.path.normpath(self.m_FolderDir) + '/build_' + aBuildType + '_' + aCompilerType + '.log' aLogFilePath = os.path.normpath(aLogFilePath) return aLogFilePath