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