Skip to content

Commit

Permalink
Make includeorder.py handle #ifndef
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Jun 18, 2019
1 parent 2c69996 commit 8121621
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
16 changes: 16 additions & 0 deletions wpiformat/test/test_includeorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,4 +546,20 @@ def test_includeorder():
"#endif" + os.linesep)
test.add_latest_input_as_output(True)

# Ensure #ifndef is handled properly
test.add_input("./Test.h",
"#ifndef __APPLE__" + os.linesep + \
"#include <util.h>" + os.linesep + \
"#elif !defined(_WIN32)" + os.linesep + \
"#include <pty.h>" + os.linesep + \
"#endif" + os.linesep)
test.add_latest_input_as_output(True)

# Ensure #ifndef is handled properly
test.add_input("./Test.h",
"#ifndef _WIN32" + os.linesep + \
"#include <pty.h>" + os.linesep + \
"#endif" + os.linesep)
test.add_latest_input_as_output(True)

test.run(OutputType.FILE)
5 changes: 3 additions & 2 deletions wpiformat/wpiformat/includeorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ def header_sort(self, config_file, lines_list, file_name, start, end,

i = start
while i < end:
if "#ifdef" in lines_list[i]:
if "#ifdef" in lines_list[i] or "#ifndef" in lines_list[i]:
ifdef_count = 1
for j in range(i + 1, end):
if "#ifdef" in lines_list[j]:
if "#ifdef" in lines_list[j] or "#ifndef" in lines_list[j]:
ifdef_count += 1
elif "#endif" in lines_list[j]:
ifdef_count -= 1
Expand Down Expand Up @@ -365,6 +365,7 @@ def run_pipeline(self, config_file, name, lines):
# Write lines from beginning of file to headers
i = 0
while i < len(lines_list) and ("#ifdef" not in lines_list[i] and
"#ifndef" not in lines_list[i] and
"#include" not in lines_list[i]):
i += 1
output_list = lines_list[0:i]
Expand Down

0 comments on commit 8121621

Please sign in to comment.