#!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]def getParamsString(inParams, inSeparator=' ', inEqualSign='=', inRemoveLastSeparator=False, inMultipleValueSeparator=' ', inMultipleValueBegin='', inMultipleValueEnd=''):
""" :param inParams: is a dictionary
:type inParams: dict
:param inSeparator: the separator between each key-value
:type inSeparator: str
:param inEqualSign: the affectation character between the key and the value
:type inEqualSign: str
:param inRemoveLastSeparator: if true remove the last `inSeparator`
:type inRemoveLastSeparator: bool
:param inMultipleValueSeparator: some parameter can have several values, use this parameter to define the separator.
:type inMultipleValueSeparator: str
:param inMultipleValueBegin: some parameter can have several values, use this parameter to define the beginning.
**Example**
inMultipleValueBegin = '"'
KEY = "value1 value2 ...
:type inMultipleValueBegin: str
:param inMultipleValueEnd some parameter can have several values, use this parameter to define the ending.
**Example**
inMultipleValueEnd = '"'
KEY = ... value_n-2 value_n-1"
:type inMultipleValueBegin: str
:return: concatenate string with all parameters separate by `inSeparator`
:rtype: str
**Example**
>>> getParamsString( { 'SHARED' : '1', 'MONOLITHIC' : '1', 'UNICODE' : '1', "CXXFLAGS": ["-fno-keep-inline-dllexport", "-std=c++11"] }, ' | ', ' = ', False, inMultipleValueSeparator=' ', inMultipleValueBegin='', inMultipleValueEnd='')
'SHARED = 1 | MONOLITHIC = 1 | UNICODE = 1 | CXXFLAGS = -fno-keep-inline-dllexport -std=c++11 | '
"""
result = ''
for aKey, aValue in inParams.items():
value_str = ''
if isinstance(aValue, (tuple, list)):
value_str = inMultipleValueBegin
for i in range(len(aValue) - 1):
value_str += str(aValue[i]) + inMultipleValueSeparator
value_str += aValue[-1] + inMultipleValueEnd
else:
value_str = str(aValue)
result += str(aKey) + inEqualSign + value_str + inSeparator
if inRemoveLastSeparator and len(result) >= len(inSeparator):
result = result[:-len(inSeparator)]
return result
[docs]def getAllParamsString(inArgs, inTargetArgs, inCompiler, inSeparator=' ', inEqualSign='=', inRemoveLastSeparator=False, inMultipleValueSeparator=' ', inMultipleValueBegin='', inMultipleValueEnd=''):
"""
:param inArgs: A associate container key : value
:type inArgs: dict
:param inTargetArgs: A build target.
:type inTargetArgs: GDeps.TargetArgs
:param inCompiler: A compiler to find the associate arguments in the target.
:members:`GDeps.TargetArgs.m_CompilersArgs`
:type inCompiler: GDeps.Compiler
:param inSeparator: the separator between each key-value
:type inSeparator: str
:param inEqualSign: the affectation character between the key and the value
:type inEqualSign: str
:param inRemoveLastSeparator: if true remove the last inSeparator
:type inRemoveLastSeparator: bool
:return: all the arguments in one string
:rtype: str
**Example**
>>> inSeperator = ' ',
>>> inEqualSign = '=',
>>> inRemoveLastSeparator = False
the output result will be : 'SHARED=1 MONOLITHIC=1 UNICODE=1'
.. note::
The compiler arguments has to be create with the good separators, because it's one string and stay like
that.
"""
aResult = GDeps.getParamsString(inArgs, inSeparator, inEqualSign, False, inMultipleValueSeparator, inMultipleValueBegin, inMultipleValueEnd)
aResult += GDeps.getParamsString(inTargetArgs.m_Args, inSeparator, inEqualSign, False, inMultipleValueSeparator, inMultipleValueBegin, inMultipleValueEnd)
aResult += GDeps.getParamsString(inTargetArgs.getAdressModelArgs(inCompiler.m_AdressModel), inSeparator, inEqualSign, False, inMultipleValueSeparator, inMultipleValueBegin, inMultipleValueEnd)
aResult += GDeps.getParamsString(inTargetArgs.getCompilerArgs(inCompiler), inSeparator, inEqualSign, inRemoveLastSeparator, inMultipleValueSeparator, inMultipleValueBegin, inMultipleValueEnd)
return aResult
[docs]class Make(GDeps.Reporting, GDeps.Config):
""" Define the base class to define a Maker """
def __init__(self, inConfigFile, inSectionName, inFolderDir, inSolutionName, inArgs, inTargetsArgs, inCompilers=[], inIdes=[], inExePath="", inTypeName=""):
""" :param inConfigFile:
:param inSectionName: Can be empty for the maker include in the
folder directory.
:param inFolderDir: The working dir.
example:
c:\\working\\libs\\boost_1-58
:param inSolutionName: Can be empty for the maker include in the
folder directory
:param inArgs:
:param inTargetsArgs:
:param inCompilers:
:param inIdes:
:param inExePath:
:param inTypeName:
"""
GDeps.Reporting.__init__(self)
GDeps.Config.__init__(self, inConfigFile, inSectionName)
self.m_ExePath = inExePath
""" The maker executable path. Can be the working directory for makers include into
the sources.
"""
self.m_FolderDir = inFolderDir
""" The working directory for the maker """
self.m_SolutionName = inSolutionName
""" Define the solution to be build.
@remarks Some makers are include into the sources like
boost don't need it.
"""
self.m_Args = inArgs
""" Array of string for the maker """
self.m_TargetsArgs = inTargetsArgs
""" array of GDeps.TargetArgs """
self.m_Compilers = inCompilers
""" Array of GDeps.Compiler """
self.m_Ides = inIdes
""" Array of GDeps.Ide """
self.m_TypeName = inTypeName
""" The maker type name :
**Example**
CMake32
"""
[docs] def make(self):
""" return a GDeps.MacroReporting """
return GDeps.MacroReporting()
[docs] def read(self, inSection):
"""
:param inSection:
:raise: :func:`GDeps.Make.read` raise a assertion if the path doesn't exist.
"""
if len(self.m_SectionName) > 0 and not self.m_ExePath:
self.m_ExePath = inSection[GDeps.Keys.ms_ExePath]
r""" Be care full (or not some time no!!!) don't write manually the paths
with double backslash \\ but only one backslash \ the python parser
add the double backslash \\
"""
assert os.path.exists(self.m_ExePath), "This application doesn't exist : " + self.m_ExePath
[docs] def write(self):
if len(self.m_SectionName) > 0 and not self.m_ExePath:
aSection = GDeps.Config.write(self)
aSection[GDeps.Keys.ms_ExePath] = self.m_ExePath
return aSection