Hector Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 1 | # Copyright (C) 2017 The Android Open Source Project |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
Hector Dearman | 2cc71f6 | 2021-07-14 10:28:58 +0100 | [diff] [blame] | 15 | from __future__ import print_function |
Florian Mayer | 640b7ae | 2018-05-09 15:28:32 +0100 | [diff] [blame] | 16 | import itertools |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame] | 17 | import subprocess |
Hector Dearman | 2cc71f6 | 2021-07-14 10:28:58 +0100 | [diff] [blame] | 18 | import time |
| 19 | |
Lalit Maganti | 86a053e | 2022-11-09 23:35:20 +0000 | [diff] [blame] | 20 | USE_PYTHON3 = True |
| 21 | |
| 22 | |
Hector Dearman | 2cc71f6 | 2021-07-14 10:28:58 +0100 | [diff] [blame] | 23 | def RunAndReportIfLong(func, *args, **kargs): |
| 24 | start = time.time() |
| 25 | results = func(*args, **kargs) |
| 26 | end = time.time() |
| 27 | limit = 0.5 # seconds |
| 28 | name = func.__name__ |
| 29 | runtime = end - start |
| 30 | if runtime > limit: |
| 31 | print("{} took >{:.2}s ({:.2}s)".format(name, limit, runtime)) |
| 32 | return results |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame] | 33 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 34 | |
Hector Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 35 | def CheckChange(input, output): |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 36 | # There apparently is no way to wrap strings in blueprints, so ignore long |
| 37 | # lines in them. |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 38 | def long_line_sources(x): |
| 39 | return input.FilterSourceFile( |
| 40 | x, |
Ryan Savitski | 135038e | 2020-11-12 20:57:57 +0000 | [diff] [blame] | 41 | files_to_check='.*', |
| 42 | files_to_skip=[ |
Lalit Maganti | 3dc0ffe | 2021-06-09 13:27:52 +0100 | [diff] [blame] | 43 | 'Android[.]bp', |
Lalit Maganti | bf99dd3 | 2023-02-07 23:50:48 +0000 | [diff] [blame] | 44 | "buildtools/grpc/BUILD.gn", |
Lalit Maganti | 3dc0ffe | 2021-06-09 13:27:52 +0100 | [diff] [blame] | 45 | '.*[.]json$', |
| 46 | '.*[.]sql$', |
| 47 | '.*[.]out$', |
Anna Mayzner | 6988df8 | 2023-01-23 10:37:16 +0000 | [diff] [blame] | 48 | 'test/trace_processor/.*/tests.*$', |
Lalit Maganti | 3dc0ffe | 2021-06-09 13:27:52 +0100 | [diff] [blame] | 49 | '(.*/)?BUILD$', |
| 50 | 'WORKSPACE', |
| 51 | '.*/Makefile$', |
| 52 | '/perfetto_build_flags.h$', |
| 53 | "infra/luci/.*", |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 54 | ]) |
| 55 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 56 | results = [] |
Hector Dearman | 2cc71f6 | 2021-07-14 10:28:58 +0100 | [diff] [blame] | 57 | results += RunAndReportIfLong(input.canned_checks.CheckDoNotSubmit, input, |
| 58 | output) |
| 59 | results += RunAndReportIfLong(input.canned_checks.CheckChangeHasNoTabs, input, |
| 60 | output) |
| 61 | results += RunAndReportIfLong( |
| 62 | input.canned_checks.CheckLongLines, |
| 63 | input, |
| 64 | output, |
| 65 | 80, |
| 66 | source_file_filter=long_line_sources) |
| 67 | results += RunAndReportIfLong( |
| 68 | input.canned_checks.CheckPatchFormatted, input, output, check_js=True) |
| 69 | results += RunAndReportIfLong(input.canned_checks.CheckGNFormatted, input, |
| 70 | output) |
| 71 | results += RunAndReportIfLong(CheckIncludeGuards, input, output) |
| 72 | results += RunAndReportIfLong(CheckIncludeViolations, input, output) |
| 73 | results += RunAndReportIfLong(CheckProtoComments, input, output) |
| 74 | results += RunAndReportIfLong(CheckBuild, input, output) |
| 75 | results += RunAndReportIfLong(CheckAndroidBlueprint, input, output) |
| 76 | results += RunAndReportIfLong(CheckBinaryDescriptors, input, output) |
| 77 | results += RunAndReportIfLong(CheckMergedTraceConfigProto, input, output) |
| 78 | results += RunAndReportIfLong(CheckProtoEventList, input, output) |
| 79 | results += RunAndReportIfLong(CheckBannedCpp, input, output) |
Primiano Tucci | 0fd92a9 | 2023-07-17 11:47:38 -0700 | [diff] [blame] | 80 | results += RunAndReportIfLong(CheckBadCppPatterns, input, output) |
Anna Mayzner | 412e056 | 2022-11-25 09:55:51 +0000 | [diff] [blame] | 81 | results += RunAndReportIfLong(CheckSqlModules, input, output) |
Hector Dearman | 2cc71f6 | 2021-07-14 10:28:58 +0100 | [diff] [blame] | 82 | results += RunAndReportIfLong(CheckSqlMetrics, input, output) |
Primiano Tucci | 3d4217d | 2021-11-05 11:11:51 +0000 | [diff] [blame] | 83 | results += RunAndReportIfLong(CheckTestData, input, output) |
Primiano Tucci | 11d94e1 | 2022-08-02 17:44:33 +0100 | [diff] [blame] | 84 | results += RunAndReportIfLong(CheckAmalgamatedPythonTools, input, output) |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 85 | return results |
Hector Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 86 | |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame] | 87 | |
Hector Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 88 | def CheckChangeOnUpload(input_api, output_api): |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 89 | return CheckChange(input_api, output_api) |
Hector Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 90 | |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame] | 91 | |
Hector Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 92 | def CheckChangeOnCommit(input_api, output_api): |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 93 | return CheckChange(input_api, output_api) |
Hector Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 94 | |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame] | 95 | |
Lalit Maganti | 279ecde | 2019-04-01 16:57:12 +0100 | [diff] [blame] | 96 | def CheckBuild(input_api, output_api): |
Bruce Dawson | 7627d04 | 2023-07-17 10:08:24 -0700 | [diff] [blame] | 97 | # The script invocation doesn't work on Windows. |
| 98 | if input_api.is_windows: |
| 99 | return [] |
| 100 | |
Primiano Tucci | 9c41165 | 2019-08-27 07:13:59 +0200 | [diff] [blame] | 101 | tool = 'tools/gen_bazel' |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 102 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 103 | # If no GN files were modified, bail out. |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 104 | def build_file_filter(x): |
| 105 | return input_api.FilterSourceFile( |
Ryan Savitski | 135038e | 2020-11-12 20:57:57 +0000 | [diff] [blame] | 106 | x, files_to_check=('.*BUILD[.]gn$', '.*[.]gni$', 'BUILD\.extras', tool)) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 107 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 108 | if not input_api.AffectedSourceFiles(build_file_filter): |
Lalit Maganti | 279ecde | 2019-04-01 16:57:12 +0100 | [diff] [blame] | 109 | return [] |
Primiano Tucci | 9c41165 | 2019-08-27 07:13:59 +0200 | [diff] [blame] | 110 | if subprocess.call([tool, '--check-only']): |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 111 | return [ |
| 112 | output_api.PresubmitError('Bazel BUILD(s) are out of date. Run ' + |
| 113 | tool + ' to update them.') |
| 114 | ] |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 115 | return [] |
| 116 | |
Lalit Maganti | 279ecde | 2019-04-01 16:57:12 +0100 | [diff] [blame] | 117 | |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame] | 118 | def CheckAndroidBlueprint(input_api, output_api): |
Bruce Dawson | 7627d04 | 2023-07-17 10:08:24 -0700 | [diff] [blame] | 119 | # The script invocation doesn't work on Windows. |
| 120 | if input_api.is_windows: |
| 121 | return [] |
| 122 | |
Primiano Tucci | 9c41165 | 2019-08-27 07:13:59 +0200 | [diff] [blame] | 123 | tool = 'tools/gen_android_bp' |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 124 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 125 | # If no GN files were modified, bail out. |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 126 | def build_file_filter(x): |
| 127 | return input_api.FilterSourceFile( |
Rasika Navarange | 4c6a6a6 | 2023-11-12 13:39:54 +0000 | [diff] [blame] | 128 | x, |
| 129 | files_to_check=('.*BUILD[.]gn$', '.*[.]gni$', tool), |
| 130 | # Do not require Android.bp to be regenerated for chrome |
| 131 | # stdlib changes. |
| 132 | files_to_skip=( |
| 133 | 'src/trace_processor/perfetto_sql/stdlib/chrome/BUILD.gn')) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 134 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 135 | if not input_api.AffectedSourceFiles(build_file_filter): |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame] | 136 | return [] |
Primiano Tucci | 9c41165 | 2019-08-27 07:13:59 +0200 | [diff] [blame] | 137 | if subprocess.call([tool, '--check-only']): |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 138 | return [ |
| 139 | output_api.PresubmitError('Android build files are out of date. ' + |
| 140 | 'Run ' + tool + ' to update them.') |
| 141 | ] |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 142 | return [] |
| 143 | |
Primiano Tucci | c501080 | 2018-01-19 17:13:21 +0000 | [diff] [blame] | 144 | |
Primiano Tucci | 40e9872 | 2018-02-16 11:50:17 +0000 | [diff] [blame] | 145 | def CheckIncludeGuards(input_api, output_api): |
Bruce Dawson | 7627d04 | 2023-07-17 10:08:24 -0700 | [diff] [blame] | 146 | # The script invocation doesn't work on Windows. |
| 147 | if input_api.is_windows: |
| 148 | return [] |
| 149 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 150 | tool = 'tools/fix_include_guards' |
| 151 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 152 | def file_filter(x): |
| 153 | return input_api.FilterSourceFile( |
Ryan Savitski | 135038e | 2020-11-12 20:57:57 +0000 | [diff] [blame] | 154 | x, files_to_check=['.*[.]cc$', '.*[.]h$', tool]) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 155 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 156 | if not input_api.AffectedSourceFiles(file_filter): |
Primiano Tucci | 40e9872 | 2018-02-16 11:50:17 +0000 | [diff] [blame] | 157 | return [] |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 158 | if subprocess.call([tool, '--check-only']): |
| 159 | return [ |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 160 | output_api.PresubmitError('Please run ' + tool + |
| 161 | ' to fix include guards.') |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 162 | ] |
| 163 | return [] |
| 164 | |
| 165 | |
Ryan | 704bc82 | 2020-03-31 02:31:13 +0100 | [diff] [blame] | 166 | def CheckBannedCpp(input_api, output_api): |
Hector Dearman | 53d91b9 | 2019-12-13 17:07:52 +0000 | [diff] [blame] | 167 | bad_cpp = [ |
Hector Dearman | 53d91b9 | 2019-12-13 17:07:52 +0000 | [diff] [blame] | 168 | (r'\bstd::stoi\b', |
| 169 | 'std::stoi throws exceptions prefer base::StringToInt32()'), |
| 170 | (r'\bstd::stol\b', |
| 171 | 'std::stoull throws exceptions prefer base::StringToInt32()'), |
| 172 | (r'\bstd::stoul\b', |
| 173 | 'std::stoull throws exceptions prefer base::StringToUint32()'), |
| 174 | (r'\bstd::stoll\b', |
| 175 | 'std::stoull throws exceptions prefer base::StringToInt64()'), |
| 176 | (r'\bstd::stoull\b', |
| 177 | 'std::stoull throws exceptions prefer base::StringToUint64()'), |
| 178 | (r'\bstd::stof\b', |
| 179 | 'std::stof throws exceptions prefer base::StringToDouble()'), |
| 180 | (r'\bstd::stod\b', |
| 181 | 'std::stod throws exceptions prefer base::StringToDouble()'), |
| 182 | (r'\bstd::stold\b', |
| 183 | 'std::stold throws exceptions prefer base::StringToDouble()'), |
Primiano Tucci | 78cd82b | 2021-10-13 13:50:27 +0100 | [diff] [blame] | 184 | (r'\bstrncpy\b', |
| 185 | 'strncpy does not null-terminate if src > dst. Use base::StringCopy'), |
| 186 | (r'[(=]\s*snprintf\(', |
| 187 | 'snprintf can return > dst_size. Use base::SprintfTrunc'), |
Primiano Tucci | 997ab09 | 2021-10-18 20:53:35 +0100 | [diff] [blame] | 188 | (r'//.*\bDNS\b', |
| 189 | '// DNS (Do Not Ship) found. Did you mean to remove some testing code?'), |
Ryan | 704bc82 | 2020-03-31 02:31:13 +0100 | [diff] [blame] | 190 | (r'\bPERFETTO_EINTR\(close\(', |
| 191 | 'close(2) must not be retried on EINTR on Linux and other OSes ' |
| 192 | 'that we run on, as the fd will be closed.'), |
Primiano Tucci | 58d2dc6 | 2021-06-24 16:03:24 +0100 | [diff] [blame] | 193 | (r'^#include <inttypes.h>', 'Use <cinttypes> rather than <inttypes.h>. ' + |
| 194 | 'See https://github.com/google/perfetto/issues/146'), |
Hector Dearman | 53d91b9 | 2019-12-13 17:07:52 +0000 | [diff] [blame] | 195 | ] |
| 196 | |
| 197 | def file_filter(x): |
Ryan Savitski | 135038e | 2020-11-12 20:57:57 +0000 | [diff] [blame] | 198 | return input_api.FilterSourceFile(x, files_to_check=[r'.*\.h$', r'.*\.cc$']) |
Hector Dearman | 53d91b9 | 2019-12-13 17:07:52 +0000 | [diff] [blame] | 199 | |
| 200 | errors = [] |
| 201 | for f in input_api.AffectedSourceFiles(file_filter): |
| 202 | for line_number, line in f.ChangedContents(): |
Primiano Tucci | 78cd82b | 2021-10-13 13:50:27 +0100 | [diff] [blame] | 203 | if input_api.re.search(r'^\s*//', line): |
| 204 | continue # Skip comments |
Hector Dearman | 53d91b9 | 2019-12-13 17:07:52 +0000 | [diff] [blame] | 205 | for regex, message in bad_cpp: |
| 206 | if input_api.re.search(regex, line): |
| 207 | errors.append( |
Ryan | 704bc82 | 2020-03-31 02:31:13 +0100 | [diff] [blame] | 208 | output_api.PresubmitError('Banned pattern:\n {}:{} {}'.format( |
Hector Dearman | 53d91b9 | 2019-12-13 17:07:52 +0000 | [diff] [blame] | 209 | f.LocalPath(), line_number, message))) |
| 210 | return errors |
| 211 | |
| 212 | |
Primiano Tucci | 0fd92a9 | 2023-07-17 11:47:38 -0700 | [diff] [blame] | 213 | def CheckBadCppPatterns(input_api, output_api): |
| 214 | bad_patterns = [ |
| 215 | (r'.*/tracing_service_impl[.]cc$', r'\btrigger_config\(\)', |
| 216 | 'Use GetTriggerMode(session->config) rather than .trigger_config()'), |
| 217 | ] |
| 218 | errors = [] |
| 219 | for file_regex, code_regex, message in bad_patterns: |
| 220 | filt = lambda x: input_api.FilterSourceFile(x, files_to_check=[file_regex]) |
| 221 | for f in input_api.AffectedSourceFiles(filt): |
| 222 | for line_number, line in f.ChangedContents(): |
| 223 | if input_api.re.search(r'^\s*//', line): |
| 224 | continue # Skip comments |
| 225 | if input_api.re.search(code_regex, line): |
| 226 | errors.append( |
| 227 | output_api.PresubmitError('{}:{} {}'.format( |
| 228 | f.LocalPath(), line_number, message))) |
| 229 | return errors |
| 230 | |
| 231 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 232 | def CheckIncludeViolations(input_api, output_api): |
Bruce Dawson | 7627d04 | 2023-07-17 10:08:24 -0700 | [diff] [blame] | 233 | # The script invocation doesn't work on Windows. |
| 234 | if input_api.is_windows: |
| 235 | return [] |
| 236 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 237 | tool = 'tools/check_include_violations' |
| 238 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 239 | def file_filter(x): |
Ryan Savitski | 135038e | 2020-11-12 20:57:57 +0000 | [diff] [blame] | 240 | return input_api.FilterSourceFile( |
| 241 | x, files_to_check=['include/.*[.]h$', tool]) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 242 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 243 | if not input_api.AffectedSourceFiles(file_filter): |
| 244 | return [] |
| 245 | if subprocess.call([tool]): |
| 246 | return [output_api.PresubmitError(tool + ' failed.')] |
| 247 | return [] |
Primiano Tucci | 40e9872 | 2018-02-16 11:50:17 +0000 | [diff] [blame] | 248 | |
| 249 | |
Hector Dearman | b7fa544 | 2018-11-08 18:39:32 +0000 | [diff] [blame] | 250 | def CheckBinaryDescriptors(input_api, output_api): |
Bruce Dawson | 7627d04 | 2023-07-17 10:08:24 -0700 | [diff] [blame] | 251 | # The script invocation doesn't work on Windows. |
| 252 | if input_api.is_windows: |
| 253 | return [] |
| 254 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 255 | tool = 'tools/gen_binary_descriptors' |
| 256 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 257 | def file_filter(x): |
| 258 | return input_api.FilterSourceFile( |
Ryan Savitski | 135038e | 2020-11-12 20:57:57 +0000 | [diff] [blame] | 259 | x, files_to_check=['protos/perfetto/.*[.]proto$', '.*[.]h', tool]) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 260 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 261 | if not input_api.AffectedSourceFiles(file_filter): |
Hector Dearman | b7fa544 | 2018-11-08 18:39:32 +0000 | [diff] [blame] | 262 | return [] |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 263 | if subprocess.call([tool, '--check-only']): |
| 264 | return [ |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 265 | output_api.PresubmitError('Please run ' + tool + |
| 266 | ' to update binary descriptors.') |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 267 | ] |
| 268 | return [] |
Hector Dearman | b7fa544 | 2018-11-08 18:39:32 +0000 | [diff] [blame] | 269 | |
| 270 | |
Primiano Tucci | c501080 | 2018-01-19 17:13:21 +0000 | [diff] [blame] | 271 | def CheckMergedTraceConfigProto(input_api, output_api): |
Bruce Dawson | 7627d04 | 2023-07-17 10:08:24 -0700 | [diff] [blame] | 272 | # The script invocation doesn't work on Windows. |
| 273 | if input_api.is_windows: |
| 274 | return [] |
| 275 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 276 | tool = 'tools/gen_merged_protos' |
| 277 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 278 | def build_file_filter(x): |
| 279 | return input_api.FilterSourceFile( |
Ryan Savitski | 135038e | 2020-11-12 20:57:57 +0000 | [diff] [blame] | 280 | x, files_to_check=['protos/perfetto/.*[.]proto$', tool]) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 281 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 282 | if not input_api.AffectedSourceFiles(build_file_filter): |
Primiano Tucci | c501080 | 2018-01-19 17:13:21 +0000 | [diff] [blame] | 283 | return [] |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 284 | if subprocess.call([tool, '--check-only']): |
| 285 | return [ |
| 286 | output_api.PresubmitError( |
| 287 | 'perfetto_config.proto or perfetto_trace.proto is out of ' + |
| 288 | 'date. Please run ' + tool + ' to update it.') |
| 289 | ] |
| 290 | return [] |
Florian Mayer | 640b7ae | 2018-05-09 15:28:32 +0100 | [diff] [blame] | 291 | |
| 292 | |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 293 | # Prevent removing or changing lines in event_list. |
| 294 | def CheckProtoEventList(input_api, output_api): |
Florian Mayer | 640b7ae | 2018-05-09 15:28:32 +0100 | [diff] [blame] | 295 | for f in input_api.AffectedFiles(): |
Hector Dearman | 7ea83c9 | 2022-05-12 15:21:49 +0100 | [diff] [blame] | 296 | if f.LocalPath() != 'src/tools/ftrace_proto_gen/event_list': |
Florian Mayer | 640b7ae | 2018-05-09 15:28:32 +0100 | [diff] [blame] | 297 | continue |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 298 | if any((not new_line.startswith('removed')) and new_line != old_line |
Hector Dearman | d88945e | 2021-12-07 18:56:40 +0000 | [diff] [blame] | 299 | for old_line, new_line in zip(f.OldContents(), f.NewContents())): |
Florian Mayer | 640b7ae | 2018-05-09 15:28:32 +0100 | [diff] [blame] | 300 | return [ |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 301 | output_api.PresubmitError( |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 302 | 'event_list only has two supported changes: ' |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 303 | 'appending a new line, and replacing a line with removed.') |
Florian Mayer | 640b7ae | 2018-05-09 15:28:32 +0100 | [diff] [blame] | 304 | ] |
| 305 | return [] |
Anindita Ghosh | 2aa4e42 | 2020-06-26 15:48:32 +0100 | [diff] [blame] | 306 | |
| 307 | |
| 308 | def CheckProtoComments(input_api, output_api): |
Bruce Dawson | 7627d04 | 2023-07-17 10:08:24 -0700 | [diff] [blame] | 309 | # The script invocation doesn't work on Windows. |
| 310 | if input_api.is_windows: |
| 311 | return [] |
| 312 | |
Anindita Ghosh | 2aa4e42 | 2020-06-26 15:48:32 +0100 | [diff] [blame] | 313 | tool = 'tools/check_proto_comments' |
| 314 | |
| 315 | def file_filter(x): |
| 316 | return input_api.FilterSourceFile( |
Ryan Savitski | 135038e | 2020-11-12 20:57:57 +0000 | [diff] [blame] | 317 | x, files_to_check=['protos/perfetto/.*[.]proto$', tool]) |
Anindita Ghosh | 2aa4e42 | 2020-06-26 15:48:32 +0100 | [diff] [blame] | 318 | |
| 319 | if not input_api.AffectedSourceFiles(file_filter): |
| 320 | return [] |
| 321 | if subprocess.call([tool]): |
| 322 | return [output_api.PresubmitError(tool + ' failed')] |
| 323 | return [] |
Lalit Maganti | e0e8bdb | 2021-01-11 19:43:55 +0000 | [diff] [blame] | 324 | |
| 325 | |
Anna Mayzner | 412e056 | 2022-11-25 09:55:51 +0000 | [diff] [blame] | 326 | def CheckSqlModules(input_api, output_api): |
Bruce Dawson | 7627d04 | 2023-07-17 10:08:24 -0700 | [diff] [blame] | 327 | # The script invocation doesn't work on Windows. |
| 328 | if input_api.is_windows: |
| 329 | return [] |
| 330 | |
Anna Mayzner | 412e056 | 2022-11-25 09:55:51 +0000 | [diff] [blame] | 331 | tool = 'tools/check_sql_modules.py' |
| 332 | |
| 333 | def file_filter(x): |
| 334 | return input_api.FilterSourceFile( |
Alexander Timin | 8e1c5e8 | 2023-11-06 14:21:12 +0000 | [diff] [blame] | 335 | x, |
| 336 | files_to_check=[ |
| 337 | 'src/trace_processor/perfetto_sql/stdlib/.*[.]sql$', tool |
| 338 | ]) |
Anna Mayzner | 412e056 | 2022-11-25 09:55:51 +0000 | [diff] [blame] | 339 | |
| 340 | if not input_api.AffectedSourceFiles(file_filter): |
| 341 | return [] |
| 342 | if subprocess.call([tool]): |
| 343 | return [output_api.PresubmitError(tool + ' failed')] |
| 344 | return [] |
| 345 | |
| 346 | |
Lalit Maganti | e0e8bdb | 2021-01-11 19:43:55 +0000 | [diff] [blame] | 347 | def CheckSqlMetrics(input_api, output_api): |
Bruce Dawson | 7627d04 | 2023-07-17 10:08:24 -0700 | [diff] [blame] | 348 | # The script invocation doesn't work on Windows. |
| 349 | if input_api.is_windows: |
| 350 | return [] |
| 351 | |
Lalit Maganti | e0e8bdb | 2021-01-11 19:43:55 +0000 | [diff] [blame] | 352 | tool = 'tools/check_sql_metrics.py' |
| 353 | |
| 354 | def file_filter(x): |
| 355 | return input_api.FilterSourceFile( |
| 356 | x, files_to_check=['src/trace_processor/metrics/.*[.]sql$', tool]) |
| 357 | |
| 358 | if not input_api.AffectedSourceFiles(file_filter): |
| 359 | return [] |
| 360 | if subprocess.call([tool]): |
| 361 | return [output_api.PresubmitError(tool + ' failed')] |
| 362 | return [] |
Primiano Tucci | 3d4217d | 2021-11-05 11:11:51 +0000 | [diff] [blame] | 363 | |
| 364 | |
| 365 | def CheckTestData(input_api, output_api): |
Bruce Dawson | 7627d04 | 2023-07-17 10:08:24 -0700 | [diff] [blame] | 366 | # The script invocation doesn't work on Windows. |
| 367 | if input_api.is_windows: |
| 368 | return [] |
| 369 | |
Primiano Tucci | 3d4217d | 2021-11-05 11:11:51 +0000 | [diff] [blame] | 370 | tool = 'tools/test_data' |
| 371 | if subprocess.call([tool, 'status', '--quiet']): |
| 372 | return [ |
| 373 | output_api.PresubmitError( |
Mohit Saini | 8abc524 | 2022-06-24 11:16:03 +0100 | [diff] [blame] | 374 | '//test/data is out of sync. Run ' + tool + ' status for more. \n' |
| 375 | 'If you rebaselined UI tests or added a new test trace, run:' |
| 376 | '`tools/test_data upload`. Otherwise run `tools/install-build-deps`' |
Andrew Shulaev | d85d05f | 2022-07-04 11:54:42 +0100 | [diff] [blame] | 377 | ' or `tools/test_data download --overwrite` to sync local test_data' |
| 378 | ) |
Primiano Tucci | 3d4217d | 2021-11-05 11:11:51 +0000 | [diff] [blame] | 379 | ] |
| 380 | return [] |
Primiano Tucci | 11d94e1 | 2022-08-02 17:44:33 +0100 | [diff] [blame] | 381 | |
| 382 | |
| 383 | def CheckAmalgamatedPythonTools(input_api, output_api): |
Bruce Dawson | 7627d04 | 2023-07-17 10:08:24 -0700 | [diff] [blame] | 384 | # The script invocation doesn't work on Windows. |
| 385 | if input_api.is_windows: |
| 386 | return [] |
| 387 | |
Primiano Tucci | 11d94e1 | 2022-08-02 17:44:33 +0100 | [diff] [blame] | 388 | tool = 'tools/gen_amalgamated_python_tools' |
| 389 | |
| 390 | # If no GN files were modified, bail out. |
| 391 | def build_file_filter(x): |
| 392 | return input_api.FilterSourceFile(x, files_to_check=('python/.*$', tool)) |
| 393 | |
| 394 | if not input_api.AffectedSourceFiles(build_file_filter): |
| 395 | return [] |
| 396 | if subprocess.call([tool, '--check-only']): |
| 397 | return [ |
| 398 | output_api.PresubmitError( |
| 399 | 'amalgamated python tools/ are out of date. ' + 'Run ' + tool + |
| 400 | ' to update them.') |
| 401 | ] |
| 402 | return [] |