一鍵開關VS的release模式優化


  因為我們公司的項目規模非常大了,如果日常調試使用debug模式的話,每次調試啟動都要非常長的時間,因此大多數人使用release關優化的方式來進行日常開發。但是因為持續集成的存在,上傳的代碼要求是開啟優化的,這樣服務器才能打出優化后的版本。

  因為上面說的這種情況,導致我們的成員進行調試的時候,經常會調試進開了優化的dll中,那么這次的調試就宣告無果了,因為開了優化之后調試模式下的變量信息都是錯亂的,必須關掉調試,關閉那個dll的優化,重新編譯重新下斷點,非常耗時。

  因此,我寫了下面這個python腳本,用以方便程序員一鍵開關release模式下的優化。這樣就可以在調試前關閉所有dll的優化,在提交前再開啟所有優化了。代碼如下:

import lxml
import codecs
import sys
import os
from lxml import etree
from lxml.html import clean

def ProcessOneFile(filePath, bMaxSpeed):
    oContent = etree.parse(filePath)
    root = oContent.getroot()
    ns1 = {}
    ns1['tt'] = root.nsmap[None]
    optimizationElements = root.xpath('//tt:ItemDefinitionGroup[contains(@Condition,"Release")]/tt:ClCompile/tt:Optimization', namespaces=ns1)
    for element in optimizationElements:
        element.text = 'MaxSpeed' if bMaxSpeed else 'Disabled'
    oContent.write(filePath, encoding = "utf-8", pretty_print = True, method = "xml", xml_declaration=True)

def searchFile(curpath, endWith, bMaxSpeed):
    try:
        os.chdir(curpath)
    except:
        return
    fl = os.listdir(os.curdir)
    for nFile in fl:
        if os.path.isfile(nFile):
            if nFile.endswith(endWith):
                print(nFile)
                ProcessOneFile(nFile, bMaxSpeed)
                return
    for nFile in fl:
        if os.path.isdir(nFile):
            searchFile(nFile, endWith, bMaxSpeed)
            os.chdir(os.pardir)


if __name__ == '__main__':
    bMaxSpeed = True
    if len(sys.argv) > 1:
        bMaxSpeed = sys.argv[1] == "MaxSpeed"
    fatherPath = os.getcwd()
    searchFile(fatherPath, ".vcxproj", bMaxSpeed)

使用方式就是將這個腳本放到你想開關代碼的目錄里。然后這個目錄和其子目錄下的所有工程都會處理。為了速度我還將其編成了exe,並用如下兩個bat命令行來使用。

ModifyMaxSpeed MaxSpeed
ModifyMaxSpeed Disabled

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM