chase@chromium.org | b9a9832 | 2010-12-23 22:32:45 +0000 | [diff] [blame] | 1 | # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
maruel@chromium.org | 3d23524 | 2009-05-15 12:40:48 +0000 | [diff] [blame] | 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', |
dpranke@chromium.org | 5fe603e | 2011-03-09 21:02:50 +0000 | [diff] [blame] | 16 | 'tests.owners_unittest', |
maruel@chromium.org | ce30ef7 | 2009-05-25 15:20:42 +0000 | [diff] [blame] | 17 | 'tests.presubmit_unittest', |
maruel@chromium.org | d5800f1 | 2009-11-12 20:03:43 +0000 | [diff] [blame] | 18 | 'tests.scm_unittest', |
maruel@chromium.org | ce30ef7 | 2009-05-25 15:20:42 +0000 | [diff] [blame] | 19 | 'tests.trychange_unittest', |
nirnimesh@chromium.org | b82e409 | 2009-06-18 14:24:08 +0000 | [diff] [blame] | 20 | 'tests.watchlists_unittest', |
maruel@chromium.org | ce30ef7 | 2009-05-25 15:20:42 +0000 | [diff] [blame] | 21 | ] |
maruel@chromium.org | 3d23524 | 2009-05-15 12:40:48 +0000 | [diff] [blame] | 22 | |
dpranke@chromium.org | 627ea67 | 2011-03-11 23:29:03 +0000 | [diff] [blame^] | 23 | |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 24 | def CommonChecks(input_api, output_api): |
maruel@chromium.org | 7b305e8 | 2009-05-19 18:24:20 +0000 | [diff] [blame] | 25 | output = [] |
maruel@chromium.org | 5d0dc43 | 2011-01-03 02:40:37 +0000 | [diff] [blame] | 26 | # Verify that LocalPath() is local, e.g.: |
| 27 | # os.path.join(PresubmitLocalPath(), LocalPath()) == AbsoluteLocalPath() |
| 28 | for i in input_api.AffectedFiles(): |
| 29 | if (input_api.os_path.join(input_api.PresubmitLocalPath(), i.LocalPath()) != |
| 30 | i.AbsoluteLocalPath()): |
| 31 | output.append(output_api.PresubmitError('Path inconsistency')) |
| 32 | # Return right away because it needs to be fixed first. |
| 33 | return output |
| 34 | |
dpranke@chromium.org | 627ea67 | 2011-03-11 23:29:03 +0000 | [diff] [blame^] | 35 | # TODO(dpranke): uncomment and enable :). |
| 36 | # |
| 37 | # output.extend(input_api.canned_checks.CheckOwners( |
| 38 | # input_api, |
| 39 | # output_api)) |
dpranke@chromium.org | 3ae183f | 2011-03-09 21:40:32 +0000 | [diff] [blame] | 40 | |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 41 | output.extend(input_api.canned_checks.RunPythonUnitTests( |
| 42 | input_api, |
| 43 | output_api, |
| 44 | UNIT_TESTS)) |
maruel@chromium.org | bbfc80f | 2010-06-22 17:55:15 +0000 | [diff] [blame] | 45 | output.extend(WasGitClUploadHookModified(input_api, output_api)) |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 46 | |
maruel@chromium.org | 5d0dc43 | 2011-01-03 02:40:37 +0000 | [diff] [blame] | 47 | white_list = [r'.*\.py$', r'^git-try$'] |
maruel@chromium.org | bf38a7e | 2010-12-14 18:15:54 +0000 | [diff] [blame] | 48 | black_list = list(input_api.DEFAULT_BLACK_LIST) + [ |
maruel@chromium.org | 5d0dc43 | 2011-01-03 02:40:37 +0000 | [diff] [blame] | 49 | r'^cpplint\.py$', |
| 50 | r'^git_cl[\/\\].*', |
| 51 | r'^git_cl_repo[\/\\].*', |
| 52 | r'^git_cl[\/\\]test[\/\\]rietveld.*'] |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 53 | output.extend(input_api.canned_checks.RunPylint( |
| 54 | input_api, |
| 55 | output_api, |
maruel@chromium.org | bf38a7e | 2010-12-14 18:15:54 +0000 | [diff] [blame] | 56 | white_list=white_list, |
| 57 | black_list=black_list)) |
maruel@chromium.org | ce30ef7 | 2009-05-25 15:20:42 +0000 | [diff] [blame] | 58 | return output |
| 59 | |
| 60 | |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 61 | def CheckChangeOnUpload(input_api, output_api): |
| 62 | return CommonChecks(input_api, output_api) |
| 63 | |
| 64 | |
maruel@chromium.org | ce30ef7 | 2009-05-25 15:20:42 +0000 | [diff] [blame] | 65 | def CheckChangeOnCommit(input_api, output_api): |
| 66 | output = [] |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 67 | output.extend(CommonChecks(input_api, output_api)) |
| 68 | output.extend(input_api.canned_checks.CheckDoNotSubmit( |
| 69 | input_api, |
| 70 | output_api)) |
maruel@chromium.org | 7b305e8 | 2009-05-19 18:24:20 +0000 | [diff] [blame] | 71 | return output |
maruel@chromium.org | bbfc80f | 2010-06-22 17:55:15 +0000 | [diff] [blame] | 72 | |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 73 | |
maruel@chromium.org | bbfc80f | 2010-06-22 17:55:15 +0000 | [diff] [blame] | 74 | def WasGitClUploadHookModified(input_api, output_api): |
| 75 | for affected_file in input_api.AffectedSourceFiles(None): |
| 76 | if (input_api.os_path.basename(affected_file.LocalPath()) == |
| 77 | 'git-cl-upload-hook'): |
| 78 | return [output_api.PresubmitPromptWarning( |
| 79 | 'Don\'t forget to fix git-cl to download the newest version of ' |
| 80 | 'git-cl-upload-hook')] |
| 81 | return [] |