| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Top-level presubmit script for Chromium. | 5 """Top-level presubmit script for Chromium. |
| 6 | 6 |
| 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 8 for more details about the presubmit API built into gcl. | 8 for more details about the presubmit API built into gcl. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 # Outsource work to gclient verify | 405 # Outsource work to gclient verify |
| 406 try: | 406 try: |
| 407 input_api.subprocess.check_output(['gclient', 'verify']) | 407 input_api.subprocess.check_output(['gclient', 'verify']) |
| 408 return [] | 408 return [] |
| 409 except input_api.subprocess.CalledProcessError, error: | 409 except input_api.subprocess.CalledProcessError, error: |
| 410 return [output_api.PresubmitError( | 410 return [output_api.PresubmitError( |
| 411 'DEPS file must have only git dependencies.', | 411 'DEPS file must have only git dependencies.', |
| 412 long_text=error.output)] | 412 long_text=error.output)] |
| 413 | 413 |
| 414 | 414 |
| 415 def _CheckGNCheck(input_api, output_api): |
| 416 """Checks that gn gen and gn check pass""" |
| 417 |
| 418 class _TemporaryDirectory(object): |
| 419 """Context manager for tempfile.mkdtemp()""" |
| 420 def __init__(self, parent_dir=None): |
| 421 self.parent_dir = parent_dir |
| 422 |
| 423 def __enter__(self): |
| 424 self.path = input_api.tempfile.mkdtemp(dir=self.parent_dir) |
| 425 return self.path |
| 426 |
| 427 def __exit__(self, exc_type, exc_value, traceback): |
| 428 # input_api does not include shutil or any nice way to delete |
| 429 # a directory, so we hackishly import it here. |
| 430 import shutil |
| 431 shutil.rmtree(self.path) |
| 432 |
| 433 # TODO(eseidel): We should not have to pass dir= here but unfortunately |
| 434 # gn's rebase_path can't handle absolute paths! crbug.com/429324 |
| 435 temp_parent = input_api.change.RepositoryRoot() |
| 436 with _TemporaryDirectory(parent_dir=temp_parent) as out_dir: |
| 437 relative_out_dir = input_api.os_path.relpath(out_dir, temp_parent) |
| 438 try: |
| 439 input_api.subprocess.check_output(['gn', 'gen', relative_out_dir]) |
| 440 except input_api.subprocess.CalledProcessError, error: |
| 441 return [output_api.PresubmitError( |
| 442 'gn gen must not fail.', long_text=error.output)] |
| 443 |
| 444 # TODO(eseidel): Currently only these are known to pass, |
| 445 # once everything passes we can just call 'gn check' once without a filter! |
| 446 KNOWN_PASSING = [ |
| 447 '//sky/*', |
| 448 '//mojo/public/*', |
| 449 ] |
| 450 for target_filter in KNOWN_PASSING: |
| 451 try: |
| 452 input_api.subprocess.check_output(['gn', 'check', relative_out_dir, |
| 453 target_filter]) |
| 454 except input_api.subprocess.CalledProcessError, error: |
| 455 error_title = 'gn check %s must not fail.' % target_filter |
| 456 return [output_api.PresubmitError(error_title, long_text=error.output)] |
| 457 return [] |
| 458 |
| 459 |
| 415 def _CheckNoBannedFunctions(input_api, output_api): | 460 def _CheckNoBannedFunctions(input_api, output_api): |
| 416 """Make sure that banned functions are not used.""" | 461 """Make sure that banned functions are not used.""" |
| 417 warnings = [] | 462 warnings = [] |
| 418 errors = [] | 463 errors = [] |
| 419 | 464 |
| 420 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h')) | 465 file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h')) |
| 421 for f in input_api.AffectedFiles(file_filter=file_filter): | 466 for f in input_api.AffectedFiles(file_filter=file_filter): |
| 422 for line_num, line in f.ChangedContents(): | 467 for line_num, line in f.ChangedContents(): |
| 423 for func_name, message, error in _BANNED_OBJC_FUNCTIONS: | 468 for func_name, message, error in _BANNED_OBJC_FUNCTIONS: |
| 424 matched = False | 469 matched = False |
| (...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 output_api, | 1330 output_api, |
| 1286 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) | 1331 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) |
| 1287 results.extend(_CheckSpamLogging(input_api, output_api)) | 1332 results.extend(_CheckSpamLogging(input_api, output_api)) |
| 1288 results.extend(_CheckForAnonymousVariables(input_api, output_api)) | 1333 results.extend(_CheckForAnonymousVariables(input_api, output_api)) |
| 1289 results.extend(_CheckCygwinShell(input_api, output_api)) | 1334 results.extend(_CheckCygwinShell(input_api, output_api)) |
| 1290 results.extend(_CheckUserActionUpdate(input_api, output_api)) | 1335 results.extend(_CheckUserActionUpdate(input_api, output_api)) |
| 1291 results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) | 1336 results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) |
| 1292 results.extend(_CheckParseErrors(input_api, output_api)) | 1337 results.extend(_CheckParseErrors(input_api, output_api)) |
| 1293 results.extend(_CheckForIPCRules(input_api, output_api)) | 1338 results.extend(_CheckForIPCRules(input_api, output_api)) |
| 1294 results.extend(_CheckForOverrideAndFinalRules(input_api, output_api)) | 1339 results.extend(_CheckForOverrideAndFinalRules(input_api, output_api)) |
| 1340 results.extend(_CheckGNCheck(input_api, output_api)) |
| 1295 | 1341 |
| 1296 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): | 1342 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): |
| 1297 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( | 1343 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( |
| 1298 input_api, output_api, | 1344 input_api, output_api, |
| 1299 input_api.PresubmitLocalPath(), | 1345 input_api.PresubmitLocalPath(), |
| 1300 whitelist=[r'^PRESUBMIT_test\.py$'])) | 1346 whitelist=[r'^PRESUBMIT_test\.py$'])) |
| 1301 return results | 1347 return results |
| 1302 | 1348 |
| 1303 | 1349 |
| 1304 def _CheckAuthorizedAuthor(input_api, output_api): | 1350 def _CheckAuthorizedAuthor(input_api, output_api): |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1698 builders.extend(['cros_x86']) | 1744 builders.extend(['cros_x86']) |
| 1699 | 1745 |
| 1700 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it | 1746 # The AOSP bot doesn't build the chrome/ layer, so ignore any changes to it |
| 1701 # unless they're .gyp(i) files as changes to those files can break the gyp | 1747 # unless they're .gyp(i) files as changes to those files can break the gyp |
| 1702 # step on that bot. | 1748 # step on that bot. |
| 1703 if (not all(re.search('^chrome', f) for f in files) or | 1749 if (not all(re.search('^chrome', f) for f in files) or |
| 1704 any(re.search('\.gypi?$', f) for f in files)): | 1750 any(re.search('\.gypi?$', f) for f in files)): |
| 1705 builders.extend(['android_aosp']) | 1751 builders.extend(['android_aosp']) |
| 1706 | 1752 |
| 1707 return GetDefaultTryConfigs(builders) | 1753 return GetDefaultTryConfigs(builders) |
| OLD | NEW |