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 | |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame^] | 22 | def CommonChecks(input_api, output_api): |
maruel@chromium.org | 7b305e8 | 2009-05-19 18:24:20 +0000 | [diff] [blame] | 23 | output = [] |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame^] | 24 | output.extend(input_api.canned_checks.RunPythonUnitTests( |
| 25 | input_api, |
| 26 | output_api, |
| 27 | UNIT_TESTS)) |
maruel@chromium.org | bbfc80f | 2010-06-22 17:55:15 +0000 | [diff] [blame] | 28 | output.extend(WasGitClUploadHookModified(input_api, output_api)) |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame^] | 29 | |
| 30 | def filter_python_sources(affected_file): |
| 31 | filepath = affected_file.LocalPath() |
| 32 | return ((filepath.endswith('.py') and |
| 33 | filepath != 'cpplint.py' and |
| 34 | not filepath.startswith('tests')) or |
| 35 | filepath == 'git-try') |
| 36 | |
| 37 | output.extend(input_api.canned_checks.RunPylint( |
| 38 | input_api, |
| 39 | output_api, |
| 40 | source_file_filter=filter_python_sources)) |
maruel@chromium.org | ce30ef7 | 2009-05-25 15:20:42 +0000 | [diff] [blame] | 41 | return output |
| 42 | |
| 43 | |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame^] | 44 | def CheckChangeOnUpload(input_api, output_api): |
| 45 | return CommonChecks(input_api, output_api) |
| 46 | |
| 47 | |
maruel@chromium.org | ce30ef7 | 2009-05-25 15:20:42 +0000 | [diff] [blame] | 48 | def CheckChangeOnCommit(input_api, output_api): |
| 49 | output = [] |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame^] | 50 | output.extend(CommonChecks(input_api, output_api)) |
| 51 | output.extend(input_api.canned_checks.CheckDoNotSubmit( |
| 52 | input_api, |
| 53 | output_api)) |
maruel@chromium.org | 7b305e8 | 2009-05-19 18:24:20 +0000 | [diff] [blame] | 54 | return output |
maruel@chromium.org | bbfc80f | 2010-06-22 17:55:15 +0000 | [diff] [blame] | 55 | |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame^] | 56 | |
maruel@chromium.org | bbfc80f | 2010-06-22 17:55:15 +0000 | [diff] [blame] | 57 | def WasGitClUploadHookModified(input_api, output_api): |
| 58 | for affected_file in input_api.AffectedSourceFiles(None): |
| 59 | if (input_api.os_path.basename(affected_file.LocalPath()) == |
| 60 | 'git-cl-upload-hook'): |
| 61 | return [output_api.PresubmitPromptWarning( |
| 62 | 'Don\'t forget to fix git-cl to download the newest version of ' |
| 63 | 'git-cl-upload-hook')] |
| 64 | return [] |