mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 770182 Warn when preprocessing unnecessarily r=bsmedberg
This commit is contained in:
parent
73ec324196
commit
be77a8234e
@ -370,6 +370,7 @@ class JarMaker(object):
|
||||
pp.setMarker('%')
|
||||
pp.out = outf
|
||||
pp.do_include(inf)
|
||||
pp.warnUnused(realsrc)
|
||||
outf.close()
|
||||
inf.close()
|
||||
return
|
||||
|
@ -41,6 +41,7 @@ class Preprocessor:
|
||||
'LINE': 0,
|
||||
'DIRECTORY': os.path.abspath('.')}.iteritems():
|
||||
self.context[k] = v
|
||||
self.actionLevel = 0
|
||||
self.disableLevel = 0
|
||||
# ifStates can be
|
||||
# 0: hadTrue
|
||||
@ -74,6 +75,13 @@ class Preprocessor:
|
||||
self.LE = '\n'
|
||||
self.varsubst = re.compile('@(?P<VAR>\w+)@', re.U)
|
||||
|
||||
def warnUnused(self, file):
|
||||
if self.actionLevel == 0:
|
||||
sys.stderr.write('%s: WARNING: no preprocessor directives found\n' % file)
|
||||
elif self.actionLevel == 1:
|
||||
sys.stderr.write('%s: WARNING: no useful preprocessor directives found\n' % file)
|
||||
pass
|
||||
|
||||
def setLineEndings(self, aLE):
|
||||
"""
|
||||
Set the line endings to be used for output.
|
||||
@ -135,8 +143,10 @@ class Preprocessor:
|
||||
if defaultToStdin and len(args) == 0:
|
||||
args = [sys.stdin]
|
||||
includes.extend(args)
|
||||
for f in includes:
|
||||
self.do_include(f, False)
|
||||
if includes:
|
||||
for f in includes:
|
||||
self.do_include(f, False)
|
||||
self.warnUnused(f)
|
||||
pass
|
||||
|
||||
def getCommandLineParser(self, unescapeDefines = False):
|
||||
@ -186,6 +196,8 @@ class Preprocessor:
|
||||
"""
|
||||
Handle a single line of input (internal).
|
||||
"""
|
||||
if self.actionLevel == 0 and self.comment.match(aLine):
|
||||
self.actionLevel = 1
|
||||
m = self.instruction.match(aLine)
|
||||
if m:
|
||||
args = None
|
||||
@ -199,6 +211,8 @@ class Preprocessor:
|
||||
level, cmd = self.cmds[cmd]
|
||||
if (level >= self.disableLevel):
|
||||
cmd(args)
|
||||
if cmd != 'literal':
|
||||
self.actionLevel = 2
|
||||
elif self.disableLevel == 0 and not self.comment.match(aLine):
|
||||
self.write(aLine)
|
||||
pass
|
||||
|
@ -41,6 +41,7 @@ class Preprocessor:
|
||||
'LINE': 0,
|
||||
'DIRECTORY': os.path.abspath('.')}.iteritems():
|
||||
self.context[k] = v
|
||||
self.actionLevel = 0
|
||||
self.disableLevel = 0
|
||||
# ifStates can be
|
||||
# 0: hadTrue
|
||||
@ -74,6 +75,13 @@ class Preprocessor:
|
||||
self.LE = '\n'
|
||||
self.varsubst = re.compile('@(?P<VAR>\w+)@', re.U)
|
||||
|
||||
def warnUnused(self, file):
|
||||
if self.actionLevel == 0:
|
||||
sys.stderr.write('%s: WARNING: no preprocessor directives found\n' % file)
|
||||
elif self.actionLevel == 1:
|
||||
sys.stderr.write('%s: WARNING: no useful preprocessor directives found\n' % file)
|
||||
pass
|
||||
|
||||
def setLineEndings(self, aLE):
|
||||
"""
|
||||
Set the line endings to be used for output.
|
||||
@ -135,8 +143,10 @@ class Preprocessor:
|
||||
if defaultToStdin and len(args) == 0:
|
||||
args = [sys.stdin]
|
||||
includes.extend(args)
|
||||
for f in includes:
|
||||
self.do_include(f, False)
|
||||
if includes:
|
||||
for f in includes:
|
||||
self.do_include(f, False)
|
||||
self.warnUnused(f)
|
||||
pass
|
||||
|
||||
def getCommandLineParser(self, unescapeDefines = False):
|
||||
@ -186,6 +196,8 @@ class Preprocessor:
|
||||
"""
|
||||
Handle a single line of input (internal).
|
||||
"""
|
||||
if self.actionLevel == 0 and self.comment.match(aLine):
|
||||
self.actionLevel = 1
|
||||
m = self.instruction.match(aLine)
|
||||
if m:
|
||||
args = None
|
||||
@ -199,6 +211,8 @@ class Preprocessor:
|
||||
level, cmd = self.cmds[cmd]
|
||||
if (level >= self.disableLevel):
|
||||
cmd(args)
|
||||
if cmd != 'literal':
|
||||
self.actionLevel = 2
|
||||
elif self.disableLevel == 0 and not self.comment.match(aLine):
|
||||
self.write(aLine)
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user