chrisha@chromium.org | c920ad2 | 2012-02-02 18:26:04 +0000 | [diff] [blame] | 1 | # Copyright (c) 2012 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 |
maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 8 | details on the presubmit API built into depot_tools. |
maruel@chromium.org | 3d23524 | 2009-05-15 12:40:48 +0000 | [diff] [blame] | 9 | """ |
| 10 | |
szager@chromium.org | 3407103 | 2014-03-18 17:23:48 +0000 | [diff] [blame] | 11 | import fnmatch |
| 12 | import os |
| 13 | |
dpranke@chromium.org | 627ea67 | 2011-03-11 23:29:03 +0000 | [diff] [blame] | 14 | |
Vadim Shtayura | 0909885 | 2018-06-21 22:50:30 +0000 | [diff] [blame] | 15 | # CIPD ensure manifest for checking CIPD client itself. |
| 16 | CIPD_CLIENT_ENSURE_FILE_TEMPLATE = r''' |
| 17 | # Full supported. |
| 18 | $VerifiedPlatform linux-amd64 mac-amd64 windows-amd64 windows-386 |
| 19 | # Best effort support. |
| 20 | $VerifiedPlatform linux-386 linux-ppc64 linux-ppc64le linux-s390x |
| 21 | $VerifiedPlatform linux-arm64 linux-armv6l linux-mips64 |
Robert Iannucci | 7d47eb5 | 2017-12-06 12:18:18 -0800 | [diff] [blame] | 22 | |
| 23 | %s %s |
| 24 | ''' |
| 25 | |
| 26 | |
agable | f39c333 | 2016-09-26 09:35:42 -0700 | [diff] [blame] | 27 | def DepotToolsPylint(input_api, output_api): |
| 28 | """Gather all the pylint logic into one place to make it self-contained.""" |
| 29 | white_list = [ |
| 30 | r'^[^/]*\.py$', |
| 31 | r'^testing_support/[^/]*\.py$', |
| 32 | r'^tests/[^/]*\.py$', |
| 33 | r'^recipe_modules/.*\.py$', # Allow recursive search in recipe modules. |
tandrii@chromium.org | 55cb27e | 2016-05-16 17:54:40 +0000 | [diff] [blame] | 34 | ] |
agable | f39c333 | 2016-09-26 09:35:42 -0700 | [diff] [blame] | 35 | black_list = list(input_api.DEFAULT_BLACK_LIST) |
szager@chromium.org | 3407103 | 2014-03-18 17:23:48 +0000 | [diff] [blame] | 36 | if os.path.exists('.gitignore'): |
| 37 | with open('.gitignore') as fh: |
| 38 | lines = [l.strip() for l in fh.readlines()] |
| 39 | black_list.extend([fnmatch.translate(l) for l in lines if |
| 40 | l and not l.startswith('#')]) |
| 41 | if os.path.exists('.git/info/exclude'): |
| 42 | with open('.git/info/exclude') as fh: |
| 43 | lines = [l.strip() for l in fh.readlines()] |
| 44 | black_list.extend([fnmatch.translate(l) for l in lines if |
| 45 | l and not l.startswith('#')]) |
maruel@chromium.org | ff9a217 | 2012-04-24 16:55:32 +0000 | [diff] [blame] | 46 | disabled_warnings = [ |
| 47 | 'R0401', # Cyclic import |
| 48 | 'W0613', # Unused argument |
| 49 | ] |
agable | f39c333 | 2016-09-26 09:35:42 -0700 | [diff] [blame] | 50 | return input_api.canned_checks.GetPylint( |
scottmg@chromium.org | 69ae86a | 2014-01-17 03:55:45 +0000 | [diff] [blame] | 51 | input_api, |
| 52 | output_api, |
agable | f39c333 | 2016-09-26 09:35:42 -0700 | [diff] [blame] | 53 | white_list=white_list, |
scottmg@chromium.org | 69ae86a | 2014-01-17 03:55:45 +0000 | [diff] [blame] | 54 | black_list=black_list, |
| 55 | disabled_warnings=disabled_warnings) |
agable | f39c333 | 2016-09-26 09:35:42 -0700 | [diff] [blame] | 56 | |
| 57 | |
| 58 | def CommonChecks(input_api, output_api, tests_to_black_list): |
| 59 | results = [] |
| 60 | results.extend(input_api.canned_checks.CheckOwners(input_api, output_api)) |
Edward Lesmes | cb62e48 | 2018-04-19 18:29:35 -0400 | [diff] [blame] | 61 | results.extend(input_api.canned_checks.CheckOwnersFormat( |
| 62 | input_api, output_api)) |
Vadim Shtayura | 7e50ee3 | 2018-07-26 17:43:51 +0000 | [diff] [blame^] | 63 | |
| 64 | # Run only selected tests on Windows. |
| 65 | tests_to_white_list = [r'.*test\.py$'] |
| 66 | if input_api.platform.startswith(('cygwin', 'win32')): |
| 67 | print('Warning: skipping most unit tests on Windows') |
| 68 | tests_to_white_list = [r'.*cipd_bootstrap_test\.py$'] |
| 69 | |
scottmg@chromium.org | 69ae86a | 2014-01-17 03:55:45 +0000 | [diff] [blame] | 70 | # TODO(maruel): Make sure at least one file is modified first. |
| 71 | # TODO(maruel): If only tests are modified, only run them. |
agable | f39c333 | 2016-09-26 09:35:42 -0700 | [diff] [blame] | 72 | tests = DepotToolsPylint(input_api, output_api) |
Vadim Shtayura | 7e50ee3 | 2018-07-26 17:43:51 +0000 | [diff] [blame^] | 73 | tests.extend(input_api.canned_checks.GetUnitTestsInDirectory( |
scottmg@chromium.org | 69ae86a | 2014-01-17 03:55:45 +0000 | [diff] [blame] | 74 | input_api, |
| 75 | output_api, |
| 76 | 'tests', |
Vadim Shtayura | 7e50ee3 | 2018-07-26 17:43:51 +0000 | [diff] [blame^] | 77 | whitelist=tests_to_white_list, |
| 78 | blacklist=tests_to_black_list)) |
Robert Iannucci | 7d47eb5 | 2017-12-06 12:18:18 -0800 | [diff] [blame] | 79 | |
| 80 | # Validate CIPD manifests. |
| 81 | root = input_api.os_path.normpath( |
| 82 | input_api.os_path.abspath(input_api.PresubmitLocalPath())) |
| 83 | rel_file = lambda rel: input_api.os_path.join(root, rel) |
| 84 | cipd_manifests = set(rel_file(input_api.os_path.join(*x)) for x in ( |
| 85 | ('cipd_manifest.txt',), |
| 86 | ('bootstrap', 'win', 'manifest.txt'), |
| 87 | ('bootstrap', 'win', 'manifest_bleeding_edge.txt'), |
| 88 | |
| 89 | # Also generate a file for the cipd client itself. |
| 90 | ('cipd_client_version',), |
| 91 | )) |
| 92 | affected_manifests = input_api.AffectedFiles( |
| 93 | include_deletes=False, |
| 94 | file_filter=lambda x: |
| 95 | input_api.os_path.normpath(x.AbsoluteLocalPath()) in cipd_manifests) |
| 96 | for path in affected_manifests: |
| 97 | path = path.AbsoluteLocalPath() |
| 98 | if path.endswith('.txt'): |
| 99 | tests.append(input_api.canned_checks.CheckCIPDManifest( |
| 100 | input_api, output_api, path=path)) |
| 101 | else: |
| 102 | pkg = 'infra/tools/cipd/${platform}' |
| 103 | ver = input_api.ReadFile(path) |
| 104 | tests.append(input_api.canned_checks.CheckCIPDManifest( |
Vadim Shtayura | 0909885 | 2018-06-21 22:50:30 +0000 | [diff] [blame] | 105 | input_api, output_api, |
| 106 | content=CIPD_CLIENT_ENSURE_FILE_TEMPLATE % (pkg, ver))) |
Robert Iannucci | 7d47eb5 | 2017-12-06 12:18:18 -0800 | [diff] [blame] | 107 | |
scottmg@chromium.org | 69ae86a | 2014-01-17 03:55:45 +0000 | [diff] [blame] | 108 | results.extend(input_api.RunTests(tests)) |
maruel@chromium.org | 3c9f7ca | 2011-04-01 14:52:38 +0000 | [diff] [blame] | 109 | return results |
maruel@chromium.org | 2a74d37 | 2011-03-29 19:05:50 +0000 | [diff] [blame] | 110 | |
| 111 | |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 112 | def CheckChangeOnUpload(input_api, output_api): |
maruel@chromium.org | d52417c | 2011-09-02 20:13:17 +0000 | [diff] [blame] | 113 | # Do not run integration tests on upload since they are way too slow. |
| 114 | tests_to_black_list = [ |
| 115 | r'^checkout_test\.py$', |
Vadim Shtayura | 7e50ee3 | 2018-07-26 17:43:51 +0000 | [diff] [blame^] | 116 | r'^cipd_bootstrap_test\.py$', |
maruel@chromium.org | d52417c | 2011-09-02 20:13:17 +0000 | [diff] [blame] | 117 | r'^gclient_smoketest\.py$', |
| 118 | r'^scm_unittest\.py$', |
ilevy@chromium.org | 5856562 | 2013-03-17 23:18:37 +0000 | [diff] [blame] | 119 | r'^subprocess2_test\.py$', |
Vadim Shtayura | 7e50ee3 | 2018-07-26 17:43:51 +0000 | [diff] [blame^] | 120 | ] |
maruel@chromium.org | d52417c | 2011-09-02 20:13:17 +0000 | [diff] [blame] | 121 | return CommonChecks(input_api, output_api, tests_to_black_list) |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 122 | |
| 123 | |
maruel@chromium.org | ce30ef7 | 2009-05-25 15:20:42 +0000 | [diff] [blame] | 124 | def CheckChangeOnCommit(input_api, output_api): |
| 125 | output = [] |
maruel@chromium.org | d52417c | 2011-09-02 20:13:17 +0000 | [diff] [blame] | 126 | output.extend(CommonChecks(input_api, output_api, [])) |
maruel@chromium.org | e94aedc | 2010-12-13 21:11:30 +0000 | [diff] [blame] | 127 | output.extend(input_api.canned_checks.CheckDoNotSubmit( |
| 128 | input_api, |
| 129 | output_api)) |
maruel@chromium.org | 7b305e8 | 2009-05-19 18:24:20 +0000 | [diff] [blame] | 130 | return output |