maruel@chromium.org | 3d23524 | 2009-05-15 12:40:48 +0000 | [diff] [blame] | 1 | # Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Top-level presubmit script for depot tools. |
| 6 | |
| 7 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for |
| 8 | details on the presubmit API built into gcl. |
| 9 | """ |
| 10 | |
maruel@chromium.org | ce30ef7 | 2009-05-25 15:20:42 +0000 | [diff] [blame] | 11 | UNIT_TESTS = [ |
| 12 | 'tests.gcl_unittest', |
maruel@chromium.org | ad80e3b | 2010-09-09 14:18:28 +0000 | [diff] [blame] | 13 | 'tests.gclient_scm_test', |
maruel@chromium.org | 888b835 | 2010-08-11 18:42:03 +0000 | [diff] [blame] | 14 | 'tests.gclient_smoketest', |
maruel@chromium.org | d5800f1 | 2009-11-12 20:03:43 +0000 | [diff] [blame] | 15 | 'tests.gclient_utils_test', |
maruel@chromium.org | ce30ef7 | 2009-05-25 15:20:42 +0000 | [diff] [blame] | 16 | 'tests.presubmit_unittest', |
maruel@chromium.org | d5800f1 | 2009-11-12 20:03:43 +0000 | [diff] [blame] | 17 | 'tests.scm_unittest', |
maruel@chromium.org | ce30ef7 | 2009-05-25 15:20:42 +0000 | [diff] [blame] | 18 | 'tests.trychange_unittest', |
nirnimesh@chromium.org | b82e409 | 2009-06-18 14:24:08 +0000 | [diff] [blame] | 19 | 'tests.watchlists_unittest', |
maruel@chromium.org | ce30ef7 | 2009-05-25 15:20:42 +0000 | [diff] [blame] | 20 | ] |
maruel@chromium.org | 3d23524 | 2009-05-15 12:40:48 +0000 | [diff] [blame] | 21 | |
| 22 | def CheckChangeOnUpload(input_api, output_api): |
maruel@chromium.org | 7b305e8 | 2009-05-19 18:24:20 +0000 | [diff] [blame] | 23 | output = [] |
| 24 | output.extend(input_api.canned_checks.RunPythonUnitTests(input_api, |
| 25 | output_api, |
maruel@chromium.org | ce30ef7 | 2009-05-25 15:20:42 +0000 | [diff] [blame] | 26 | UNIT_TESTS)) |
maruel@chromium.org | bbfc80f | 2010-06-22 17:55:15 +0000 | [diff] [blame] | 27 | output.extend(WasGitClUploadHookModified(input_api, output_api)) |
maruel@chromium.org | fa41037 | 2010-09-10 17:01:01 +0000 | [diff] [blame] | 28 | output.extend(RunPylint(input_api, output_api)) |
maruel@chromium.org | ce30ef7 | 2009-05-25 15:20:42 +0000 | [diff] [blame] | 29 | return output |
| 30 | |
| 31 | |
| 32 | def CheckChangeOnCommit(input_api, output_api): |
| 33 | output = [] |
| 34 | output.extend(input_api.canned_checks.RunPythonUnitTests(input_api, |
| 35 | output_api, |
| 36 | UNIT_TESTS)) |
maruel@chromium.org | 7b305e8 | 2009-05-19 18:24:20 +0000 | [diff] [blame] | 37 | output.extend(input_api.canned_checks.CheckDoNotSubmit(input_api, |
| 38 | output_api)) |
maruel@chromium.org | bbfc80f | 2010-06-22 17:55:15 +0000 | [diff] [blame] | 39 | output.extend(WasGitClUploadHookModified(input_api, output_api)) |
maruel@chromium.org | fa41037 | 2010-09-10 17:01:01 +0000 | [diff] [blame] | 40 | output.extend(RunPylint(input_api, output_api)) |
maruel@chromium.org | 7b305e8 | 2009-05-19 18:24:20 +0000 | [diff] [blame] | 41 | return output |
maruel@chromium.org | bbfc80f | 2010-06-22 17:55:15 +0000 | [diff] [blame] | 42 | |
| 43 | def WasGitClUploadHookModified(input_api, output_api): |
| 44 | for affected_file in input_api.AffectedSourceFiles(None): |
| 45 | if (input_api.os_path.basename(affected_file.LocalPath()) == |
| 46 | 'git-cl-upload-hook'): |
| 47 | return [output_api.PresubmitPromptWarning( |
| 48 | 'Don\'t forget to fix git-cl to download the newest version of ' |
| 49 | 'git-cl-upload-hook')] |
| 50 | return [] |
maruel@chromium.org | fa41037 | 2010-09-10 17:01:01 +0000 | [diff] [blame] | 51 | |
| 52 | def RunPylint(input_api, output_api): |
| 53 | import glob |
| 54 | files = glob.glob('*.py') |
| 55 | # It's a python script |
| 56 | files.append('git-try') |
| 57 | # It uses non-standard pylint exceptions that makes pylint always fail. |
| 58 | files.remove('cpplint.py') |
maruel@chromium.org | 5631746 | 2010-09-10 20:12:26 +0000 | [diff] [blame] | 59 | try: |
| 60 | proc = input_api.subprocess.Popen(['pylint', '-E'] + files) |
maruel@chromium.org | 1e629b3 | 2010-09-13 18:53:22 +0000 | [diff] [blame^] | 61 | except OSError: |
| 62 | if input_api.platform == 'win32': |
| 63 | # It's windows, give up. |
| 64 | return [] |
| 65 | else: |
| 66 | return [output_api.PresubmitError( |
| 67 | 'Please install pylint with "easy_install pylint"')] |
maruel@chromium.org | fa41037 | 2010-09-10 17:01:01 +0000 | [diff] [blame] | 68 | proc.communicate() |
| 69 | if proc.returncode: |
| 70 | return [output_api.PresubmitError('Fix pylint errors first.')] |
| 71 | return [] |