def sort_includes(f):
"""Sort the #include lines of a specific file."""
+
+ # Skip files which are under INPUTS trees or test trees.
+ if 'INPUTS/' in f.name or 'test/' in f.name:
+ return
+
+ ext = os.path.splitext(f.name)[1]
+ if ext not in ['.cpp', '.c', '.h', '.inc', '.def']:
+ return
+
lines = f.readlines()
- look_for_api_header = os.path.splitext(f.name)[1] == '.cpp'
+ look_for_api_header = ext in ['.cpp', '.c']
found_headers = False
headers_begin = 0
headers_end = 0
api_headers.append(header)
look_for_api_header = False
continue
- if header.startswith('<'):
+ if header.startswith('<') or header.startswith('"gtest/'):
system_headers.append(header)
continue
if (header.startswith('"llvm/') or header.startswith('"llvm-c/') or
if not found_headers:
return
- local_headers.sort()
- project_headers.sort()
- system_headers.sort()
+ local_headers = sorted(set(local_headers))
+ project_headers = sorted(set(project_headers))
+ system_headers = sorted(set(system_headers))
headers = api_headers + local_headers + project_headers + system_headers
header_lines = ['#include ' + h for h in headers]
lines = lines[:headers_begin] + header_lines + lines[headers_end + 1:]