| 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 os | 10 import os |
| 10 import re | 11 import re |
| 11 import sys | 12 import sys |
| 12 | 13 |
| 13 | 14 |
| 14 # Directories that will be scanned by cpplint by the presubmit script. | 15 # Directories that will be scanned by cpplint by the presubmit script. |
| 15 CPPLINT_DIRS = [ | 16 CPPLINT_DIRS = [ |
| 16 'webrtc/audio', | 17 'webrtc/audio', |
| 17 'webrtc/call', | 18 'webrtc/call', |
| 18 'webrtc/common_video', | 19 'webrtc/common_video', |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 return [output_api.PresubmitError( | 285 return [output_api.PresubmitError( |
| 285 'Referencing source files above the directory of the GN file is not ' | 286 'Referencing source files above the directory of the GN file is not ' |
| 286 'allowed. Please introduce new GN targets in the proper location ' | 287 'allowed. Please introduce new GN targets in the proper location ' |
| 287 'instead.\n' | 288 'instead.\n' |
| 288 'Invalid source entries:\n' | 289 'Invalid source entries:\n' |
| 289 '%s\n' | 290 '%s\n' |
| 290 'Violating GN files:' % '\n'.join(violating_source_entries), | 291 'Violating GN files:' % '\n'.join(violating_source_entries), |
| 291 items=violating_gn_files)] | 292 items=violating_gn_files)] |
| 292 return [] | 293 return [] |
| 293 | 294 |
| 295 def _CheckNoMixingCAndCCSources(input_api, gn_files, output_api): |
| 296 # Disallow mixing .c and .cc source files in the same target. |
| 297 source_pattern = input_api.re.compile(r' +sources \+?= \[(.*?)\]', |
| 298 re.MULTILINE | re.DOTALL) |
| 299 file_pattern = input_api.re.compile(r'"(.*)"') |
| 300 violating_gn_files = dict() |
| 301 for gn_file in gn_files: |
| 302 contents = input_api.ReadFile(gn_file) |
| 303 for source_block_match in source_pattern.finditer(contents): |
| 304 c_files = [] |
| 305 cc_files = [] |
| 306 for file_list_match in file_pattern.finditer(source_block_match.group(1)): |
| 307 source_file = file_list_match.group(1) |
| 308 if source_file.endswith('.c'): |
| 309 c_files.append(source_file) |
| 310 if source_file.endswith('.cc'): |
| 311 cc_files.append(source_file) |
| 312 if c_files and cc_files: |
| 313 violating_gn_files[gn_file.LocalPath()] = sorted(c_files + cc_files) |
| 314 if violating_gn_files: |
| 315 return [output_api.PresubmitError( |
| 316 'GN targets cannot mix .cc and .c source files. Please create a ' |
| 317 'separate target for each collection of sources.\n' |
| 318 'Mixed sources: \n' |
| 319 '%s\n' |
| 320 'Violating GN files:' % json.dumps(violating_gn_files, indent=2), |
| 321 items=violating_gn_files.keys())] |
| 322 return [] |
| 323 |
| 294 def _CheckGnChanges(input_api, output_api): | 324 def _CheckGnChanges(input_api, output_api): |
| 295 source_file_filter = lambda x: input_api.FilterSourceFile( | 325 source_file_filter = lambda x: input_api.FilterSourceFile( |
| 296 x, white_list=(r'.+\.(gn|gni)$',)) | 326 x, white_list=(r'.+\.(gn|gni)$',)) |
| 297 | 327 |
| 298 gn_files = [] | 328 gn_files = [] |
| 299 for f in input_api.AffectedSourceFiles(source_file_filter): | 329 for f in input_api.AffectedSourceFiles(source_file_filter): |
| 300 if f.LocalPath().startswith('webrtc'): | 330 if f.LocalPath().startswith('webrtc'): |
| 301 gn_files.append(f) | 331 gn_files.append(f) |
| 302 | 332 |
| 303 result = [] | 333 result = [] |
| 304 if gn_files: | 334 if gn_files: |
| 305 result.extend(_CheckNoRtcBaseDeps(input_api, gn_files, output_api)) | 335 result.extend(_CheckNoRtcBaseDeps(input_api, gn_files, output_api)) |
| 306 result.extend(_CheckNoSourcesAbove(input_api, gn_files, output_api)) | 336 result.extend(_CheckNoSourcesAbove(input_api, gn_files, output_api)) |
| 337 result.extend(_CheckNoMixingCAndCCSources(input_api, gn_files, output_api)) |
| 307 return result | 338 return result |
| 308 | 339 |
| 309 def _CheckUnwantedDependencies(input_api, output_api): | 340 def _CheckUnwantedDependencies(input_api, output_api): |
| 310 """Runs checkdeps on #include statements added in this | 341 """Runs checkdeps on #include statements added in this |
| 311 change. Breaking - rules is an error, breaking ! rules is a | 342 change. Breaking - rules is an error, breaking ! rules is a |
| 312 warning. | 343 warning. |
| 313 """ | 344 """ |
| 314 # Copied from Chromium's src/PRESUBMIT.py. | 345 # Copied from Chromium's src/PRESUBMIT.py. |
| 315 | 346 |
| 316 # We need to wait until we have an input_api object and use this | 347 # We need to wait until we have an input_api object and use this |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 input_api, output_api)) | 557 input_api, output_api)) |
| 527 results.extend(input_api.canned_checks.CheckChangeHasDescription( | 558 results.extend(input_api.canned_checks.CheckChangeHasDescription( |
| 528 input_api, output_api)) | 559 input_api, output_api)) |
| 529 results.extend(_CheckChangeHasBugField(input_api, output_api)) | 560 results.extend(_CheckChangeHasBugField(input_api, output_api)) |
| 530 results.extend(input_api.canned_checks.CheckChangeHasTestField( | 561 results.extend(input_api.canned_checks.CheckChangeHasTestField( |
| 531 input_api, output_api)) | 562 input_api, output_api)) |
| 532 results.extend(input_api.canned_checks.CheckTreeIsOpen( | 563 results.extend(input_api.canned_checks.CheckTreeIsOpen( |
| 533 input_api, output_api, | 564 input_api, output_api, |
| 534 json_url='http://webrtc-status.appspot.com/current?format=json')) | 565 json_url='http://webrtc-status.appspot.com/current?format=json')) |
| 535 return results | 566 return results |
| OLD | NEW |