summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--PRESUBMIT.py11
-rwxr-xr-xPRESUBMIT_test.py34
2 files changed, 43 insertions, 2 deletions
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index b395233..ee75ad3 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -557,8 +557,13 @@ def _CheckIncludeOrderInFile(input_api, f, changed_linenums):
# often need to appear in a specific order.
excluded_include_pattern = input_api.re.compile(r'\s*#include \<.*/.*')
custom_include_pattern = input_api.re.compile(r'\s*#include "(?P<FILE>.*)"')
- if_pattern = (
- input_api.re.compile(r'\s*#\s*(if|elif|else|endif|define|undef).*'))
+ if_pattern = input_api.re.compile(
+ r'\s*#\s*(if|elif|else|endif|define|undef).*')
+ # Some files need specialized order of includes; exclude such files from this
+ # check.
+ uncheckable_includes_pattern = input_api.re.compile(
+ r'\s*#include '
+ '("ipc/.*macros\.h"|<windows\.h>|".*gl.*autogen.h")\s*')
contents = f.NewContents()
warnings = []
@@ -591,6 +596,8 @@ def _CheckIncludeOrderInFile(input_api, f, changed_linenums):
current_scope = []
for line in contents[line_num:]:
line_num += 1
+ if uncheckable_includes_pattern.match(line):
+ return []
if if_pattern.match(line):
scopes.append(current_scope)
current_scope = []
diff --git a/PRESUBMIT_test.py b/PRESUBMIT_test.py
index a8bbc80..979ad89 100755
--- a/PRESUBMIT_test.py
+++ b/PRESUBMIT_test.py
@@ -252,6 +252,40 @@ class IncludeOrderTest(unittest.TestCase):
self.assertEqual(1, len(warnings[0].items))
self.assertEqual('notify', warnings[0].type)
+ def testUncheckableIncludes(self):
+ mock_input_api = MockInputApi()
+ contents = ['#include <windows.h>',
+ '#include "b.h"'
+ '#include "a.h"']
+ mock_file = MockFile('', contents)
+ warnings = PRESUBMIT._CheckIncludeOrderInFile(
+ mock_input_api, mock_file, range(1, len(contents) + 1))
+ self.assertEqual(0, len(warnings))
+
+ contents = ['#include "gpu/command_buffer/gles_autogen.h"',
+ '#include "b.h"'
+ '#include "a.h"']
+ mock_file = MockFile('', contents)
+ warnings = PRESUBMIT._CheckIncludeOrderInFile(
+ mock_input_api, mock_file, range(1, len(contents) + 1))
+ self.assertEqual(0, len(warnings))
+
+ contents = ['#include "gl_mock_autogen.h"',
+ '#include "b.h"'
+ '#include "a.h"']
+ mock_file = MockFile('', contents)
+ warnings = PRESUBMIT._CheckIncludeOrderInFile(
+ mock_input_api, mock_file, range(1, len(contents) + 1))
+ self.assertEqual(0, len(warnings))
+
+ contents = ['#include "ipc/some_macros.h"',
+ '#include "b.h"'
+ '#include "a.h"']
+ mock_file = MockFile('', contents)
+ warnings = PRESUBMIT._CheckIncludeOrderInFile(
+ mock_input_api, mock_file, range(1, len(contents) + 1))
+ self.assertEqual(0, len(warnings))
+
class VersionControlerConflictsTest(unittest.TestCase):
def testTypicalConflict(self):