Commit e27f9842 authored by pkalinnikov's avatar pkalinnikov Committed by Commit bot

Add presubmit script checking FlatBuffer changes.

This change introduces a presubmit check ensuring that developers modifying
.fbs files in subresource_filter get reminded to change IndexedRuleset format
version (if that is required).

BUG=609747

Review-Url: https://codereview.chromium.org/2850813003
Cr-Commit-Position: refs/heads/master@{#468618}
parent 2091c3c5
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Presubmit script for subresource_filter component's core/common directory.
See https://www.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details about the presubmit API built into depot_tools.
"""
def CheckIndexedRulesetVersion(input_api, output_api):
""" Checks that IndexedRuleset format version is modified when necessary.
Whenever a *.fbs or indexed_ruleset.cc file is touched in
components/subresource_filter/core/common and kIndexedFormatVersion constant
is not changed, this check returns a presubmit warning to make sure the value
should not be updated.
"""
indexed_ruleset_changed = False
indexed_ruleset_version_changed = False
for affected_file in input_api.AffectedFiles():
path = affected_file.LocalPath()
if not 'components/subresource_filter/core/common' in path:
continue
basename = input_api.basename(path)
if basename.endswith('.fbs') or basename == 'indexed_ruleset.cc':
indexed_ruleset_changed = True
if basename == 'indexed_ruleset.cc':
for (_, line) in affected_file.ChangedContents():
if 'kIndexedFormatVersion =' in line:
indexed_ruleset_version_changed = True
break
if indexed_ruleset_changed and not indexed_ruleset_version_changed:
return [output_api.PresubmitPromptWarning(
'Please make sure that IndexedRuleset modifications in *.fbs and '
'indexed_ruleset.cc do not require updating '
'RulesetIndexer::kIndexedFormatVersion.')]
return []
def CheckChangeOnUpload(input_api, output_api):
return CheckIndexedRulesetVersion(input_api, output_api)
...@@ -39,6 +39,12 @@ static_assert(kNGramSize <= sizeof(NGram), "NGram type is too narrow."); ...@@ -39,6 +39,12 @@ static_assert(kNGramSize <= sizeof(NGram), "NGram type is too narrow.");
class RulesetIndexer { class RulesetIndexer {
public: public:
// The current binary format version of the indexed ruleset. // The current binary format version of the indexed ruleset.
//
// Increase this value when introducing an incompatible change in
// IndexedRuleset format, or otherwise willing to nudge clients to rebuild
// their ruleset (e.g., a change is compatible, but significantly reduces the
// size of the buffer). Note: The PRESUBMIT.py script tries to keep
// contributors aware of that.
static const int kIndexedFormatVersion; static const int kIndexedFormatVersion;
RulesetIndexer(); RulesetIndexer();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment