blob: 63fdb9777250212f348922c401ec33356e549c71 [file] [log] [blame]
[email protected]c920ad22012-02-02 18:26:041# Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]3d235242009-05-15 12:40:482# 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
7See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
[email protected]2a74d372011-03-29 19:05:508details on the presubmit API built into depot_tools.
[email protected]3d235242009-05-15 12:40:489"""
10
[email protected]34071032014-03-18 17:23:4811import fnmatch
12import os
13
[email protected]627ea672011-03-11 23:29:0314
Vadim Shtayura09098852018-06-21 22:50:3015# CIPD ensure manifest for checking CIPD client itself.
16CIPD_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 Shtayura333617b2018-08-07 20:46:3821$VerifiedPlatform linux-arm64 linux-armv6l
22$VerifiedPlatform linux-mips64 linux-mips64le linux-mipsle
Robert Iannucci7d47eb52017-12-06 20:18:1823
24%s %s
25'''
26
27
agablef39c3332016-09-26 16:35:4228def 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]55cb27e2016-05-16 17:54:4035 ]
agablef39c3332016-09-26 16:35:4236 black_list = list(input_api.DEFAULT_BLACK_LIST)
[email protected]34071032014-03-18 17:23:4837 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]ff9a2172012-04-24 16:55:3247 disabled_warnings = [
48 'R0401', # Cyclic import
49 'W0613', # Unused argument
50 ]
agablef39c3332016-09-26 16:35:4251 return input_api.canned_checks.GetPylint(
[email protected]69ae86a2014-01-17 03:55:4552 input_api,
53 output_api,
agablef39c3332016-09-26 16:35:4254 white_list=white_list,
[email protected]69ae86a2014-01-17 03:55:4555 black_list=black_list,
56 disabled_warnings=disabled_warnings)
agablef39c3332016-09-26 16:35:4257
58
59def CommonChecks(input_api, output_api, tests_to_black_list):
60 results = []
61 results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
Edward Lesmescb62e482018-04-19 22:29:3562 results.extend(input_api.canned_checks.CheckOwnersFormat(
63 input_api, output_api))
Vadim Shtayura7e50ee32018-07-26 17:43:5164
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]69ae86a2014-01-17 03:55:4571 # TODO(maruel): Make sure at least one file is modified first.
72 # TODO(maruel): If only tests are modified, only run them.
agablef39c3332016-09-26 16:35:4273 tests = DepotToolsPylint(input_api, output_api)
Vadim Shtayura7e50ee32018-07-26 17:43:5174 tests.extend(input_api.canned_checks.GetUnitTestsInDirectory(
[email protected]69ae86a2014-01-17 03:55:4575 input_api,
76 output_api,
77 'tests',
Vadim Shtayura7e50ee32018-07-26 17:43:5178 whitelist=tests_to_white_list,
79 blacklist=tests_to_black_list))
Robert Iannucci7d47eb52017-12-06 20:18:1880
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 Shtayura09098852018-06-21 22:50:30106 input_api, output_api,
107 content=CIPD_CLIENT_ENSURE_FILE_TEMPLATE % (pkg, ver)))
Vadim Shtayuraf9b48452018-09-18 00:22:26108 tests.append(input_api.canned_checks.CheckCIPDClientDigests(
109 input_api, output_api, client_version_file=path))
Robert Iannucci7d47eb52017-12-06 20:18:18110
[email protected]69ae86a2014-01-17 03:55:45111 results.extend(input_api.RunTests(tests))
[email protected]3c9f7ca2011-04-01 14:52:38112 return results
[email protected]2a74d372011-03-29 19:05:50113
114
[email protected]e94aedc2010-12-13 21:11:30115def CheckChangeOnUpload(input_api, output_api):
[email protected]d52417c2011-09-02 20:13:17116 # Do not run integration tests on upload since they are way too slow.
117 tests_to_black_list = [
118 r'^checkout_test\.py$',
Vadim Shtayura7e50ee32018-07-26 17:43:51119 r'^cipd_bootstrap_test\.py$',
[email protected]d52417c2011-09-02 20:13:17120 r'^gclient_smoketest\.py$',
121 r'^scm_unittest\.py$',
[email protected]58565622013-03-17 23:18:37122 r'^subprocess2_test\.py$',
Vadim Shtayura7e50ee32018-07-26 17:43:51123 ]
[email protected]d52417c2011-09-02 20:13:17124 return CommonChecks(input_api, output_api, tests_to_black_list)
[email protected]e94aedc2010-12-13 21:11:30125
126
[email protected]ce30ef72009-05-25 15:20:42127def CheckChangeOnCommit(input_api, output_api):
128 output = []
[email protected]d52417c2011-09-02 20:13:17129 output.extend(CommonChecks(input_api, output_api, []))
[email protected]e94aedc2010-12-13 21:11:30130 output.extend(input_api.canned_checks.CheckDoNotSubmit(
131 input_api,
132 output_api))
[email protected]7b305e82009-05-19 18:24:20133 return output