优化Python脚本--替换VC2005/2008工程x64配置
对一个Win32工程添加x64配置后,宏定义WIN32需要改为_WIN64,Python脚本如下:
import os
def replaceprojtext(s, pos, find, replace):
if pos > 0 and s.rfind(find) > pos:
return (True, s[:pos] + s[pos:].replace(find, replace))
return (False, s)
def replaceproj(fn):
s = open(fn).read()
pos = s.find('|x64')
c1, s = replaceprojtext(s, pos, 'WIN32;', '_WIN64;')
c2, s = replaceprojtext(s, pos, ';WIN32"', ';_WIN64"')
c3, s = replaceprojtext(s, pos, '0\\$(ConfigurationName)', '0x64\\$(ConfigurationName)')
if c1 or c2 or c3:
print(fn)
open(fn,'w').write(s)
def replaceprojs(path):
for fn in [path+'\\'+fn for fn in os.listdir(path)]:
if fn[-7:]=='.vcproj':
replaceproj(fn)
elif os.path.isdir(fn):
replaceprojs(fn)
replaceprojs(r'F:\x3linux\cppunit-1.12.1')
最后一行的路径需要修改为实际路径。

浙公网安备 33010602011771号