Mercurial > codeOptimizer
changeset 2:10f1d7de9bc3
New module for reading configurations.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Sun, 16 Sep 2012 21:29:22 +0200 |
| parents | a1224150b8f6 |
| children | f65c2d63ab66 |
| files | Options.py codeOptimizer.py |
| diffstat | 2 files changed, 40 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Options.py Sun Sep 16 21:29:22 2012 +0200 @@ -0,0 +1,32 @@ +#!/usr/bin/env python -O + +import xml.dom.minidom, sys, re + +class Config: + def __init__(self, path): + self.document = xml.dom.minidom.parse(path) + + @staticmethod + def getOption(node, option, match): + for potentialMatch in node.childNodes: + if potentialMatch.nodeName == "option": + if potentialMatch.hasAttribute('match'): + matchstr = potentialMatch.getAttribute('match') + try: + prog = re.compile(matchstr) + except: + raise xml.dom.SyntaxErr(matchstr + + + " is not a valid value for attribute match") + if prog.match(match): + res = Config.getOption(potentialMatch, option, match) + if not res: + res = potentialMatch.getAttribute('cxxflags') + return res + return None + + def getCxxflags(self, name): + value = self.getOption(self.document.childNodes[0], 'Cxxflags', name) + if not value: + raise xml.dom.NotFoundErr() + return value
--- a/codeOptimizer.py Sun Sep 16 10:35:39 2012 +0200 +++ b/codeOptimizer.py Sun Sep 16 21:29:22 2012 +0200 @@ -4,6 +4,7 @@ from Compilable import Compilable from DepGraph import DepGraph +from Options import Config @@ -19,18 +20,19 @@ return True return False - -infiles = sys.argv[1:] +try: + options = Config(sys.argv[1]) +except: + print sys.argv[1] + ' is not a valid xml file' +infiles = sys.argv[2:] files = {} unknown = [] -flags = '-DHAS_BOOST -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_XML_LIB -DQT_SQL_LIB -O3 -Wall -I/opt/local/include -I/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/include -F/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/lib -I/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/include/QtOpenGL -I/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/include/QtXml -I/Users/bfg/QtSDK/Desktop/Qt/4.8.1/gcc/include/QtSql -I/Users/bfg/projects/dedupe' - for file in infiles: if isHppfile(file) or isCppfile(file): c = Compilable(file) - c.setFlags(flags) + c.setFlags(options.getCxxflags(file)) files[file] = c else: unknown.append(file) @@ -52,7 +54,7 @@ for file in files: if not file.worksWithoutModifications(): print file.path - raise SystemExit(str.join(file.path) + " does not compile at all") + raise SystemExit(file.path + " does not compile at all") for file in files: removable = file.removeRemovableIncludes()
