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 | |
| 20 | |
| 21 | def RunAndReportIfLong(func, *args, **kargs): |
| 22 | start = time.time() |
| 23 | results = func(*args, **kargs) |
| 24 | end = time.time() |
| 25 | limit = 0.5 # seconds |
| 26 | name = func.__name__ |
| 27 | runtime = end - start |
| 28 | if runtime > limit: |
| 29 | print("{} took >{:.2}s ({:.2}s)".format(name, limit, runtime)) |
| 30 | return results |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame] | 31 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 32 | |
Hector Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 33 | def CheckChange(input, output): |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 34 | # There apparently is no way to wrap strings in blueprints, so ignore long |
| 35 | # lines in them. |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 36 | def long_line_sources(x): |
| 37 | return input.FilterSourceFile( |
| 38 | x, |
Ryan Savitski | 135038e | 2020-11-12 20:57:57 +0000 | [diff] [blame] | 39 | files_to_check='.*', |
| 40 | files_to_skip=[ |
Lalit Maganti | 3dc0ffe | 2021-06-09 13:27:52 +0100 | [diff] [blame] | 41 | 'Android[.]bp', |
| 42 | '.*[.]json$', |
| 43 | '.*[.]sql$', |
| 44 | '.*[.]out$', |
| 45 | 'test/trace_processor/.*/index$', |
| 46 | '(.*/)?BUILD$', |
| 47 | 'WORKSPACE', |
| 48 | '.*/Makefile$', |
| 49 | '/perfetto_build_flags.h$', |
| 50 | "infra/luci/.*", |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 51 | ]) |
| 52 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 53 | results = [] |
Hector Dearman | 2cc71f6 | 2021-07-14 10:28:58 +0100 | [diff] [blame] | 54 | results += RunAndReportIfLong(input.canned_checks.CheckDoNotSubmit, input, |
| 55 | output) |
| 56 | results += RunAndReportIfLong(input.canned_checks.CheckChangeHasNoTabs, input, |
| 57 | output) |
| 58 | results += RunAndReportIfLong( |
| 59 | input.canned_checks.CheckLongLines, |
| 60 | input, |
| 61 | output, |
| 62 | 80, |
| 63 | source_file_filter=long_line_sources) |
| 64 | results += RunAndReportIfLong( |
| 65 | input.canned_checks.CheckPatchFormatted, input, output, check_js=True) |
| 66 | results += RunAndReportIfLong(input.canned_checks.CheckGNFormatted, input, |
| 67 | output) |
| 68 | results += RunAndReportIfLong(CheckIncludeGuards, input, output) |
| 69 | results += RunAndReportIfLong(CheckIncludeViolations, input, output) |
| 70 | results += RunAndReportIfLong(CheckProtoComments, input, output) |
| 71 | results += RunAndReportIfLong(CheckBuild, input, output) |
| 72 | results += RunAndReportIfLong(CheckAndroidBlueprint, input, output) |
| 73 | results += RunAndReportIfLong(CheckBinaryDescriptors, input, output) |
| 74 | results += RunAndReportIfLong(CheckMergedTraceConfigProto, input, output) |
| 75 | results += RunAndReportIfLong(CheckProtoEventList, input, output) |
| 76 | results += RunAndReportIfLong(CheckBannedCpp, input, output) |
| 77 | results += RunAndReportIfLong(CheckSqlMetrics, input, output) |
Primiano Tucci | 3d4217d | 2021-11-05 11:11:51 +0000 | [diff] [blame] | 78 | results += RunAndReportIfLong(CheckTestData, input, output) |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 79 | return results |
Hector Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 80 | |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame] | 81 | |
Hector Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 82 | def CheckChangeOnUpload(input_api, output_api): |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 83 | return CheckChange(input_api, output_api) |
Hector Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 84 | |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame] | 85 | |
Hector Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 86 | def CheckChangeOnCommit(input_api, output_api): |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 87 | return CheckChange(input_api, output_api) |
Hector Dearman | 534765e | 2017-11-01 11:17:38 +0000 | [diff] [blame] | 88 | |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame] | 89 | |
Lalit Maganti | 279ecde | 2019-04-01 16:57:12 +0100 | [diff] [blame] | 90 | def CheckBuild(input_api, output_api): |
Primiano Tucci | 9c41165 | 2019-08-27 07:13:59 +0200 | [diff] [blame] | 91 | tool = 'tools/gen_bazel' |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 92 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 93 | # If no GN files were modified, bail out. |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 94 | def build_file_filter(x): |
| 95 | return input_api.FilterSourceFile( |
Ryan Savitski | 135038e | 2020-11-12 20:57:57 +0000 | [diff] [blame] | 96 | x, files_to_check=('.*BUILD[.]gn$', '.*[.]gni$', 'BUILD\.extras', tool)) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 97 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 98 | if not input_api.AffectedSourceFiles(build_file_filter): |
Lalit Maganti | 279ecde | 2019-04-01 16:57:12 +0100 | [diff] [blame] | 99 | return [] |
Primiano Tucci | 9c41165 | 2019-08-27 07:13:59 +0200 | [diff] [blame] | 100 | if subprocess.call([tool, '--check-only']): |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 101 | return [ |
| 102 | output_api.PresubmitError('Bazel BUILD(s) are out of date. Run ' + |
| 103 | tool + ' to update them.') |
| 104 | ] |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 105 | return [] |
| 106 | |
Lalit Maganti | 279ecde | 2019-04-01 16:57:12 +0100 | [diff] [blame] | 107 | |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame] | 108 | def CheckAndroidBlueprint(input_api, output_api): |
Primiano Tucci | 9c41165 | 2019-08-27 07:13:59 +0200 | [diff] [blame] | 109 | tool = 'tools/gen_android_bp' |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 110 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 111 | # If no GN files were modified, bail out. |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 112 | def build_file_filter(x): |
| 113 | return input_api.FilterSourceFile( |
Ryan Savitski | 135038e | 2020-11-12 20:57:57 +0000 | [diff] [blame] | 114 | x, files_to_check=('.*BUILD[.]gn$', '.*[.]gni$', tool)) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 115 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 116 | if not input_api.AffectedSourceFiles(build_file_filter): |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame] | 117 | return [] |
Primiano Tucci | 9c41165 | 2019-08-27 07:13:59 +0200 | [diff] [blame] | 118 | if subprocess.call([tool, '--check-only']): |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 119 | return [ |
| 120 | output_api.PresubmitError('Android build files are out of date. ' + |
| 121 | 'Run ' + tool + ' to update them.') |
| 122 | ] |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 123 | return [] |
| 124 | |
Primiano Tucci | c501080 | 2018-01-19 17:13:21 +0000 | [diff] [blame] | 125 | |
Primiano Tucci | 40e9872 | 2018-02-16 11:50:17 +0000 | [diff] [blame] | 126 | def CheckIncludeGuards(input_api, output_api): |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 127 | tool = 'tools/fix_include_guards' |
| 128 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 129 | def file_filter(x): |
| 130 | return input_api.FilterSourceFile( |
Ryan Savitski | 135038e | 2020-11-12 20:57:57 +0000 | [diff] [blame] | 131 | x, files_to_check=['.*[.]cc$', '.*[.]h$', tool]) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 132 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 133 | if not input_api.AffectedSourceFiles(file_filter): |
Primiano Tucci | 40e9872 | 2018-02-16 11:50:17 +0000 | [diff] [blame] | 134 | return [] |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 135 | if subprocess.call([tool, '--check-only']): |
| 136 | return [ |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 137 | output_api.PresubmitError('Please run ' + tool + |
| 138 | ' to fix include guards.') |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 139 | ] |
| 140 | return [] |
| 141 | |
| 142 | |
Ryan | 704bc82 | 2020-03-31 02:31:13 +0100 | [diff] [blame] | 143 | def CheckBannedCpp(input_api, output_api): |
Hector Dearman | 53d91b9 | 2019-12-13 17:07:52 +0000 | [diff] [blame] | 144 | bad_cpp = [ |
Hector Dearman | 53d91b9 | 2019-12-13 17:07:52 +0000 | [diff] [blame] | 145 | (r'\bstd::stoi\b', |
| 146 | 'std::stoi throws exceptions prefer base::StringToInt32()'), |
| 147 | (r'\bstd::stol\b', |
| 148 | 'std::stoull throws exceptions prefer base::StringToInt32()'), |
| 149 | (r'\bstd::stoul\b', |
| 150 | 'std::stoull throws exceptions prefer base::StringToUint32()'), |
| 151 | (r'\bstd::stoll\b', |
| 152 | 'std::stoull throws exceptions prefer base::StringToInt64()'), |
| 153 | (r'\bstd::stoull\b', |
| 154 | 'std::stoull throws exceptions prefer base::StringToUint64()'), |
| 155 | (r'\bstd::stof\b', |
| 156 | 'std::stof throws exceptions prefer base::StringToDouble()'), |
| 157 | (r'\bstd::stod\b', |
| 158 | 'std::stod throws exceptions prefer base::StringToDouble()'), |
| 159 | (r'\bstd::stold\b', |
| 160 | 'std::stold throws exceptions prefer base::StringToDouble()'), |
Primiano Tucci | 78cd82b | 2021-10-13 13:50:27 +0100 | [diff] [blame] | 161 | (r'\bstrncpy\b', |
| 162 | 'strncpy does not null-terminate if src > dst. Use base::StringCopy'), |
| 163 | (r'[(=]\s*snprintf\(', |
| 164 | 'snprintf can return > dst_size. Use base::SprintfTrunc'), |
Primiano Tucci | 997ab09 | 2021-10-18 20:53:35 +0100 | [diff] [blame] | 165 | (r'//.*\bDNS\b', |
| 166 | '// DNS (Do Not Ship) found. Did you mean to remove some testing code?'), |
Ryan | 704bc82 | 2020-03-31 02:31:13 +0100 | [diff] [blame] | 167 | (r'\bPERFETTO_EINTR\(close\(', |
| 168 | 'close(2) must not be retried on EINTR on Linux and other OSes ' |
| 169 | 'that we run on, as the fd will be closed.'), |
Primiano Tucci | 58d2dc6 | 2021-06-24 16:03:24 +0100 | [diff] [blame] | 170 | (r'^#include <inttypes.h>', 'Use <cinttypes> rather than <inttypes.h>. ' + |
| 171 | 'See https://github.com/google/perfetto/issues/146'), |
Hector Dearman | 53d91b9 | 2019-12-13 17:07:52 +0000 | [diff] [blame] | 172 | ] |
| 173 | |
| 174 | def file_filter(x): |
Ryan Savitski | 135038e | 2020-11-12 20:57:57 +0000 | [diff] [blame] | 175 | return input_api.FilterSourceFile(x, files_to_check=[r'.*\.h$', r'.*\.cc$']) |
Hector Dearman | 53d91b9 | 2019-12-13 17:07:52 +0000 | [diff] [blame] | 176 | |
| 177 | errors = [] |
| 178 | for f in input_api.AffectedSourceFiles(file_filter): |
| 179 | for line_number, line in f.ChangedContents(): |
Primiano Tucci | 78cd82b | 2021-10-13 13:50:27 +0100 | [diff] [blame] | 180 | if input_api.re.search(r'^\s*//', line): |
| 181 | continue # Skip comments |
Hector Dearman | 53d91b9 | 2019-12-13 17:07:52 +0000 | [diff] [blame] | 182 | for regex, message in bad_cpp: |
| 183 | if input_api.re.search(regex, line): |
| 184 | errors.append( |
Ryan | 704bc82 | 2020-03-31 02:31:13 +0100 | [diff] [blame] | 185 | output_api.PresubmitError('Banned pattern:\n {}:{} {}'.format( |
Hector Dearman | 53d91b9 | 2019-12-13 17:07:52 +0000 | [diff] [blame] | 186 | f.LocalPath(), line_number, message))) |
| 187 | return errors |
| 188 | |
| 189 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 190 | def CheckIncludeViolations(input_api, output_api): |
| 191 | tool = 'tools/check_include_violations' |
| 192 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 193 | def file_filter(x): |
Ryan Savitski | 135038e | 2020-11-12 20:57:57 +0000 | [diff] [blame] | 194 | return input_api.FilterSourceFile( |
| 195 | x, files_to_check=['include/.*[.]h$', tool]) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 196 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 197 | if not input_api.AffectedSourceFiles(file_filter): |
| 198 | return [] |
| 199 | if subprocess.call([tool]): |
| 200 | return [output_api.PresubmitError(tool + ' failed.')] |
| 201 | return [] |
Primiano Tucci | 40e9872 | 2018-02-16 11:50:17 +0000 | [diff] [blame] | 202 | |
| 203 | |
Hector Dearman | b7fa544 | 2018-11-08 18:39:32 +0000 | [diff] [blame] | 204 | def CheckBinaryDescriptors(input_api, output_api): |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 205 | tool = 'tools/gen_binary_descriptors' |
| 206 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 207 | def file_filter(x): |
| 208 | return input_api.FilterSourceFile( |
Ryan Savitski | 135038e | 2020-11-12 20:57:57 +0000 | [diff] [blame] | 209 | x, files_to_check=['protos/perfetto/.*[.]proto$', '.*[.]h', tool]) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 210 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 211 | if not input_api.AffectedSourceFiles(file_filter): |
Hector Dearman | b7fa544 | 2018-11-08 18:39:32 +0000 | [diff] [blame] | 212 | return [] |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 213 | if subprocess.call([tool, '--check-only']): |
| 214 | return [ |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 215 | output_api.PresubmitError('Please run ' + tool + |
| 216 | ' to update binary descriptors.') |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 217 | ] |
| 218 | return [] |
Hector Dearman | b7fa544 | 2018-11-08 18:39:32 +0000 | [diff] [blame] | 219 | |
| 220 | |
Primiano Tucci | c501080 | 2018-01-19 17:13:21 +0000 | [diff] [blame] | 221 | def CheckMergedTraceConfigProto(input_api, output_api): |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 222 | tool = 'tools/gen_merged_protos' |
| 223 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 224 | def build_file_filter(x): |
| 225 | return input_api.FilterSourceFile( |
Ryan Savitski | 135038e | 2020-11-12 20:57:57 +0000 | [diff] [blame] | 226 | x, files_to_check=['protos/perfetto/.*[.]proto$', tool]) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 227 | |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 228 | if not input_api.AffectedSourceFiles(build_file_filter): |
Primiano Tucci | c501080 | 2018-01-19 17:13:21 +0000 | [diff] [blame] | 229 | return [] |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 230 | if subprocess.call([tool, '--check-only']): |
| 231 | return [ |
| 232 | output_api.PresubmitError( |
| 233 | 'perfetto_config.proto or perfetto_trace.proto is out of ' + |
| 234 | 'date. Please run ' + tool + ' to update it.') |
| 235 | ] |
| 236 | return [] |
Florian Mayer | 640b7ae | 2018-05-09 15:28:32 +0100 | [diff] [blame] | 237 | |
| 238 | |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 239 | # Prevent removing or changing lines in event_list. |
| 240 | def CheckProtoEventList(input_api, output_api): |
Florian Mayer | 640b7ae | 2018-05-09 15:28:32 +0100 | [diff] [blame] | 241 | for f in input_api.AffectedFiles(): |
Hector Dearman | 7ea83c9 | 2022-05-12 15:21:49 +0100 | [diff] [blame] | 242 | if f.LocalPath() != 'src/tools/ftrace_proto_gen/event_list': |
Florian Mayer | 640b7ae | 2018-05-09 15:28:32 +0100 | [diff] [blame] | 243 | continue |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 244 | if any((not new_line.startswith('removed')) and new_line != old_line |
Hector Dearman | d88945e | 2021-12-07 18:56:40 +0000 | [diff] [blame] | 245 | for old_line, new_line in zip(f.OldContents(), f.NewContents())): |
Florian Mayer | 640b7ae | 2018-05-09 15:28:32 +0100 | [diff] [blame] | 246 | return [ |
Primiano Tucci | bf3b19c | 2019-06-01 08:40:26 +0100 | [diff] [blame] | 247 | output_api.PresubmitError( |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 248 | 'event_list only has two supported changes: ' |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 249 | 'appending a new line, and replacing a line with removed.') |
Florian Mayer | 640b7ae | 2018-05-09 15:28:32 +0100 | [diff] [blame] | 250 | ] |
| 251 | return [] |
Anindita Ghosh | 2aa4e42 | 2020-06-26 15:48:32 +0100 | [diff] [blame] | 252 | |
| 253 | |
| 254 | def CheckProtoComments(input_api, output_api): |
| 255 | tool = 'tools/check_proto_comments' |
| 256 | |
| 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$', tool]) |
Anindita Ghosh | 2aa4e42 | 2020-06-26 15:48:32 +0100 | [diff] [blame] | 260 | |
| 261 | if not input_api.AffectedSourceFiles(file_filter): |
| 262 | return [] |
| 263 | if subprocess.call([tool]): |
| 264 | return [output_api.PresubmitError(tool + ' failed')] |
| 265 | return [] |
Lalit Maganti | e0e8bdb | 2021-01-11 19:43:55 +0000 | [diff] [blame] | 266 | |
| 267 | |
| 268 | def CheckSqlMetrics(input_api, output_api): |
| 269 | tool = 'tools/check_sql_metrics.py' |
| 270 | |
| 271 | def file_filter(x): |
| 272 | return input_api.FilterSourceFile( |
| 273 | x, files_to_check=['src/trace_processor/metrics/.*[.]sql$', tool]) |
| 274 | |
| 275 | if not input_api.AffectedSourceFiles(file_filter): |
| 276 | return [] |
| 277 | if subprocess.call([tool]): |
| 278 | return [output_api.PresubmitError(tool + ' failed')] |
| 279 | return [] |
Primiano Tucci | 3d4217d | 2021-11-05 11:11:51 +0000 | [diff] [blame] | 280 | |
| 281 | |
| 282 | def CheckTestData(input_api, output_api): |
| 283 | tool = 'tools/test_data' |
| 284 | if subprocess.call([tool, 'status', '--quiet']): |
| 285 | return [ |
| 286 | output_api.PresubmitError( |
| 287 | '//test/data is out of sync. Run ' + tool + ' status for more. \n' + |
| 288 | 'If you rebaselined UI tests or added a new test trace, run: \n' + |
| 289 | 'tools/test_data upload') |
| 290 | ] |
| 291 | return [] |