Skip to content

Commit 11c6ddf

Browse files
author
vladlosev
committed
Prevents pump.py from splitting long IWYU pragma lines.
git-svn-id: http://googletest.googlecode.com/svn/trunk@620 861a406c-534a-0410-8894-cb66d6ee9925
1 parent 120f8b3 commit 11c6ddf

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

scripts/pump.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -704,14 +704,14 @@ def RunCode(env, code_node, output):
704704
RunAtomicCode(env, atomic_code, output)
705705

706706

707-
def IsComment(cur_line):
707+
def IsSingleLineComment(cur_line):
708708
return '//' in cur_line
709709

710710

711-
def IsInPreprocessorDirevative(prev_lines, cur_line):
711+
def IsInPreprocessorDirective(prev_lines, cur_line):
712712
if cur_line.lstrip().startswith('#'):
713713
return True
714-
return prev_lines != [] and prev_lines[-1].endswith('\\')
714+
return prev_lines and prev_lines[-1].endswith('\\')
715715

716716

717717
def WrapComment(line, output):
@@ -768,37 +768,45 @@ def WrapCode(line, line_concat, output):
768768
output.append(prefix + cur_line.strip())
769769

770770

771-
def WrapPreprocessorDirevative(line, output):
771+
def WrapPreprocessorDirective(line, output):
772772
WrapCode(line, ' \\', output)
773773

774774

775775
def WrapPlainCode(line, output):
776776
WrapCode(line, '', output)
777777

778778

779-
def IsHeaderGuardOrInclude(line):
779+
def IsMultiLineIWYUPragma(line):
780+
return re.search(r'/\* IWYU pragma: ', line)
781+
782+
783+
def IsHeaderGuardIncludeOrOneLineIWYUPragma(line):
780784
return (re.match(r'^#(ifndef|define|endif\s*//)\s*[\w_]+\s*$', line) or
781-
re.match(r'^#include\s', line))
785+
re.match(r'^#include\s', line) or
786+
# Don't break IWYU pragmas, either; that causes iwyu.py problems.
787+
re.search(r'// IWYU pragma: ', line))
782788

783789

784790
def WrapLongLine(line, output):
785791
line = line.rstrip()
786792
if len(line) <= 80:
787793
output.append(line)
788-
elif IsComment(line):
789-
if IsHeaderGuardOrInclude(line):
790-
# The style guide made an exception to allow long header guard lines
791-
# and includes.
794+
elif IsSingleLineComment(line):
795+
if IsHeaderGuardIncludeOrOneLineIWYUPragma(line):
796+
# The style guide made an exception to allow long header guard lines,
797+
# includes and IWYU pragmas.
792798
output.append(line)
793799
else:
794800
WrapComment(line, output)
795-
elif IsInPreprocessorDirevative(output, line):
796-
if IsHeaderGuardOrInclude(line):
797-
# The style guide made an exception to allow long header guard lines
798-
# and includes.
801+
elif IsInPreprocessorDirective(output, line):
802+
if IsHeaderGuardIncludeOrOneLineIWYUPragma(line):
803+
# The style guide made an exception to allow long header guard lines,
804+
# includes and IWYU pragmas.
799805
output.append(line)
800806
else:
801-
WrapPreprocessorDirevative(line, output)
807+
WrapPreprocessorDirective(line, output)
808+
elif IsMultiLineIWYUPragma(line):
809+
output.append(line)
802810
else:
803811
WrapPlainCode(line, output)
804812

0 commit comments

Comments
 (0)