Source code for gdeps.dm
#!python3
# Copyright 2007-2017 Gemr. All Rights Reserved.
# Licensed to MIT see LICENSE.txt
import configparser
import warnings
import os
import gdeps as GDeps
__author__ = 'Suryavarman (http://sourceforge.net/u/suryavarman/profile/)'
[docs]class DigitalMars(GDeps.Compiler):
"""
.. note:::
If you have this error :
>>> "Warning 2: File Not Found stlp45dm_static.lib"
don't forget to download Digital Mars with the stl version. I don't know how to
download for free the debug version.
See : http://www.digitalmars.com/d/archives/digitalmars/D/32586.html
To begin with something we set the enVar with the stl support.
https://dlang.org/dmd-windows.html
"""
def __init__(self, inConfigFile, inSectionName, inDir, inAdressModel, inTypeName):
GDeps.Compiler.__init__(self, inConfigFile, inSectionName, inDir, inAdressModel, inTypeName)
self.m_ErrorRegexp = r"(.*: error:.*|.*Fatal error:.*|.*is invalid.*|.*Error.*)"
self.m_WarningRegexp = r".*: Warning.*"
[docs] def getCxxDir(self):
return os.path.normpath(self.m_Dir + r"\\dmc")
[docs] def getCDir(self):
return os.path.normpath(self.m_Dir + r"\\dmc.exe")
[docs] def getRcDir(self):
return os.path.normpath(self.m_Dir + r"\\libunres.exe")
[docs] def getMakeDir(self):
return os.path.normpath(self.m_Dir + r"\\make.exe")
[docs] def getLinkDir(self):
return os.path.normpath(self.m_Dir + r"\\link.exe")
[docs]class Dm_32(DigitalMars):
"""
Implementation of Digitalmars 32 bits.
.. note::
By default we use `the STL port<https://www.daniweb.com/programming/software-development/threads/340777/digital-mars-unable-to-open-input-file-iostream>`_
"""
def __init__(self, inConfigFile, inSectionName="dm_32", inDir=r"C:\\dm\\bin"):
DigitalMars.__init__(self, inConfigFile, inSectionName, inDir, GDeps.AdressModel.x86, Dm_32.getTypeName())
[docs] def getUpdateEnvarBatch(self):
aBinDir = self.m_Dir
aDmDir = GDeps.getParentDir(self.m_Dir)
aResult = '@set "PATH=%PATH%;' + aBinDir + '"'
aResult += os.linesep
aResult += '@set "BIN=' + aBinDir + '"'
aResult += os.linesep
aResult += '@set "INCLUDE=' + os.path.normpath(aDmDir + r'\\stlport\\stlport') + ';' + os.path.normpath(aDmDir + r'\\include') + ';' + os.path.normpath(aDmDir + r'\\mfc\\include') + ';%INCLUDE%"'
aResult += os.linesep
aResult += '@set "LIB=' + os.path.normpath(aDmDir + r'\\lib') + ';' + os.path.normpath(aDmDir + r'\\mfc\\lib') + ';%LIB%"'
aResult += os.linesep
aResult += '@set "HELP=' + os.path.normpath(aDmDir + r'\\help') + '"'
aResult += os.linesep
return aResult
[docs] def setvars(self):
GDeps.call(self.getUpdateEnvarBatch())
aBinDir = self.m_Dir
aDmDir = GDeps.getParentDir(self.m_Dir)
os.environ['PATH'] = os.environ['PATH'] if 'PATH' in os.environ else '' + ';' + os.path.normpath(aBinDir)
os.environ['BIN'] = os.path.normpath(aBinDir) + ';' + os.environ['BIN'] if 'BIN' in os.environ else ''
os.environ['INCLUDE'] = os.path.normpath(aDmDir + r'\\stlport\\stlport') + ';' + \
os.path.normpath(aDmDir + r'\\include') + ';' + \
os.path.normpath(aDmDir + r'\\mfc\\include') + ';' + \
os.environ['INCLUDE'] if 'INCLUDE' in os.environ else ''
os.environ['LIB'] = os.path.normpath(aDmDir + r'\\lib') + ';' + \
os.path.normpath(aDmDir + r'\\mfc\\lib') + ';' + \
os.environ['LIB'] if 'LIB' in os.environ else ''
os.environ['HELP'] = os.path.normpath(aBinDir) + ';' + os.environ['HELP'] if 'HELP' in os.environ else ''
r""" sc.ini
We have to re-write the sc.ini with the path because of Codeblocks. Codeblocks use the sc.ini file and it
cannot be override.
[Version]
version = 857
[Environment]
PATH=%PATH%;"%@P%\..\bin"
BIN="%@P%\..\bin"
INCLUDE="%@P%\..\stlport\stlport";"%@P%\..\include";"%@P%\..\mfc\include";%INCLUDE%
LIB="%@P%\..\lib";"%@P%\..\mfc\lib";%LIB%
HELP="%@P%\..\help"
https://docs.python.org/3/library/configparser.html
"""
aSCFile = configparser.ConfigParser(interpolation=None)
aConfigPath = os.path.normpath(aBinDir + r'\\sc.ini')
aSCFile.read(aConfigPath)
aConfigBackupPath = os.path.normpath(aBinDir + r'\\sc.ini.gdeps.backup')
warnings.warn('The file ' + aConfigPath + ' will be overwrite. If the file ' + aConfigBackupPath +
" doesn't exist. We have create the backup file " + aConfigBackupPath)
if not os.path.exists(aConfigBackupPath):
with open(aConfigBackupPath, 'w') as aConfigfile:
aSCFile.write(aConfigfile)
aSCFile['Environment'] = {'PATH': r'%PATH%;"%@P%\..\bin"',
'BIN': r'"%@P%\..\bin"',
'INCLUDE': r'"%@P%\..\stlport\stlport";"%@P%\..\include";"%@P%\..\mfc\include";%INCLUDE%',
'LIB': r'"%@P%\..\lib";"%@P%\..\mfc\lib";%LIB%',
'HELP': r'"%@P%\..\help"'}
with open(aConfigPath, 'w') as aConfigfile:
aSCFile.write(aConfigfile)
@staticmethod
[docs] def getTypeName():
return "Dm_32"
@staticmethod
[docs] def getStaticLibraryWildCard():
"""
:return: The extension of the static library associate with this compiler.
:rtype: str
"""
# todo I don't know, i have to test
return "lib"