Introduce a 'nonnull' metadata on Load instructions.
[oota-llvm.git] / utils / sort_includes.py
index 855cb38ad594c4f5829a6f2512c8c3037d966931..fef97550db8d8f84ec5e012246ecbf2ca5d88424 100755 (executable)
@@ -13,8 +13,17 @@ import os
 
 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
@@ -55,9 +64,9 @@ def sort_includes(f):
   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:]