def EliminateIncludes(self): pattern = r'(?<!//)#\s*include ["<][^">]*[">].*' regex = re.compile(pattern) for header in self.mHeaders: file = open(header, 'r') data = file.read() file.close() match = regex.search(data) if match and Perforce.OpenForEdit(header): while match: begin = match.start() file = open(header, 'w') file.write(data[:begin] + '//' + data[begin:]) file.close() sourceFile = os.path.join(os.path.dirname(header), 'EliminateIncludes.cpp') file = open(sourceFile, 'w') file.write('#include "%s"\n' % os.path.basename(header)) file.close() if self.Compile(sourceFile) == 0: data = data[:begin] + '//' + data[begin:] else: file = open(header, 'w') file.write(data) file.close() os.remove(sourceFile) match = regex.search(data, match.end())
def AddX64Configuration(filename): file = open(filename, 'r') text = file.read() file.close() last = 0 vcproj = '' pattern = '(\t+<Platform\n\t+Name=)"Win32"(\n\t+/>\n)' regex = re.compile(pattern, re.I | re.S) match = regex.search(text) if match: vcproj += text[:match.end()] + match.group(1) + '"x64"' + match.group( 2) last = match.end() pattern = '(?:\t+<(?:file)?configuration\s+name="(?:debug|release)\|win32"\s+)(?:.*?)(?:</(?:file)?configuration>\n)' regex = re.compile(pattern, re.I | re.S) match = regex.search(text, last) found = match != None while match: vcproj += text[last:match.end()] + CreateX64Configuration( text[match.start():match.end()]) last = match.end() match = regex.search(text, last) if found and Perforce.OpenForEdit(filename): vcproj += text[last:] file = open(filename, 'w') file.write(vcproj) file.close()
def RemoveWin64Configuration( filename ): file = open( filename, 'r' ) text = file.read() file.close() pattern = '\t+StripPrivateSymbols *= *"[^"]+"\n' regex = re.compile( pattern, re.I |re.S ) newtext = regex.sub('', text) if text != newtext and Perforce.OpenForEdit( filename ): file = open( filename, 'w' ) text = file.write(newtext) file.close()
def RemoveDetect64BitPortabilityProblems( filename ): file = open( filename, 'r' ) text = file.read() file.close() pattern = r'\t+Detect64BitPortabilityProblems="[^"]+"[^\n]*\n' regex = re.compile( pattern, re.I |re.S ) newtext = regex.sub('', text) if newtext != text and Perforce.OpenForEdit( filename ): file = open( filename, 'w' ) file.write( newtext ) file.close()
def UpdateVcProj(filename, compilerRegex, linkerRegex): file = open( filename, 'r' ) org_text = file.read() file.close() new_text = org_text boost = FindBoostPath(filename) new_text = UpdateCompilerSettings(new_text, boost, compilerRegex) new_text = UpdateLinkerSettings(new_text, boost, linkerRegex) if new_text != org_text: print(('Updating %s' % filename)) Perforce.OpenForEdit(filename) file = open( filename, 'w' ) file.write(new_text) file.close()
def RemoveWin64Configuration( filename ): file = open( filename, 'r' ) text = file.read() file.close() #pattern = '(?P<pre><(?:file)?configuration\s+name="(?:debug|release)\|x64"\s+)(?P<config>.*?)(?P<post></(?:file)?configuration>)' pattern = '(?:\t+<(?:file)?configuration\s+name="win64 (?:debug|release)\|win32"\s+)(?:.*?)(?:</(?:file)?configuration>\n)' regex = re.compile( pattern, re.I |re.S ) match = regex.search( text ) found = match != None while match: begin = match.start() end = match.start() + len( match.group(0) ) text = text[ : begin ] + text[ end : ] match = regex.search( text ) if found and Perforce.OpenForEdit( filename ): file = open( filename, 'w' ) file.write( text ) file.close()
def UpdateVCProj(filename): file = open(filename, 'r') lines = file.readlines() file.close() basename = filename[filename.rfind('\\') + 1:len(filename)] if Perforce.OpenForEdit(filename) == False: return print(('Processing file "' + basename + '"')) file = open(filename, 'w') insideConfig = False insideFileConfig = False insideWin64 = False for line in lines: if line.strip().lower() == '<configuration': insideConfig = True elif line.strip().lower() == '<fileconfiguration': insideFileConfig = True elif( insideConfig or insideFileConfig ) and \ line.strip().lower().find( 'name="win64' ) != -1: insideWin64 = True insideConfig = False insideFileConfig = False elif insideWin64 and \ ( line.strip().lower() == '</configuration>' or \ line.strip().lower() == '</fileconfiguration>' ): insideWin64 = False insideConfig = False insideFileConfig = False elif insideWin64: continue elif insideConfig or insideFileConfig: if insideConfig: file.write('\t\t<Configuration\n') insideConfig = False elif insideFileConfig: file.write('\t\t\t\t<FileConfiguration\n') insideFileConfig = False if line.strip().find('x64'): line = line.replace('x64', 'Win64-x64') file.write(line) elif not insideWin64 and line.strip().find('x64'): line = line.replace('x64', 'Win64-x64') file.write(line) else: file.write(line) file.close()
def UpdateVCProj(filename): file = open(filename, 'r') lines = file.readlines() file.close() basename = filename[filename.rfind('\\') + 1:len(filename)] if basename.lower().startswith('z_'): return if Perforce.OpenForEdit(filename) == False: return print(('Processing file "' + basename + '"')) file = open(filename, 'w') bInsideConfig = False bFoundConfig = False release = False bInsideCompilerTool = False bInsideLinkerTool = False bInsideLibrarianTool = False foundCompilerOptimizations = False foundLinkerOptimizations = False foundLibrarianOptimizations = False for line in lines: if bFoundConfig == False and line.strip().upper() == '<CONFIGURATION': #print 'Found a configuration section' file.write(line) bFoundConfig = True elif bFoundConfig and line.strip().upper().startswith('NAME="'): file.write(line) if line.strip().upper() == 'NAME="RELEASE|WIN32"': #print 'Found the release win32 configuration section' bInsideConfig = True else: #print 'Not a valid configuration section' bInsideConfig = False bFoundConfig = False elif bInsideConfig and line.strip().upper() == '</CONFIGURATION>': file.write(line) release = False bInsideCompilerTool = False bInsideLinkerTool = False bInsideConfig = False bInsideLibrarianTool = False elif bInsideConfig and line.strip() == 'Name="VCLinkerTool"': #print 'Found begin of linker tool' file.write(line) bInsideLinkerTool = True bInsideCompilerTool = False bInsideLibrarianTool = False #elif bInsideConfig and bInsideLinkerTool and \ # line.strip().startswith( 'LinkIncremental=' ): # #print 'Found LinkIncremental in linker tool' # if line.strip().endswith( '"2"' ): # line = line.replace( '2', '1' ) # file.write( line ) elif bInsideConfig and bInsideLinkerTool and \ line.strip().startswith( 'LinkTimeCodeGeneration=' ): #print 'Removing LinkTimeCodeGeneration in linker tool' #file.write( line ) foundLinkerOptimizations = True elif bInsideConfig and bInsideLinkerTool and line.strip().find( '/>') != -1: #print 'Found end of linker tool' if foundLinkerOptimizations == False: print('Didn\'t find any linker optimizations') # file.write( '\t\t\t\tLinkTimeCodeGeneration="1"\n' ) file.write(line) bInsideCompilerTool = False bInsideLinkerTool = False elif bInsideConfig and line.strip() == 'Name="VCLibrarianTool"': #print 'Found begin of compiler tool' file.write(line) bInsideCompilerTool = False bInsideLinkerTool = False bInsideLibrarianTool = True elif bInsideConfig and bInsideLibrarianTool and \ line.strip().startswith( 'AdditionalOptions=' ): #print 'Found LinkTimeCodeGeneration in librarian tool' if line.strip().upper().find('/LTCG') == -1: print( 'Didn\'t find LinkTimeCodeGeneration in librarian tool additional options' ) file.write(line) else: if line.strip().upper().find(' /LTCG') != -1: line = line.replace(' /LTCG', '') file.write(line) # print line #else: # print 'AdditionalOptions="/LTCG" removed' foundLibrarianOptimizations = True elif bInsideConfig and bInsideLibrarianTool and line.strip().find( '/>') != -1: #print 'Found end of librarian tool' if foundLibrarianOptimizations == False: print('Didn\'t find any librarian optimizations') # file.write( '\t\t\t\tAdditionalOptions="/LTCG"\n' ) file.write(line) bInsideCompilerTool = False bInsideLinkerTool = False bInsideLibrarianTool = False elif bInsideConfig and line.strip() == 'Name="VCCLCompilerTool"': #print 'Found begin of compiler tool' file.write(line) bInsideCompilerTool = True bInsideLinkerTool = False bInsideLibrarianTool = False elif bInsideConfig and bInsideCompilerTool and \ line.strip().startswith( 'WholeProgramOptimization=' ): #print 'Removing WholeProgramOptimization in compiler tool' #print 'Found WholeProgramOptimization in compiler tool' #file.write( line ) foundCompilerOptimizations = True elif bInsideConfig and bInsideCompilerTool and line.strip().find( '/>') != -1: #print 'Found end of compiler tool' if foundCompilerOptimizations == False: print( 'Didn\'t find WholeProgramOptimization in the compiler tool' ) #file.write( '\t\t\t\tWholeProgramOptimization="true"\n' ) file.write(line) bInsideCompilerTool = False bInsideLinkerTool = False bInsideLibrarianTool = False #if line.strip().lower().startswith( 'additionalincludedirectories' ) and \ # line.lower().find( 'boost' ) == -1 and \ # line.lower().find( 'vs.net' ) != -1: # index = line.lower().find( 'vs.net' ) # addition = ';' + line[ line.rfind( ';', 0, index ) + 1 : index ] + 'Boost' # line = line[ 0 : line.rfind('"') ] + addition + line[ line.rfind('"') : len( line ) ] # file.write( line ) # print line.strip() else: file.write(line) file.close()
def UpdateMainCpp(filename): file = open(filename, 'r') lines = file.readlines() file.close() if Perforce.OpenForEdit(filename) == False: return print(('Processing file "' + filename + '"')) file = open(filename, 'w') updated = False deleteBlankSpaces = False foundUnitMain = False for line in lines: if not updated and line.strip().lower( ) == '#include "base/dev/cppunit/cppunitmain.h"': file.write('#define _CRTDBG_MAP_ALLOC\n') file.write('#include <stdlib.h>\n') file.write('#include <crtdbg.h>\n') file.write(line) foundInclude = True elif not updated and deleteBlankSpaces and line.strip() == '': continue elif not updated and deleteBlankSpaces and line.strip().lower( ) == 'int main( int argc, char * argv[] )': file.write(line) deleteBlankSpaces = False continue elif not updated and line.strip().lower( ) == '#include "base/dev/timing.h"': file.write(line + '\n') deleteBlankSpaces = True #elif foundInclude and line.strip() == '': # file.write( '#include "Base/Dev/Timing.h"\n' ) # file.write( line ) # foundInclude = False elif line.strip().lower().find( '_crtdbg_map_alloc' ) != -1 or \ line.strip().lower().startswith( '_crtsetdbgflag' ): file.write(line) updated = True elif not updated and line.strip().lower( ) == 'cleartimers(log_if_data, "before testrunner");': if not foundUnitMain: file.write( '\t_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );\n\n' ) else: line = line.replace('Before', 'After') foundUnitMain = False file.write(line) elif not updated and line.strip().lower( ) == 'cppunitmain( argc, argv );': file.write(line) foundUnitMain = True #elif not updated and line.strip().lower() == 'return 0;': # file.write( '\tClearTimers(LOG_IF_DATA, "Before TestRunner");\n' ) # file.write( '\tg_pTimingManager->PreserveTransientTimers();\n' ) # file.write( line ) else: file.write(line) file.close()
import os, sys, re, Utils, Perforce def IsProjectFile( file ): return not re.search('wsfiles', file, re.I) and re.match(r'^.*\.vcproj$', file, re.I) if __name__ == '__main__': for file in Utils.RecurseDirectory( os.getcwd(), IsProjectFile, False ): Perforce.OpenForEdit(file)