Karan Bhatia | 7ed729ec | 2018-08-25 01:41:42 | [diff] [blame] | 1 | # Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Presubmit script for components/url_pattern_index directory. |
| 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 | """ |
| 10 | |
| 11 | def CheckUrlPatternIndexFormatVersion(input_api, output_api): |
| 12 | """ Checks the kUrlPatternIndexFormatVersion is modified when necessary. |
| 13 | |
| 14 | Whenever any of the following files is changed: |
| 15 | - components/url_pattern_index/flat/url_pattern_index.fbs |
| 16 | - components/url_pattern_index/url_pattern_index.cc |
| 17 | and kUrlPatternIndexFormatVersion stays intact, this check returns a |
| 18 | presubmit warning to make sure the value is updated if necessary. |
| 19 | """ |
| 20 | |
| 21 | url_pattern_index_files_changed = False |
| 22 | url_pattern_index_version_changed = False |
| 23 | |
| 24 | for affected_file in input_api.AffectedFiles(): |
| 25 | basename = input_api.basename(affected_file.LocalPath()) |
| 26 | |
| 27 | if (basename == 'url_pattern_index.fbs' or |
| 28 | basename == 'url_pattern_index.cc'): |
| 29 | url_pattern_index_files_changed = True |
| 30 | |
| 31 | if basename == 'url_pattern_index.h': |
| 32 | for (_, line) in affected_file.ChangedContents(): |
| 33 | if 'constexpr int kUrlPatternIndexFormatVersion' in line: |
| 34 | url_pattern_index_version_changed = True |
| 35 | break |
| 36 | |
| 37 | out = [] |
| 38 | if url_pattern_index_files_changed and not url_pattern_index_version_changed: |
| 39 | out.append(output_api.PresubmitPromptWarning( |
| 40 | 'Please make sure that url_pattern_index::kUrlPatternIndexFormatVersion' |
| 41 | ' is modified if necessary.')) |
| 42 | |
| 43 | return out |
| 44 | |
| 45 | def CheckChangeOnUpload(input_api, output_api): |
| 46 | return CheckUrlPatternIndexFormatVersion(input_api, output_api) |