diff options
author | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 20:38:57 +0000 |
---|---|---|
committer | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-14 20:38:57 +0000 |
commit | 728b9bbafc32f1ddc3b97046c995825cce1e7b77 (patch) | |
tree | ca155004cc693f87bdc1ae8d8028bd48118b7b95 /PRESUBMIT.py | |
parent | 5a24d2bd3246d0c108e36de9067508b05b162be5 (diff) | |
download | chromium_src-728b9bbafc32f1ddc3b97046c995825cce1e7b77.zip chromium_src-728b9bbafc32f1ddc3b97046c995825cce1e7b77.tar.gz chromium_src-728b9bbafc32f1ddc3b97046c995825cce1e7b77.tar.bz2 |
Fix the presubmit include check.
Some files in content/ can have their first include in content/public.
Also, the check didn't detect all the error where there were non-include lines
between two conflicting #include lines.
BUG=NONE
Review URL: https://codereview.chromium.org/11365263
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167735 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'PRESUBMIT.py')
-rw-r--r-- | PRESUBMIT.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 4ddc09f..b3f7989 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -522,32 +522,34 @@ def _CheckIncludeOrderForScope(scope, input_api, file_path, changed_linenums): state = C_SYSTEM_INCLUDES previous_line = '' + previous_line_num = 0 problem_linenums = [] for line_num, line in scope: if c_system_include_pattern.match(line): if state != C_SYSTEM_INCLUDES: - problem_linenums.append(line_num) + problem_linenums.append((line_num, previous_line_num)) elif previous_line and previous_line > line: - problem_linenums.append(line_num) + problem_linenums.append((line_num, previous_line_num)) elif cpp_system_include_pattern.match(line): if state == C_SYSTEM_INCLUDES: state = CPP_SYSTEM_INCLUDES elif state == CUSTOM_INCLUDES: - problem_linenums.append(line_num) + problem_linenums.append((line_num, previous_line_num)) elif previous_line and previous_line > line: - problem_linenums.append(line_num) + problem_linenums.append((line_num, previous_line_num)) elif custom_include_pattern.match(line): if state != CUSTOM_INCLUDES: state = CUSTOM_INCLUDES elif previous_line and previous_line > line: - problem_linenums.append(line_num) + problem_linenums.append((line_num, previous_line_num)) else: problem_linenums.append(line_num) previous_line = line + previous_line_num = line_num warnings = [] - for line_num in problem_linenums: - if line_num in changed_linenums or line_num - 1 in changed_linenums: + for (line_num, previous_line_num) in problem_linenums: + if line_num in changed_linenums or previous_line_num in changed_linenums: warnings.append(' %s:%d' % (file_path, line_num)) return warnings @@ -569,8 +571,12 @@ def _CheckIncludeOrderInFile(input_api, output_api, f, is_source, for line in contents: line_num += 1 if include_pattern.match(line): - expected = '#include "%s"' % f.LocalPath().replace('.cc', '.h') - if line != expected: + # The file name for the first include needs to be the same as for the + # file checked; the path can differ. + expected_ending = ( + input_api.os_path.basename(f.LocalPath()).replace('.cc', '.h') + + '"') + if not line.endswith(expected_ending): # Maybe there was no special first include, and that's fine. Process # the line again along with the normal includes. line_num -= 1 |