Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make includeorder.py handle #ifndef #157

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions wpiformat/wpiformat/includeorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ def header_sort(self, config_file, lines_list, file_name, start, end, ifdef_leve

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 @@ -419,7 +419,9 @@ 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 "#include" not in lines_list[i]
"#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
79 changes: 79 additions & 0 deletions wpiformat/wpiformat/test/test_includeorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,4 +949,83 @@ def test_includeorder():
)
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)

# Ensure include guards are handled properly
test.add_input(
"./Test.h",
"#ifndef CSCORE_CONFIGURABLESOURCEIMPL_H_"
+ os.linesep
+ "#define CSCORE_CONFIGURABLESOURCEIMPL_H_"
+ os.linesep
+ os.linesep
+ "#include <atomic>"
+ os.linesep
+ "#include <functional>"
+ os.linesep
+ "#include <memory>"
+ os.linesep
+ "#include <string>"
+ os.linesep
+ "#include <string_view>"
+ os.linesep
+ "#include <vector>"
+ os.linesep
+ os.linesep
+ "#include <wpi/span.h>"
+ os.linesep
+ os.linesep
+ '#include "SourceImpl.h"'
+ os.linesep
+ os.linesep
+ "namespace cs {"
+ os.linesep
+ os.linesep
+ "class ConfigurableSourceImpl : public SourceImpl {"
+ os.linesep
+ " protected:"
+ os.linesep
+ " ConfigurableSourceImpl(std::string_view name, wpi::Logger& logger,"
+ os.linesep
+ " Notifier& notifier, Telemetry& telemetry,"
+ os.linesep
+ " const VideoMode& mode);"
+ os.linesep
+ "};"
+ os.linesep
+ os.linesep
+ "} // namespace cs"
+ os.linesep
+ os.linesep
+ "#endif // CSCORE_CONFIGURABLESOURCEIMPL_H_"
+ os.linesep,
)
test.add_latest_input_as_output(True)

test.run(OutputType.FILE)
Loading