qyearsley | 61be68b | 2015-07-06 12:57:02 -0700 | [diff] [blame] | 1 | # Copyright 2015 The Chromium Authors. All rights reserved. |
sullivan | 3283c9a | 2015-05-28 12:41:09 -0700 | [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 catapult. |
| 6 | |
| 7 | See https://www.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 8 | for more details about the presubmit API built into depot_tools. |
| 9 | """ |
sullivan | 497af69 | 2015-08-11 10:39:21 -0700 | [diff] [blame] | 10 | import re |
Petr Cermak | 3946db2 | 2015-05-22 15:35:39 +0100 | [diff] [blame] | 11 | import sys |
sullivan | 3283c9a | 2015-05-28 12:41:09 -0700 | [diff] [blame] | 12 | |
sullivan | 7bb77ca | 2015-08-07 10:44:03 -0700 | [diff] [blame] | 13 | _EXCLUDED_PATHS = ( |
dtu | a9d94bc | 2015-09-15 13:54:19 -0700 | [diff] [blame] | 14 | r'(.*[\\/])?\.git[\\/].*', |
sullivan | 7bb77ca | 2015-08-07 10:44:03 -0700 | [diff] [blame] | 15 | 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$', |
sullivan | f8f372d | 2017-05-12 14:16:25 -0700 | [diff] [blame^] | 28 | r'^dashboard[\\/]dashboard[\\/]api[\\/]examples[\\/].*.js', |
dtu | a9d94bc | 2015-09-15 13:54:19 -0700 | [diff] [blame] | 29 | r'^dashboard[\\/]dashboard[\\/]templates[\\/].*', |
| 30 | r'^experimental[\\/]heatmap[\\/].*', |
primiano | 494b9b2 | 2017-04-10 13:15:36 -0700 | [diff] [blame] | 31 | r'^experimental[\\/]trace_on_tap[\\/]third_party[\\/].*', |
dtu | a9d94bc | 2015-09-15 13:54:19 -0700 | [diff] [blame] | 32 | r'^perf_insights[\\/]test_data[\\/].*', |
| 33 | r'^perf_insights[\\/]third_party[\\/].*', |
| 34 | r'^third_party[\\/].*', |
| 35 | r'^tracing[\\/]\.allow-devtools-save$', |
| 36 | r'^tracing[\\/]bower\.json$', |
| 37 | r'^tracing[\\/]\.bowerrc$', |
| 38 | r'^tracing[\\/]tracing_examples[\\/]string_convert\.js$', |
| 39 | r'^tracing[\\/]test_data[\\/].*', |
| 40 | r'^tracing[\\/]third_party[\\/].*', |
qyearsley | 4e6e99b | 2016-02-08 14:13:44 -0800 | [diff] [blame] | 41 | r'^telemetry[\\/]support[\\/]html_output[\\/]results-template.html', |
sullivan | 7bb77ca | 2015-08-07 10:44:03 -0700 | [diff] [blame] | 42 | ) |
| 43 | |
sullivan | 3283c9a | 2015-05-28 12:41:09 -0700 | [diff] [blame] | 44 | |
petrcermak | dad7f31 | 2016-06-01 05:49:22 -0700 | [diff] [blame] | 45 | _CATAPULT_BUG_ID_RE = re.compile(r'#[1-9]\d*') |
| 46 | _RIETVELD_BUG_ID_RE = re.compile(r'[1-9]\d*') |
cwallez | b287a2a | 2017-03-14 08:13:00 -0700 | [diff] [blame] | 47 | _RIETVELD_REPOSITORY_NAMES = frozenset({'chromium', 'v8', 'angleproject'}) |
petrcermak | dad7f31 | 2016-06-01 05:49:22 -0700 | [diff] [blame] | 48 | |
sullivan | 497af69 | 2015-08-11 10:39:21 -0700 | [diff] [blame] | 49 | def CheckChangeLogBug(input_api, output_api): |
petrcermak | dad7f31 | 2016-06-01 05:49:22 -0700 | [diff] [blame] | 50 | # Show a presubmit message if there is no BUG= line. |
| 51 | if input_api.change.BUG is None: |
| 52 | return [output_api.PresubmitNotifyResult( |
| 53 | 'If this change has associated Catapult and/or Rietveld bug(s), add a ' |
| 54 | '"BUG=<bug>(, <bug>)*" line to the patch description where <bug> can ' |
| 55 | 'be one of the following: catapult:#NNNN, ' + |
| 56 | ', '.join('%s:NNNNNN' % n for n in _RIETVELD_REPOSITORY_NAMES) + '.')] |
| 57 | |
| 58 | # Throw a presubmit error if the BUG= line is provided but empty. |
| 59 | if input_api.change.BUG.strip() == '': |
| 60 | return [output_api.PresubmitError( |
| 61 | 'Empty BUG= line. Either remove it, or, preferably, change it to ' |
| 62 | '"BUG=<bug>(, <bug>)*" where <bug> can be one of the following: ' + |
| 63 | 'catapult:#NNNN, ' + |
| 64 | ', '.join('%s:NNNNNN' % n for n in _RIETVELD_REPOSITORY_NAMES) + '.')] |
| 65 | |
| 66 | # Check that each bug in the BUG= line has the correct format. |
| 67 | error_messages = [] |
| 68 | catapult_bug_provided = False |
| 69 | append_repository_order_error = False |
| 70 | |
| 71 | for index, bug in enumerate(input_api.change.BUG.split(',')): |
| 72 | if index > 0: |
| 73 | bug = bug.lstrip() # Allow spaces after commas. |
| 74 | |
| 75 | # Check if the bug can be split into a repository name and a bug ID (e.g. |
| 76 | # 'catapult:#1234' -> 'catapult' and '#1234'). |
| 77 | bug_parts = bug.split(':') |
| 78 | if len(bug_parts) != 2: |
| 79 | error_messages.append('Invalid bug "%s". Bugs should be provided in the ' |
| 80 | '"<repository-name>:<bug-id>" format.' % bug) |
| 81 | continue |
| 82 | repository_name, bug_id = bug_parts |
| 83 | |
| 84 | if repository_name == 'catapult': |
| 85 | if not _CATAPULT_BUG_ID_RE.match(bug_id): |
| 86 | error_messages.append('Invalid bug "%s". Bugs in the Catapult ' |
| 87 | 'repository should be provided in the ' |
| 88 | '"catapult:#NNNN" format.' % bug) |
| 89 | catapult_bug_provided = True |
| 90 | elif repository_name in _RIETVELD_REPOSITORY_NAMES: |
| 91 | if not _RIETVELD_BUG_ID_RE.match(bug_id): |
| 92 | error_messages.append('Invalid bug "%s". Bugs in the Rietveld %s ' |
| 93 | 'repository should be provided in the ' |
| 94 | '"%s:NNNNNN" format.' % (bug, repository_name, |
| 95 | repository_name)) |
| 96 | if catapult_bug_provided: |
| 97 | append_repository_order_error = True |
| 98 | else: |
| 99 | error_messages.append('Invalid bug "%s". Unknown repository "%s".' % ( |
| 100 | bug, repository_name)) |
| 101 | |
| 102 | if append_repository_order_error: |
| 103 | error_messages.append('Please list Rietveld bugs (' + |
| 104 | ', '.join('%s:NNNNNN' % n |
| 105 | for n in _RIETVELD_REPOSITORY_NAMES) + |
| 106 | ') before Catapult bugs (catapult:#NNNN) so ' |
| 107 | 'that Rietveld would display them as hyperlinks.') |
| 108 | |
| 109 | return map(output_api.PresubmitError, error_messages) |
sullivan | 497af69 | 2015-08-11 10:39:21 -0700 | [diff] [blame] | 110 | |
| 111 | |
Petr Cermak | 3946db2 | 2015-05-22 15:35:39 +0100 | [diff] [blame] | 112 | def CheckChange(input_api, output_api): |
sullivan | 1e38874 | 2015-08-03 13:45:35 -0700 | [diff] [blame] | 113 | results = [] |
Petr Cermak | 3946db2 | 2015-05-22 15:35:39 +0100 | [diff] [blame] | 114 | try: |
| 115 | sys.path += [input_api.PresubmitLocalPath()] |
sullivan | 04bf4b5 | 2015-08-21 13:08:38 -0700 | [diff] [blame] | 116 | from catapult_build import js_checks |
qyearsley | bd4fba6 | 2015-11-11 12:02:41 -0800 | [diff] [blame] | 117 | from catapult_build import html_checks |
petrcermak | 1fda6fc | 2016-02-24 10:15:03 -0800 | [diff] [blame] | 118 | from catapult_build import repo_checks |
sullivan | 497af69 | 2015-08-11 10:39:21 -0700 | [diff] [blame] | 119 | results += input_api.canned_checks.PanProjectChecks( |
| 120 | input_api, output_api, excluded_paths=_EXCLUDED_PATHS) |
sullivan | 497af69 | 2015-08-11 10:39:21 -0700 | [diff] [blame] | 121 | results += CheckChangeLogBug(input_api, output_api) |
qyearsley | e080ff9 | 2015-08-17 11:19:59 -0700 | [diff] [blame] | 122 | results += js_checks.RunChecks( |
| 123 | input_api, output_api, excluded_paths=_EXCLUDED_PATHS) |
qyearsley | bd4fba6 | 2015-11-11 12:02:41 -0800 | [diff] [blame] | 124 | results += html_checks.RunChecks( |
| 125 | input_api, output_api, excluded_paths=_EXCLUDED_PATHS) |
petrcermak | 1fda6fc | 2016-02-24 10:15:03 -0800 | [diff] [blame] | 126 | results += repo_checks.RunChecks(input_api, output_api) |
Petr Cermak | 3946db2 | 2015-05-22 15:35:39 +0100 | [diff] [blame] | 127 | finally: |
nduca | a6e18a9 | 2015-08-09 17:06:32 -0700 | [diff] [blame] | 128 | sys.path.remove(input_api.PresubmitLocalPath()) |
sullivan | 1e38874 | 2015-08-03 13:45:35 -0700 | [diff] [blame] | 129 | return results |
sullivan | c11564b | 2015-06-25 10:37:29 -0700 | [diff] [blame] | 130 | |
| 131 | |
| 132 | def CheckChangeOnUpload(input_api, output_api): |
Petr Cermak | 3946db2 | 2015-05-22 15:35:39 +0100 | [diff] [blame] | 133 | return CheckChange(input_api, output_api) |
sullivan | c11564b | 2015-06-25 10:37:29 -0700 | [diff] [blame] | 134 | |
| 135 | |
| 136 | def CheckChangeOnCommit(input_api, output_api): |
Petr Cermak | 3946db2 | 2015-05-22 15:35:39 +0100 | [diff] [blame] | 137 | return CheckChange(input_api, output_api) |