OLD | NEW |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 """Top-level presubmit script for Skia. | 6 """Top-level presubmit script for Skia. |
7 | 7 |
8 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 8 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
9 for more details about the presubmit API built into gcl. | 9 for more details about the presubmit API built into gcl. |
10 """ | 10 """ |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 for affected_file in input_api.AffectedSourceFiles(None): | 70 for affected_file in input_api.AffectedSourceFiles(None): |
71 affected_file_path = affected_file.LocalPath() | 71 affected_file_path = affected_file.LocalPath() |
72 if affected_file_path.endswith('.py'): | 72 if affected_file_path.endswith('.py'): |
73 affected_python_files.append(affected_file_path) | 73 affected_python_files.append(affected_file_path) |
74 return input_api.canned_checks.RunPylint( | 74 return input_api.canned_checks.RunPylint( |
75 input_api, output_api, | 75 input_api, output_api, |
76 disabled_warnings=pylint_disabled_warnings, | 76 disabled_warnings=pylint_disabled_warnings, |
77 white_list=affected_python_files) | 77 white_list=affected_python_files) |
78 | 78 |
79 | 79 |
| 80 def _IfDefChecks(input_api, output_api): |
| 81 """Ensures if/ifdef are not before includes. See skbug/3362 for details.""" |
| 82 comment_block_start_pattern = re.compile('^\s*\/\*.*$') |
| 83 comment_block_middle_pattern = re.compile('^\s+\*.*') |
| 84 comment_block_end_pattern = re.compile('^\s+\*\/.*$') |
| 85 single_line_comment_pattern = re.compile('^\s*//.*$') |
| 86 def is_comment(line): |
| 87 return (comment_block_start_pattern.match(line) or |
| 88 comment_block_middle_pattern.match(line) or |
| 89 comment_block_end_pattern.match(line) or |
| 90 single_line_comment_pattern.match(line)) |
| 91 |
| 92 empty_line_pattern = re.compile('^\s*$') |
| 93 def is_empty_line(line): |
| 94 return empty_line_pattern.match(line) |
| 95 |
| 96 failing_files = [] |
| 97 for affected_file in input_api.AffectedSourceFiles(None): |
| 98 affected_file_path = affected_file.LocalPath() |
| 99 if affected_file_path.endswith('.cpp') or affected_file_path.endswith('.h'): |
| 100 f = open(affected_file_path) |
| 101 for line in f.xreadlines(): |
| 102 if is_comment(line) or is_empty_line(line): |
| 103 continue |
| 104 # The below will be the first real line after comments and newlines. |
| 105 if line.startswith('#if 0 '): |
| 106 pass |
| 107 elif line.startswith('#if ') or line.startswith('#ifdef '): |
| 108 failing_files.append(affected_file_path) |
| 109 break |
| 110 |
| 111 results = [] |
| 112 if failing_files: |
| 113 results.append( |
| 114 output_api.PresubmitError( |
| 115 'The following files have #if or #ifdef before includes:\n%s\n\n' |
| 116 'See skbug.com/3362 for why this should be fixed.' % |
| 117 '\n'.join(failing_files))) |
| 118 return results |
| 119 |
| 120 |
80 def _CommonChecks(input_api, output_api): | 121 def _CommonChecks(input_api, output_api): |
81 """Presubmit checks common to upload and commit.""" | 122 """Presubmit checks common to upload and commit.""" |
82 results = [] | 123 results = [] |
83 sources = lambda x: (x.LocalPath().endswith('.h') or | 124 sources = lambda x: (x.LocalPath().endswith('.h') or |
84 x.LocalPath().endswith('.gypi') or | 125 x.LocalPath().endswith('.gypi') or |
85 x.LocalPath().endswith('.gyp') or | 126 x.LocalPath().endswith('.gyp') or |
86 x.LocalPath().endswith('.py') or | 127 x.LocalPath().endswith('.py') or |
87 x.LocalPath().endswith('.sh') or | 128 x.LocalPath().endswith('.sh') or |
88 x.LocalPath().endswith('.cpp')) | 129 x.LocalPath().endswith('.cpp')) |
89 results.extend( | 130 results.extend( |
90 _CheckChangeHasEol( | 131 _CheckChangeHasEol( |
91 input_api, output_api, source_file_filter=sources)) | 132 input_api, output_api, source_file_filter=sources)) |
92 results.extend(_PythonChecks(input_api, output_api)) | 133 results.extend(_PythonChecks(input_api, output_api)) |
| 134 results.extend(_IfDefChecks(input_api, output_api)) |
93 return results | 135 return results |
94 | 136 |
95 | 137 |
96 def CheckChangeOnUpload(input_api, output_api): | 138 def CheckChangeOnUpload(input_api, output_api): |
97 """Presubmit checks for the change on upload. | 139 """Presubmit checks for the change on upload. |
98 | 140 |
99 The following are the presubmit checks: | 141 The following are the presubmit checks: |
100 * Check change has one and only one EOL. | 142 * Check change has one and only one EOL. |
101 """ | 143 """ |
102 results = [] | 144 results = [] |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 state and an error if it is in 'Closed' state. | 375 state and an error if it is in 'Closed' state. |
334 """ | 376 """ |
335 results = [] | 377 results = [] |
336 results.extend(_CommonChecks(input_api, output_api)) | 378 results.extend(_CommonChecks(input_api, output_api)) |
337 results.extend( | 379 results.extend( |
338 _CheckTreeStatus(input_api, output_api, json_url=( | 380 _CheckTreeStatus(input_api, output_api, json_url=( |
339 SKIA_TREE_STATUS_URL + '/banner-status?format=json'))) | 381 SKIA_TREE_STATUS_URL + '/banner-status?format=json'))) |
340 results.extend(_CheckLGTMsForPublicAPI(input_api, output_api)) | 382 results.extend(_CheckLGTMsForPublicAPI(input_api, output_api)) |
341 results.extend(_CheckOwnerIsInAuthorsFile(input_api, output_api)) | 383 results.extend(_CheckOwnerIsInAuthorsFile(input_api, output_api)) |
342 return results | 384 return results |
OLD | NEW |