Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: PRESUBMIT.py

Issue 2629723004: Add presubmit check to prevent package boundary violations. (Closed)
Patch Set: Sort lists before comparing. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools-webrtc/check_package_boundaries.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 sys 13 import sys
13 14
14 15
15 # Directories that will be scanned by cpplint by the presubmit script. 16 # Directories that will be scanned by cpplint by the presubmit script.
16 CPPLINT_DIRS = [ 17 CPPLINT_DIRS = [
17 'webrtc/audio', 18 'webrtc/audio',
18 'webrtc/call', 19 'webrtc/call',
19 'webrtc/common_video', 20 'webrtc/common_video',
20 'webrtc/examples', 21 'webrtc/examples',
21 'webrtc/modules/audio_mixer', 22 'webrtc/modules/audio_mixer',
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 'webrtc/modules/video_coding/codecs/i420/include', 78 'webrtc/modules/video_coding/codecs/i420/include',
78 'webrtc/modules/video_coding/codecs/vp8/include', 79 'webrtc/modules/video_coding/codecs/vp8/include',
79 'webrtc/modules/video_coding/codecs/vp9/include', 80 'webrtc/modules/video_coding/codecs/vp9/include',
80 'webrtc/modules/video_coding/include', 81 'webrtc/modules/video_coding/include',
81 'webrtc/system_wrappers/include', 82 'webrtc/system_wrappers/include',
82 'webrtc/voice_engine/include', 83 'webrtc/voice_engine/include',
83 ) 84 )
84 API_DIRS = NATIVE_API_DIRS[:] + LEGACY_API_DIRS[:] 85 API_DIRS = NATIVE_API_DIRS[:] + LEGACY_API_DIRS[:]
85 86
86 87
88 def _RunCommand(command, cwd):
89 """Runs a command and returns the output from that command."""
90 p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
91 cwd=cwd)
92 stdout = p.stdout.read()
93 stderr = p.stderr.read()
94 p.wait()
95 p.stdout.close()
96 p.stderr.close()
97 return p.returncode, stdout, stderr
98
99
87 def _VerifyNativeApiHeadersListIsValid(input_api, output_api): 100 def _VerifyNativeApiHeadersListIsValid(input_api, output_api):
88 """Ensures the list of native API header directories is up to date.""" 101 """Ensures the list of native API header directories is up to date."""
89 non_existing_paths = [] 102 non_existing_paths = []
90 native_api_full_paths = [ 103 native_api_full_paths = [
91 input_api.os_path.join(input_api.PresubmitLocalPath(), 104 input_api.os_path.join(input_api.PresubmitLocalPath(),
92 *path.split('/')) for path in API_DIRS] 105 *path.split('/')) for path in API_DIRS]
93 for path in native_api_full_paths: 106 for path in native_api_full_paths:
94 if not os.path.isdir(path): 107 if not os.path.isdir(path):
95 non_existing_paths.append(path) 108 non_existing_paths.append(path)
96 if non_existing_paths: 109 if non_existing_paths:
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 if violating_gn_files: 291 if violating_gn_files:
279 return [output_api.PresubmitError( 292 return [output_api.PresubmitError(
280 'GN targets cannot mix .cc and .c source files. Please create a ' 293 'GN targets cannot mix .cc and .c source files. Please create a '
281 'separate target for each collection of sources.\n' 294 'separate target for each collection of sources.\n'
282 'Mixed sources: \n' 295 'Mixed sources: \n'
283 '%s\n' 296 '%s\n'
284 'Violating GN files:' % json.dumps(violating_gn_files, indent=2), 297 'Violating GN files:' % json.dumps(violating_gn_files, indent=2),
285 items=violating_gn_files.keys())] 298 items=violating_gn_files.keys())]
286 return [] 299 return []
287 300
301 def _CheckNoPackageBoundaryViolations(input_api, gn_files, output_api):
302 cwd = input_api.PresubmitLocalPath()
303 script_path = os.path.join('tools-webrtc', 'check_package_boundaries.py')
304 webrtc_path = os.path.join('webrtc')
305 command = [sys.executable, script_path, webrtc_path]
306 command += [gn_file.LocalPath() for gn_file in gn_files]
307 returncode, _, stderr = _RunCommand(command, cwd)
308 if returncode:
309 return [output_api.PresubmitError(
310 'There are package boundary violations in the following GN files:\n\n'
311 '%s' % stderr)]
312 return []
313
288 def _CheckGnChanges(input_api, output_api): 314 def _CheckGnChanges(input_api, output_api):
289 source_file_filter = lambda x: input_api.FilterSourceFile( 315 source_file_filter = lambda x: input_api.FilterSourceFile(
290 x, white_list=(r'.+\.(gn|gni)$',)) 316 x, white_list=(r'.+\.(gn|gni)$',))
291 317
292 gn_files = [] 318 gn_files = []
293 for f in input_api.AffectedSourceFiles(source_file_filter): 319 for f in input_api.AffectedSourceFiles(source_file_filter):
294 if f.LocalPath().startswith('webrtc'): 320 if f.LocalPath().startswith('webrtc'):
295 gn_files.append(f) 321 gn_files.append(f)
296 322
297 result = [] 323 result = []
298 if gn_files: 324 if gn_files:
299 result.extend(_CheckNoSourcesAbove(input_api, gn_files, output_api)) 325 result.extend(_CheckNoSourcesAbove(input_api, gn_files, output_api))
300 result.extend(_CheckNoMixingCAndCCSources(input_api, gn_files, output_api)) 326 result.extend(_CheckNoMixingCAndCCSources(input_api, gn_files, output_api))
327 result.extend(_CheckNoPackageBoundaryViolations(
328 input_api, gn_files, output_api))
301 return result 329 return result
302 330
303 def _CheckUnwantedDependencies(input_api, output_api): 331 def _CheckUnwantedDependencies(input_api, output_api):
304 """Runs checkdeps on #include statements added in this 332 """Runs checkdeps on #include statements added in this
305 change. Breaking - rules is an error, breaking ! rules is a 333 change. Breaking - rules is an error, breaking ! rules is a
306 warning. 334 warning.
307 """ 335 """
308 # Copied from Chromium's src/PRESUBMIT.py. 336 # Copied from Chromium's src/PRESUBMIT.py.
309 337
310 # We need to wait until we have an input_api object and use this 338 # We need to wait until we have an input_api object and use this
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 results.append(output_api.PresubmitError('%s could not be parsed: %s' % 426 results.append(output_api.PresubmitError('%s could not be parsed: %s' %
399 (affected_file.LocalPath(), parse_error))) 427 (affected_file.LocalPath(), parse_error)))
400 return results 428 return results
401 429
402 430
403 def _RunPythonTests(input_api, output_api): 431 def _RunPythonTests(input_api, output_api):
404 def join(*args): 432 def join(*args):
405 return input_api.os_path.join(input_api.PresubmitLocalPath(), *args) 433 return input_api.os_path.join(input_api.PresubmitLocalPath(), *args)
406 434
407 test_directories = [ 435 test_directories = [
408 join('tools-webrtc', 'autoroller', 'unittests'), 436 join('webrtc', 'tools', 'py_event_log_analyzer')
409 join('webrtc', 'tools', 'py_event_log_analyzer'), 437 ] + [
438 root for root, _, files in os.walk(join('tools-webrtc'))
439 if any(f.endswith('_test.py') for f in files)
410 ] 440 ]
411 441
412 tests = [] 442 tests = []
413 for directory in test_directories: 443 for directory in test_directories:
414 tests.extend( 444 tests.extend(
415 input_api.canned_checks.GetUnitTestsInDirectory( 445 input_api.canned_checks.GetUnitTestsInDirectory(
416 input_api, 446 input_api,
417 output_api, 447 output_api,
418 directory, 448 directory,
419 whitelist=[r'.+_test\.py$'])) 449 whitelist=[r'.+_test\.py$']))
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 input_api, output_api)) 537 input_api, output_api))
508 results.extend(input_api.canned_checks.CheckChangeHasDescription( 538 results.extend(input_api.canned_checks.CheckChangeHasDescription(
509 input_api, output_api)) 539 input_api, output_api))
510 results.extend(_CheckChangeHasBugField(input_api, output_api)) 540 results.extend(_CheckChangeHasBugField(input_api, output_api))
511 results.extend(input_api.canned_checks.CheckChangeHasTestField( 541 results.extend(input_api.canned_checks.CheckChangeHasTestField(
512 input_api, output_api)) 542 input_api, output_api))
513 results.extend(input_api.canned_checks.CheckTreeIsOpen( 543 results.extend(input_api.canned_checks.CheckTreeIsOpen(
514 input_api, output_api, 544 input_api, output_api,
515 json_url='http://webrtc-status.appspot.com/current?format=json')) 545 json_url='http://webrtc-status.appspot.com/current?format=json'))
516 return results 546 return results
OLDNEW
« no previous file with comments | « no previous file | tools-webrtc/check_package_boundaries.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698