blob: 70bd88b87c1347b7e4d3106fd20066a65132356a [file] [log] [blame]
qyearsley61be68b2015-07-06 12:57:02 -07001# Copyright 2015 The Chromium Authors. All rights reserved.
sullivan3283c9a2015-05-28 12:41:09 -07002# 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 catapult.
6
7See https://www.chromium.org/developers/how-tos/depottools/presubmit-scripts
8for more details about the presubmit API built into depot_tools.
9"""
sullivan497af692015-08-11 10:39:21 -070010import re
Petr Cermak3946db22015-05-22 15:35:39 +010011import sys
sullivan3283c9a2015-05-28 12:41:09 -070012
sullivan7bb77ca2015-08-07 10:44:03 -070013_EXCLUDED_PATHS = (
dtua9d94bc2015-09-15 13:54:19 -070014 r'(.*[\\/])?\.git[\\/].*',
sullivan7bb77ca2015-08-07 10:44:03 -070015 r'.+\.png$',
16 r'.+\.svg$',
17 r'.+\.skp$',
18 r'.+\.gypi$',
19 r'.+\.gyp$',
20 r'.+\.gn$',
21 r'.*\.gitignore$',
22 r'.*codereview.settings$',
23 r'.*AUTHOR$',
24 r'^CONTRIBUTORS\.md$',
25 r'.*LICENSE$',
26 r'.*OWNERS$',
27 r'.*README\.md$',
sullivanf8f372d2017-05-12 14:16:25 -070028 r'^dashboard[\\/]dashboard[\\/]api[\\/]examples[\\/].*.js',
dtua9d94bc2015-09-15 13:54:19 -070029 r'^dashboard[\\/]dashboard[\\/]templates[\\/].*',
Dean Michael Berrisf6162942019-05-01 17:16:35 +100030 r'^dashboard[\\/]dashboard[\\/]sheriff_config[\\/].*_pb2.py$',
dtua9d94bc2015-09-15 13:54:19 -070031 r'^experimental[\\/]heatmap[\\/].*',
primiano494b9b22017-04-10 13:15:36 -070032 r'^experimental[\\/]trace_on_tap[\\/]third_party[\\/].*',
Annie Sullivan308728e2018-06-14 17:07:11 -040033 r'^experimental[\\/]perf_sheriffing_emailer[\\/].*.js',
dtua9d94bc2015-09-15 13:54:19 -070034 r'^perf_insights[\\/]test_data[\\/].*',
35 r'^perf_insights[\\/]third_party[\\/].*',
nednguyenc9667ec2017-09-05 15:49:12 -070036 r'^telemetry[\\/]third_party[\\/].*',
dtua9d94bc2015-09-15 13:54:19 -070037 r'^third_party[\\/].*',
38 r'^tracing[\\/]\.allow-devtools-save$',
39 r'^tracing[\\/]bower\.json$',
40 r'^tracing[\\/]\.bowerrc$',
41 r'^tracing[\\/]tracing_examples[\\/]string_convert\.js$',
42 r'^tracing[\\/]test_data[\\/].*',
43 r'^tracing[\\/]third_party[\\/].*',
Oystein Eftevaag81388262017-10-04 15:06:44 -070044 r'^py_vulcanize[\\/]third_party[\\/].*',
45 r'^common/py_vulcanize[\\/].*', # TODO(hjd): Remove after fixing long lines.
sullivan7bb77ca2015-08-07 10:44:03 -070046)
47
sullivan3283c9a2015-05-28 12:41:09 -070048
Aaron Gable6907a1c2017-10-09 12:59:45 -070049_GITHUB_BUG_ID_RE = re.compile(r'#[1-9]\d*')
50_MONORAIL_BUG_ID_RE = re.compile(r'[1-9]\d*')
Nghia Nguyen219bbf12018-04-20 07:39:12 -070051_MONORAIL_PROJECT_NAMES = frozenset({'chromium', 'v8', 'angleproject', 'skia'})
petrcermakdad7f312016-06-01 05:49:22 -070052
sullivan497af692015-08-11 10:39:21 -070053def CheckChangeLogBug(input_api, output_api):
agable622801d2017-05-22 10:12:27 -070054 # Show a presubmit message if there is no Bug line or an empty Bug line.
55 if not input_api.change.BugsFromDescription():
petrcermakdad7f312016-06-01 05:49:22 -070056 return [output_api.PresubmitNotifyResult(
Aaron Gable6907a1c2017-10-09 12:59:45 -070057 'If this change has associated bugs on GitHub or Monorail, add a '
agable622801d2017-05-22 10:12:27 -070058 '"Bug: <bug>(, <bug>)*" line to the patch description where <bug> can '
petrcermakdad7f312016-06-01 05:49:22 -070059 'be one of the following: catapult:#NNNN, ' +
Aaron Gable6907a1c2017-10-09 12:59:45 -070060 ', '.join('%s:NNNNNN' % n for n in _MONORAIL_PROJECT_NAMES) + '.')]
petrcermakdad7f312016-06-01 05:49:22 -070061
petrcermakdad7f312016-06-01 05:49:22 -070062 # Check that each bug in the BUG= line has the correct format.
63 error_messages = []
64 catapult_bug_provided = False
petrcermakdad7f312016-06-01 05:49:22 -070065
agable622801d2017-05-22 10:12:27 -070066 for index, bug in enumerate(input_api.change.BugsFromDescription()):
petrcermakdad7f312016-06-01 05:49:22 -070067 # Check if the bug can be split into a repository name and a bug ID (e.g.
68 # 'catapult:#1234' -> 'catapult' and '#1234').
69 bug_parts = bug.split(':')
70 if len(bug_parts) != 2:
71 error_messages.append('Invalid bug "%s". Bugs should be provided in the '
Aaron Gable6907a1c2017-10-09 12:59:45 -070072 '"<project-name>:<bug-id>" format.' % bug)
petrcermakdad7f312016-06-01 05:49:22 -070073 continue
Aaron Gable6907a1c2017-10-09 12:59:45 -070074 project_name, bug_id = bug_parts
petrcermakdad7f312016-06-01 05:49:22 -070075
Aaron Gable6907a1c2017-10-09 12:59:45 -070076 if project_name == 'catapult':
Dave Tub3611d52017-10-09 18:38:58 -070077 if not _GITHUB_BUG_ID_RE.match(bug_id):
petrcermakdad7f312016-06-01 05:49:22 -070078 error_messages.append('Invalid bug "%s". Bugs in the Catapult '
79 'repository should be provided in the '
80 '"catapult:#NNNN" format.' % bug)
81 catapult_bug_provided = True
Aaron Gable6907a1c2017-10-09 12:59:45 -070082 elif project_name in _MONORAIL_PROJECT_NAMES:
83 if not _MONORAIL_BUG_ID_RE.match(bug_id):
84 error_messages.append('Invalid bug "%s". Bugs in the Monorail %s '
85 'project should be provided in the '
86 '"%s:NNNNNN" format.' % (bug, project_name,
87 project_name))
petrcermakdad7f312016-06-01 05:49:22 -070088 else:
89 error_messages.append('Invalid bug "%s". Unknown repository "%s".' % (
Aaron Gable6907a1c2017-10-09 12:59:45 -070090 bug, project_name))
petrcermakdad7f312016-06-01 05:49:22 -070091
petrcermakdad7f312016-06-01 05:49:22 -070092 return map(output_api.PresubmitError, error_messages)
sullivan497af692015-08-11 10:39:21 -070093
94
Petr Cermak3946db22015-05-22 15:35:39 +010095def CheckChange(input_api, output_api):
sullivan1e388742015-08-03 13:45:35 -070096 results = []
Petr Cermak3946db22015-05-22 15:35:39 +010097 try:
98 sys.path += [input_api.PresubmitLocalPath()]
benjhayden448b06c2017-07-05 21:42:49 -070099
100 from catapult_build import bin_checks
qyearsleybd4fba62015-11-11 12:02:41 -0800101 from catapult_build import html_checks
benjhayden448b06c2017-07-05 21:42:49 -0700102 from catapult_build import js_checks
petrcermak1fda6fc2016-02-24 10:15:03 -0800103 from catapult_build import repo_checks
benjhayden448b06c2017-07-05 21:42:49 -0700104
sullivan497af692015-08-11 10:39:21 -0700105 results += input_api.canned_checks.PanProjectChecks(
106 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)
Sergiy Byelozyorov48ce5252017-11-03 12:42:28 +0100107 results += input_api.RunTests(
108 input_api.canned_checks.CheckVPythonSpec(input_api, output_api))
sullivan497af692015-08-11 10:39:21 -0700109 results += CheckChangeLogBug(input_api, output_api)
qyearsleye080ff92015-08-17 11:19:59 -0700110 results += js_checks.RunChecks(
111 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)
Ryan Heisef85be7e2021-02-26 17:21:50 +0000112 results += input_api.RunTests(
113 input_api.canned_checks.CheckPatchFormatted(input_api, output_api,
114 check_js=True))
qyearsleybd4fba62015-11-11 12:02:41 -0800115 results += html_checks.RunChecks(
116 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)
petrcermak1fda6fc2016-02-24 10:15:03 -0800117 results += repo_checks.RunChecks(input_api, output_api)
benjhayden448b06c2017-07-05 21:42:49 -0700118 results += bin_checks.RunChecks(
119 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)
Petr Cermak3946db22015-05-22 15:35:39 +0100120 finally:
nducaa6e18a92015-08-09 17:06:32 -0700121 sys.path.remove(input_api.PresubmitLocalPath())
sullivan1e388742015-08-03 13:45:35 -0700122 return results
sullivanc11564b2015-06-25 10:37:29 -0700123
124
125def CheckChangeOnUpload(input_api, output_api):
Zhenyao Mo074cebc2018-08-27 11:31:05 -0700126 results = CheckChange(input_api, output_api)
127 cwd = input_api.PresubmitLocalPath()
128 exit_code = input_api.subprocess.call(
129 [input_api.python_executable, 'generate_telemetry_build.py', '--check'],
130 cwd=cwd)
131 if exit_code != 0:
132 results.append(output_api.PresubmitError(
133 'BUILD.gn needs to be re-generated. Please run '
134 '%s/generate_telemetry_build.py and include the changes in this CL' %
135 cwd))
136 return results
sullivanc11564b2015-06-25 10:37:29 -0700137
138def CheckChangeOnCommit(input_api, output_api):
Petr Cermak3946db22015-05-22 15:35:39 +0100139 return CheckChange(input_api, output_api)