OLD | NEW |
1 # Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 1 # Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
2 # | 2 # |
3 # Use of this source code is governed by a BSD-style license | 3 # Use of this source code is governed by a BSD-style license |
4 # that can be found in the LICENSE file in the root of the source | 4 # that can be found in the LICENSE file in the root of the source |
5 # tree. An additional intellectual property rights grant can be found | 5 # tree. An additional intellectual property rights grant can be found |
6 # in the file PATENTS. All contributing project authors may | 6 # in the file PATENTS. All contributing project authors may |
7 # be found in the AUTHORS file in the root of the source tree. | 7 # be found in the AUTHORS file in the root of the source tree. |
8 | 8 |
9 import json | 9 import json |
10 import os | 10 import os |
11 import platform | 11 import platform |
12 import re | 12 import re |
13 import subprocess | 13 import subprocess |
14 import sys | 14 import sys |
15 | 15 |
16 | 16 |
| 17 # Directories that will be scanned by cpplint by the presubmit script. |
| 18 CPPLINT_DIRS = [ |
| 19 'webrtc/video_engine', |
| 20 ] |
| 21 |
| 22 |
17 def _CheckNoIOStreamInHeaders(input_api, output_api): | 23 def _CheckNoIOStreamInHeaders(input_api, output_api): |
18 """Checks to make sure no .h files include <iostream>.""" | 24 """Checks to make sure no .h files include <iostream>.""" |
19 files = [] | 25 files = [] |
20 pattern = input_api.re.compile(r'^#include\s*<iostream>', | 26 pattern = input_api.re.compile(r'^#include\s*<iostream>', |
21 input_api.re.MULTILINE) | 27 input_api.re.MULTILINE) |
22 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): | 28 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
23 if not f.LocalPath().endswith('.h'): | 29 if not f.LocalPath().endswith('.h'): |
24 continue | 30 continue |
25 contents = input_api.ReadFile(f) | 31 contents = input_api.ReadFile(f) |
26 if pattern.search(contents): | 32 if pattern.search(contents): |
(...skipping 20 matching lines...) Expand all Loading... |
47 if 'FRIEND_TEST(' in line: | 53 if 'FRIEND_TEST(' in line: |
48 problems.append(' %s:%d' % (f.LocalPath(), line_num)) | 54 problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
49 | 55 |
50 if not problems: | 56 if not problems: |
51 return [] | 57 return [] |
52 return [output_api.PresubmitPromptWarning('WebRTC\'s code should not use ' | 58 return [output_api.PresubmitPromptWarning('WebRTC\'s code should not use ' |
53 'gtest\'s FRIEND_TEST() macro. Include testsupport/gtest_prod_util.h and ' | 59 'gtest\'s FRIEND_TEST() macro. Include testsupport/gtest_prod_util.h and ' |
54 'use FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))] | 60 'use FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))] |
55 | 61 |
56 | 62 |
| 63 def _IsLintWhitelisted(whitelist_dirs, file_path): |
| 64 """ Checks if a file is whitelisted for lint check.""" |
| 65 for path in whitelist_dirs: |
| 66 if os.path.dirname(file_path).startswith(path): |
| 67 return True |
| 68 return False |
| 69 |
| 70 |
57 def _CheckApprovedFilesLintClean(input_api, output_api, | 71 def _CheckApprovedFilesLintClean(input_api, output_api, |
58 source_file_filter=None): | 72 source_file_filter=None): |
59 """Checks that all new or whitelisted .cc and .h files pass cpplint.py. | 73 """Checks that all new or whitelisted .cc and .h files pass cpplint.py. |
60 This check is based on _CheckChangeLintsClean in | 74 This check is based on _CheckChangeLintsClean in |
61 depot_tools/presubmit_canned_checks.py but has less filters and only checks | 75 depot_tools/presubmit_canned_checks.py but has less filters and only checks |
62 added files.""" | 76 added files.""" |
63 result = [] | 77 result = [] |
64 | 78 |
65 # Initialize cpplint. | 79 # Initialize cpplint. |
66 import cpplint | 80 import cpplint |
67 # Access to a protected member _XX of a client class | 81 # Access to a protected member _XX of a client class |
68 # pylint: disable=W0212 | 82 # pylint: disable=W0212 |
69 cpplint._cpplint_state.ResetErrorCounts() | 83 cpplint._cpplint_state.ResetErrorCounts() |
70 | 84 |
| 85 # Create a platform independent whitelist for the CPPLINT_DIRS. |
| 86 whitelist_dirs = [input_api.os_path.join(*path.split('/')) |
| 87 for path in CPPLINT_DIRS] |
| 88 |
71 # Use the strictest verbosity level for cpplint.py (level 1) which is the | 89 # Use the strictest verbosity level for cpplint.py (level 1) which is the |
72 # default when running cpplint.py from command line. | 90 # default when running cpplint.py from command line. |
73 # To make it possible to work with not-yet-converted code, we're only applying | 91 # To make it possible to work with not-yet-converted code, we're only applying |
74 # it to new (or moved/renamed) files and files listed in LINT_FOLDERS. | 92 # it to new (or moved/renamed) files and files listed in LINT_FOLDERS. |
75 verbosity_level = 1 | 93 verbosity_level = 1 |
76 files = [] | 94 files = [] |
77 for f in input_api.AffectedSourceFiles(source_file_filter): | 95 for f in input_api.AffectedSourceFiles(source_file_filter): |
78 # Note that moved/renamed files also count as added. | 96 # Note that moved/renamed files also count as added. |
79 if f.Action() == 'A': | 97 if f.Action() == 'A' or _IsLintWhitelisted(whitelist_dirs, f.LocalPath()): |
80 files.append(f.AbsoluteLocalPath()) | 98 files.append(f.AbsoluteLocalPath()) |
81 | 99 |
82 for file_name in files: | 100 for file_name in files: |
83 cpplint.ProcessFile(file_name, verbosity_level) | 101 cpplint.ProcessFile(file_name, verbosity_level) |
84 | 102 |
85 if cpplint._cpplint_state.error_count > 0: | 103 if cpplint._cpplint_state.error_count > 0: |
86 if input_api.is_committing: | 104 if input_api.is_committing: |
87 # TODO(kjellander): Change back to PresubmitError below when we're | 105 # TODO(kjellander): Change back to PresubmitError below when we're |
88 # confident with the lint settings. | 106 # confident with the lint settings. |
89 res_type = output_api.PresubmitPromptWarning | 107 res_type = output_api.PresubmitPromptWarning |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 input_api, | 260 input_api, |
243 output_api, | 261 output_api, |
244 directory, | 262 directory, |
245 whitelist=[r'.+_test\.py$'])) | 263 whitelist=[r'.+_test\.py$'])) |
246 return input_api.RunTests(tests, parallel=True) | 264 return input_api.RunTests(tests, parallel=True) |
247 | 265 |
248 | 266 |
249 def _CommonChecks(input_api, output_api): | 267 def _CommonChecks(input_api, output_api): |
250 """Checks common to both upload and commit.""" | 268 """Checks common to both upload and commit.""" |
251 results = [] | 269 results = [] |
| 270 results.extend(_CheckApprovedFilesLintClean(input_api, output_api)) |
252 results.extend(input_api.canned_checks.RunPylint(input_api, output_api, | 271 results.extend(input_api.canned_checks.RunPylint(input_api, output_api, |
253 black_list=(r'^.*gviz_api\.py$', | 272 black_list=(r'^.*gviz_api\.py$', |
254 r'^.*gaeunit\.py$', | 273 r'^.*gaeunit\.py$', |
255 # Embedded shell-script fakes out pylint. | 274 # Embedded shell-script fakes out pylint. |
256 r'^build[\\\/].*\.py$', | 275 r'^build[\\\/].*\.py$', |
257 r'^buildtools[\\\/].*\.py$', | 276 r'^buildtools[\\\/].*\.py$', |
258 r'^chromium[\\\/].*\.py$', | 277 r'^chromium[\\\/].*\.py$', |
259 r'^google_apis[\\\/].*\.py$', | 278 r'^google_apis[\\\/].*\.py$', |
260 r'^net.*[\\\/].*\.py$', | 279 r'^net.*[\\\/].*\.py$', |
261 r'^out.*[\\\/].*\.py$', | 280 r'^out.*[\\\/].*\.py$', |
(...skipping 29 matching lines...) Expand all Loading... |
291 long_lines_sources = lambda x: input_api.FilterSourceFile(x, | 310 long_lines_sources = lambda x: input_api.FilterSourceFile(x, |
292 black_list=(r'.+\.gyp$', r'.+\.gypi$', r'.+\.gn$', r'.+\.gni$', 'DEPS')) | 311 black_list=(r'.+\.gyp$', r'.+\.gypi$', r'.+\.gn$', r'.+\.gni$', 'DEPS')) |
293 results.extend(input_api.canned_checks.CheckLongLines( | 312 results.extend(input_api.canned_checks.CheckLongLines( |
294 input_api, output_api, maxlen=80, source_file_filter=long_lines_sources)) | 313 input_api, output_api, maxlen=80, source_file_filter=long_lines_sources)) |
295 results.extend(input_api.canned_checks.CheckChangeHasNoTabs( | 314 results.extend(input_api.canned_checks.CheckChangeHasNoTabs( |
296 input_api, output_api)) | 315 input_api, output_api)) |
297 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace( | 316 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace( |
298 input_api, output_api)) | 317 input_api, output_api)) |
299 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner( | 318 results.extend(input_api.canned_checks.CheckChangeTodoHasOwner( |
300 input_api, output_api)) | 319 input_api, output_api)) |
301 results.extend(_CheckApprovedFilesLintClean(input_api, output_api)) | |
302 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) | 320 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) |
303 results.extend(_CheckNoFRIEND_TEST(input_api, output_api)) | 321 results.extend(_CheckNoFRIEND_TEST(input_api, output_api)) |
304 results.extend(_CheckGypChanges(input_api, output_api)) | 322 results.extend(_CheckGypChanges(input_api, output_api)) |
305 results.extend(_CheckUnwantedDependencies(input_api, output_api)) | 323 results.extend(_CheckUnwantedDependencies(input_api, output_api)) |
306 results.extend(_RunPythonTests(input_api, output_api)) | 324 results.extend(_RunPythonTests(input_api, output_api)) |
307 return results | 325 return results |
308 | 326 |
309 | 327 |
310 def CheckChangeOnUpload(input_api, output_api): | 328 def CheckChangeOnUpload(input_api, output_api): |
311 results = [] | 329 results = [] |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 for builder in masters[master]: | 367 for builder in masters[master]: |
350 if 'presubmit' in builder: | 368 if 'presubmit' in builder: |
351 # Do not trigger presubmit builders, since they're likely to fail | 369 # Do not trigger presubmit builders, since they're likely to fail |
352 # (e.g. OWNERS checks before finished code review), and we're running | 370 # (e.g. OWNERS checks before finished code review), and we're running |
353 # local presubmit anyway. | 371 # local presubmit anyway. |
354 pass | 372 pass |
355 else: | 373 else: |
356 try_config[master][builder] = ['defaulttests'] | 374 try_config[master][builder] = ['defaulttests'] |
357 | 375 |
358 return try_config | 376 return try_config |
OLD | NEW |