diff options
Diffstat (limited to 'chromium/components/subresource_filter/core/common/PRESUBMIT.py')
-rw-r--r-- | chromium/components/subresource_filter/core/common/PRESUBMIT.py | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/chromium/components/subresource_filter/core/common/PRESUBMIT.py b/chromium/components/subresource_filter/core/common/PRESUBMIT.py index 79908dc38b3..9c2c65adcb4 100644 --- a/chromium/components/subresource_filter/core/common/PRESUBMIT.py +++ b/chromium/components/subresource_filter/core/common/PRESUBMIT.py @@ -17,11 +17,17 @@ def CheckIndexedRulesetVersion(input_api, output_api): - components/url_pattern_index/url_pattern_index.cc and kIndexedFormatVersion constant stays intact, this check returns a presubmit warning to make sure the value should not be updated. + + Additionally, checks to ensure the format version in + tools/perf/core/default_local_state.json stays up to date with + kIndexedFormatVersion. """ indexed_ruleset_changed = False indexed_ruleset_version_changed = False + new_indexed_ruleset_version = None + for affected_file in input_api.AffectedFiles(): path = affected_file.LocalPath() if (not 'components/subresource_filter/core/common' in path and @@ -36,14 +42,37 @@ def CheckIndexedRulesetVersion(input_api, output_api): for (_, line) in affected_file.ChangedContents(): if 'kIndexedFormatVersion =' in line: indexed_ruleset_version_changed = True + new_indexed_ruleset_version = int( + indexed_ruleset_line.split()[-1].replace(';','')) break + # If the indexed ruleset version changed, ensure the perf benchmarks are using + # the new format. + out = [] + if indexed_ruleset_version_changed: + assert new_indexed_ruleset_version is not None + current_path = input_api.PresubmitLocalPath() + local_state_path = input_api.os_path.join( + current_path, '..', '..', '..', '..', 'tools', 'perf', 'core', + 'default_local_state.json') + + assert input_api.os_path.exists(local_state_path) + with open(local_state_path, 'r') as f: + json_state = input_api.json.load(f) + version = json_state['subresource_filter']['ruleset_version']['format'] + if new_indexed_ruleset_version != version: + out.append(output_api.PresubmitPromptWarning( + 'Please make sure that kIndexedFormatVersion (%d) and ' + 'the format version in tools/perf/core/default_local_state.json ' + '(%d) are in sync' % (new_indexed_ruleset_version, version))) + if indexed_ruleset_changed and not indexed_ruleset_version_changed: - return [output_api.PresubmitPromptWarning( + out.append(output_api.PresubmitPromptWarning( 'Please make sure that UrlPatternIndex/IndexedRuleset modifications in ' '*.fbs and url_pattern_index.cc/indexed_ruleset.cc do not require ' - 'updating RulesetIndexer::kIndexedFormatVersion.')] - return [] + 'updating RulesetIndexer::kIndexedFormatVersion.')) + + return out def CheckChangeOnUpload(input_api, output_api): return CheckIndexedRulesetVersion(input_api, output_api) |