| 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 re | 11 import re |
| 12 import subprocess | 12 import subprocess |
| 13 import sys | 13 import sys |
| 14 | 14 |
| 15 | 15 |
| 16 # Directories that will be scanned by cpplint by the presubmit script. | 16 # Files and directories that are *skipped* by cpplint in the presubmit script. |
| 17 CPPLINT_DIRS = [ | 17 CPPLINT_BLACKLIST = [ |
| 18 'webrtc/api', | 18 'tools-webrtc', |
| 19 'webrtc/audio', | 19 'webrtc/base', |
| 20 'webrtc/call', | 20 'webrtc/examples/objc', |
| 21 'webrtc/common_audio', | 21 'webrtc/media', |
| 22 'webrtc/common_video', | 22 'webrtc/modules/audio_coding', |
| 23 'webrtc/examples', | 23 'webrtc/modules/audio_conference_mixer', |
| 24 'webrtc/modules/audio_mixer', | 24 'webrtc/modules/audio_device', |
| 25 'webrtc/modules/bitrate_controller', | 25 'webrtc/modules/audio_processing', |
| 26 'webrtc/modules/congestion_controller', | 26 'webrtc/modules/desktop_capture', |
| 27 'webrtc/modules/pacing', | 27 'webrtc/modules/include/module_common_types.h', |
| 28 'webrtc/modules/remote_bitrate_estimator', | 28 'webrtc/modules/media_file', |
| 29 'webrtc/modules/rtp_rtcp', | 29 'webrtc/modules/utility', |
| 30 'webrtc/modules/video_coding', | 30 'webrtc/modules/video_capture', |
| 31 'webrtc/modules/video_processing', | 31 'webrtc/p2p', |
| 32 'webrtc/tools', | 32 'webrtc/pc', |
| 33 'webrtc/video', | 33 'webrtc/sdk/android/src/jni', |
| 34 'webrtc/sdk/objc', |
| 35 'webrtc/system_wrappers', |
| 36 'webrtc/test', |
| 37 'webrtc/voice_engine', |
| 38 'webrtc/call.h', |
| 39 'webrtc/common_types.h', |
| 40 'webrtc/common_types.cc', |
| 41 'webrtc/video_decoder.h', |
| 42 'webrtc/video_encoder.h', |
| 43 'webrtc/video_send_stream.h', |
| 34 ] | 44 ] |
| 35 | 45 |
| 36 # These filters will always be removed, even if the caller specifies a filter | 46 # These filters will always be removed, even if the caller specifies a filter |
| 37 # set, as they are problematic or broken in some way. | 47 # set, as they are problematic or broken in some way. |
| 38 # | 48 # |
| 39 # Justifications for each filter: | 49 # Justifications for each filter: |
| 40 # - build/c++11 : Rvalue ref checks are unreliable (false positives), | 50 # - build/c++11 : Rvalue ref checks are unreliable (false positives), |
| 41 # include file and feature blacklists are | 51 # include file and feature blacklists are |
| 42 # google3-specific. | 52 # google3-specific. |
| 43 # - whitespace/operators: Same as above (doesn't seem sufficient to eliminate | 53 # - whitespace/operators: Same as above (doesn't seem sufficient to eliminate |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 if 'FRIEND_TEST(' in line: | 212 if 'FRIEND_TEST(' in line: |
| 203 problems.append(' %s:%d' % (f.LocalPath(), line_num)) | 213 problems.append(' %s:%d' % (f.LocalPath(), line_num)) |
| 204 | 214 |
| 205 if not problems: | 215 if not problems: |
| 206 return [] | 216 return [] |
| 207 return [output_api.PresubmitPromptWarning('WebRTC\'s code should not use ' | 217 return [output_api.PresubmitPromptWarning('WebRTC\'s code should not use ' |
| 208 'gtest\'s FRIEND_TEST() macro. Include testsupport/gtest_prod_util.h and ' | 218 'gtest\'s FRIEND_TEST() macro. Include testsupport/gtest_prod_util.h and ' |
| 209 'use FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))] | 219 'use FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))] |
| 210 | 220 |
| 211 | 221 |
| 212 def _IsLintWhitelisted(whitelist_dirs, file_path): | 222 def _IsLintBlacklisted(blacklist_paths, file_path): |
| 213 """ Checks if a file is whitelisted for lint check.""" | 223 """ Checks if a file is blacklisted for lint check.""" |
| 214 for path in whitelist_dirs: | 224 for path in blacklist_paths: |
| 215 if os.path.dirname(file_path).startswith(path): | 225 if file_path == path or os.path.dirname(file_path).startswith(path): |
| 216 return True | 226 return True |
| 217 return False | 227 return False |
| 218 | 228 |
| 219 | 229 |
| 220 def _CheckApprovedFilesLintClean(input_api, output_api, | 230 def _CheckApprovedFilesLintClean(input_api, output_api, |
| 221 source_file_filter=None): | 231 source_file_filter=None): |
| 222 """Checks that all new or whitelisted .cc and .h files pass cpplint.py. | 232 """Checks that all new or non-blacklisted .cc and .h files pass cpplint.py. |
| 223 This check is based on _CheckChangeLintsClean in | 233 This check is based on _CheckChangeLintsClean in |
| 224 depot_tools/presubmit_canned_checks.py but has less filters and only checks | 234 depot_tools/presubmit_canned_checks.py but has less filters and only checks |
| 225 added files.""" | 235 added files.""" |
| 226 result = [] | 236 result = [] |
| 227 | 237 |
| 228 # Initialize cpplint. | 238 # Initialize cpplint. |
| 229 import cpplint | 239 import cpplint |
| 230 # Access to a protected member _XX of a client class | 240 # Access to a protected member _XX of a client class |
| 231 # pylint: disable=W0212 | 241 # pylint: disable=W0212 |
| 232 cpplint._cpplint_state.ResetErrorCounts() | 242 cpplint._cpplint_state.ResetErrorCounts() |
| 233 | 243 |
| 234 lint_filters = cpplint._Filters() | 244 lint_filters = cpplint._Filters() |
| 235 lint_filters.extend(BLACKLIST_LINT_FILTERS) | 245 lint_filters.extend(BLACKLIST_LINT_FILTERS) |
| 236 cpplint._SetFilters(','.join(lint_filters)) | 246 cpplint._SetFilters(','.join(lint_filters)) |
| 237 | 247 |
| 238 # Create a platform independent whitelist for the CPPLINT_DIRS. | 248 # Create a platform independent blacklist for cpplint. |
| 239 whitelist_dirs = [input_api.os_path.join(*path.split('/')) | 249 blacklist_paths = [input_api.os_path.join(*path.split('/')) |
| 240 for path in CPPLINT_DIRS] | 250 for path in CPPLINT_BLACKLIST] |
| 241 | 251 |
| 242 # Use the strictest verbosity level for cpplint.py (level 1) which is the | 252 # Use the strictest verbosity level for cpplint.py (level 1) which is the |
| 243 # default when running cpplint.py from command line. | 253 # default when running cpplint.py from command line. To make it possible to |
| 244 # To make it possible to work with not-yet-converted code, we're only applying | 254 # work with not-yet-converted code, we're only applying it to new (or |
| 245 # it to new (or moved/renamed) files and files listed in LINT_FOLDERS. | 255 # moved/renamed) files and files not listed in CPPLINT_BLACKLIST. |
| 246 verbosity_level = 1 | 256 verbosity_level = 1 |
| 247 files = [] | 257 files = [] |
| 248 for f in input_api.AffectedSourceFiles(source_file_filter): | 258 for f in input_api.AffectedSourceFiles(source_file_filter): |
| 249 # Note that moved/renamed files also count as added. | 259 # Note that moved/renamed files also count as added. |
| 250 if f.Action() == 'A' or _IsLintWhitelisted(whitelist_dirs, f.LocalPath()): | 260 if f.Action() == 'A' or not _IsLintBlacklisted(blacklist_paths, |
| 261 f.LocalPath()): |
| 251 files.append(f.AbsoluteLocalPath()) | 262 files.append(f.AbsoluteLocalPath()) |
| 252 | 263 |
| 253 for file_name in files: | 264 for file_name in files: |
| 254 cpplint.ProcessFile(file_name, verbosity_level) | 265 cpplint.ProcessFile(file_name, verbosity_level) |
| 255 | 266 |
| 256 if cpplint._cpplint_state.error_count > 0: | 267 if cpplint._cpplint_state.error_count > 0: |
| 257 if input_api.is_committing: | 268 if input_api.is_committing: |
| 258 # TODO(kjellander): Change back to PresubmitError below when we're | 269 # TODO(kjellander): Change back to PresubmitError below when we're |
| 259 # confident with the lint settings. | 270 # confident with the lint settings. |
| 260 res_type = output_api.PresubmitPromptWarning | 271 res_type = output_api.PresubmitPromptWarning |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 input_api, output_api)) | 572 input_api, output_api)) |
| 562 results.extend(input_api.canned_checks.CheckChangeHasDescription( | 573 results.extend(input_api.canned_checks.CheckChangeHasDescription( |
| 563 input_api, output_api)) | 574 input_api, output_api)) |
| 564 results.extend(_CheckChangeHasBugField(input_api, output_api)) | 575 results.extend(_CheckChangeHasBugField(input_api, output_api)) |
| 565 results.extend(input_api.canned_checks.CheckChangeHasTestField( | 576 results.extend(input_api.canned_checks.CheckChangeHasTestField( |
| 566 input_api, output_api)) | 577 input_api, output_api)) |
| 567 results.extend(input_api.canned_checks.CheckTreeIsOpen( | 578 results.extend(input_api.canned_checks.CheckTreeIsOpen( |
| 568 input_api, output_api, | 579 input_api, output_api, |
| 569 json_url='http://webrtc-status.appspot.com/current?format=json')) | 580 json_url='http://webrtc-status.appspot.com/current?format=json')) |
| 570 return results | 581 return results |
| OLD | NEW |