| OLD | NEW |
| 1 # Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Presubmit script for sync | 5 """Presubmit script for sync component. |
| 6 This checks that ModelTypeInfo entries in model_type.cc follow conventions. | 6 |
| 7 See CheckModelTypeInfoMap or model_type.cc for more detail on the rules. | 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 8 for more details about the presubmit API built into depot_tools. |
| 8 """ | 9 """ |
| 9 | 10 |
| 10 import os | 11 import os |
| 12 import re |
| 11 | 13 |
| 12 # Some definitions don't follow all the conventions we want to enforce. | 14 # Some definitions don't follow all the conventions we want to enforce. |
| 13 # It's either difficult or impossible to fix this, so we ignore the problem(s). | 15 # It's either difficult or impossible to fix this, so we ignore the problem(s). |
| 14 GRANDFATHERED_MODEL_TYPES = [ | 16 GRANDFATHERED_MODEL_TYPES = [ |
| 15 'UNSPECIFIED', # Doesn't have a root tag or notification type. | 17 'UNSPECIFIED', # Doesn't have a root tag or notification type. |
| 16 'TOP_LEVEL_FOLDER', # Doesn't have a root tag or notification type. | 18 'TOP_LEVEL_FOLDER', # Doesn't have a root tag or notification type. |
| 17 'AUTOFILL_WALLET_DATA', # Root tag and model type string lack DATA suffix. | 19 'AUTOFILL_WALLET_DATA', # Root tag and model type string lack DATA suffix. |
| 18 'APP_SETTINGS', # Model type string has inconsistent capitalization. | 20 'APP_SETTINGS', # Model type string has inconsistent capitalization. |
| 19 'EXTENSION_SETTINGS', # Model type string has inconsistent capitalization. | 21 'EXTENSION_SETTINGS', # Model type string has inconsistent capitalization. |
| 20 'SUPERVISED_USER_SETTINGS', # Root tag and model type string replace | 22 'SUPERVISED_USER_SETTINGS', # Root tag and model type string replace |
| (...skipping 29 matching lines...) Expand all Loading... |
| 50 # in model_type.cc. | 52 # in model_type.cc. |
| 51 MODEL_TYPE_START_PATTERN = '^const ModelTypeInfo kModelTypeInfoMap' | 53 MODEL_TYPE_START_PATTERN = '^const ModelTypeInfo kModelTypeInfoMap' |
| 52 MODEL_TYPE_END_PATTERN = '^\};' | 54 MODEL_TYPE_END_PATTERN = '^\};' |
| 53 | 55 |
| 54 # Strings relating to files we'll need to read. | 56 # Strings relating to files we'll need to read. |
| 55 # model_type.cc is where the ModelTypeInfoMap is | 57 # model_type.cc is where the ModelTypeInfoMap is |
| 56 # sync.proto is where the proto definitions for ModelTypes are. | 58 # sync.proto is where the proto definitions for ModelTypes are. |
| 57 PROTO_FILE_PATH = './protocol/sync.proto' | 59 PROTO_FILE_PATH = './protocol/sync.proto' |
| 58 MODEL_TYPE_FILE_NAME = 'model_type.cc' | 60 MODEL_TYPE_FILE_NAME = 'model_type.cc' |
| 59 | 61 |
| 60 | 62 SYNC_SOURCE_FILES = (r'^components[\\/]sync[\\/].*\.(cc|h)$',) |
| 61 def CheckChangeOnUpload(input_api, output_api): | |
| 62 """Preupload check function required by presubmit convention. | |
| 63 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | |
| 64 """ | |
| 65 for f in input_api.AffectedFiles(): | |
| 66 if(f.LocalPath().endswith(MODEL_TYPE_FILE_NAME)): | |
| 67 return CheckModelTypeInfoMap(input_api, output_api, f) | |
| 68 return [] | |
| 69 | |
| 70 | |
| 71 def CheckChangeOnCommit(input_api, output_api): | |
| 72 """Precommit check function required by presubmit convention. | |
| 73 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | |
| 74 """ | |
| 75 for f in input_api.AffectedFiles(): | |
| 76 if f.LocalPath().endswith(MODEL_TYPE_FILE_NAME): | |
| 77 return CheckModelTypeInfoMap(input_api, output_api, f) | |
| 78 return [] | |
| 79 | |
| 80 | 63 |
| 81 def CheckModelTypeInfoMap(input_api, output_api, model_type_file): | 64 def CheckModelTypeInfoMap(input_api, output_api, model_type_file): |
| 82 """Checks the kModelTypeInfoMap in model_type.cc follows conventions. | 65 """Checks the kModelTypeInfoMap in model_type.cc follows conventions. |
| 83 Checks that the kModelTypeInfoMap follows the below rules: | 66 Checks that the kModelTypeInfoMap follows the below rules: |
| 84 1) The model type string should match the model type name, but with | 67 1) The model type string should match the model type name, but with |
| 85 only the first letter capitalized and spaces instead of underscores. | 68 only the first letter capitalized and spaces instead of underscores. |
| 86 2) The root tag should be the same as the model type but all lowercase. | 69 2) The root tag should be the same as the model type but all lowercase. |
| 87 3) The notification type should match the proto message name. | 70 3) The notification type should match the proto message name. |
| 88 4) No duplicate data across model types. | 71 4) No duplicate data across model types. |
| 89 Args: | 72 Args: |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 Args: | 355 Args: |
| 373 field_number: string representation of a field number enum reference | 356 field_number: string representation of a field number enum reference |
| 374 Returns: | 357 Returns: |
| 375 A string that is the corresponding proto field data type. e.g. | 358 A string that is the corresponding proto field data type. e.g. |
| 376 FieldNumberToPrototypeString('EntitySpecifics::kAppFieldNumber') | 359 FieldNumberToPrototypeString('EntitySpecifics::kAppFieldNumber') |
| 377 => 'AppSpecifics' | 360 => 'AppSpecifics' |
| 378 """ | 361 """ |
| 379 return field_number.replace(FIELD_NUMBER_PREFIX, '').replace( | 362 return field_number.replace(FIELD_NUMBER_PREFIX, '').replace( |
| 380 'FieldNumber', 'Specifics').replace( | 363 'FieldNumber', 'Specifics').replace( |
| 381 'AppNotificationSpecifics', 'AppNotification') | 364 'AppNotificationSpecifics', 'AppNotification') |
| 365 |
| 366 def CheckChangeLintsClean(input_api, output_api): |
| 367 source_filter = lambda x: input_api.FilterSourceFile( |
| 368 x, white_list=SYNC_SOURCE_FILES, black_list=None) |
| 369 |
| 370 return input_api.canned_checks.CheckChangeLintsClean( |
| 371 input_api, output_api, source_filter, lint_filters=[], verbose_level=1) |
| 372 |
| 373 def CheckChanges(input_api, output_api): |
| 374 results = [] |
| 375 results += CheckChangeLintsClean(input_api, output_api) |
| 376 results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api) |
| 377 for f in input_api.AffectedFiles(): |
| 378 if f.LocalPath().endswith(MODEL_TYPE_FILE_NAME): |
| 379 return CheckModelTypeInfoMap(input_api, output_api, f) |
| 380 return results |
| 381 |
| 382 def CheckChangeOnUpload(input_api, output_api): |
| 383 return CheckChanges(input_api, output_api) |
| 384 |
| 385 def CheckChangeOnCommit(input_api, output_api): |
| 386 return CheckChanges(input_api, output_api) |
| OLD | NEW |