Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: tools/json_schema_compiler/feature_compiler.py

Issue 2494653005: Support API aliases (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 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 import argparse 5 import argparse
6 import copy 6 import copy
7 from datetime import datetime 7 from datetime import datetime
8 from functools import partial 8 from functools import partial
9 import os 9 import os
10 10
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 # the collection of all possible values. For instance, if a 95 # the collection of all possible values. For instance, if a
96 # feature specifies 'contexts': 'all', the generated C++ will 96 # feature specifies 'contexts': 'all', the generated C++ will
97 # assign the list of Feature::BLESSED_EXTENSION_CONTEXT, 97 # assign the list of Feature::BLESSED_EXTENSION_CONTEXT,
98 # Feature::BLESSED_WEB_PAGE_CONTEXT et al for contexts. If not 98 # Feature::BLESSED_WEB_PAGE_CONTEXT et al for contexts. If not
99 # specified, defaults to false. 99 # specified, defaults to false.
100 # 'values': A list of all possible allowed values for a given key. 100 # 'values': A list of all possible allowed values for a given key.
101 # If a type definition does not have any restrictions (beyond the type itself), 101 # If a type definition does not have any restrictions (beyond the type itself),
102 # an empty definition ({}) is used. 102 # an empty definition ({}) is used.
103 FEATURE_GRAMMAR = ( 103 FEATURE_GRAMMAR = (
104 { 104 {
105 'alias': {
Devlin 2016/11/14 18:03:56 We need to test these. We also need to throw erro
tbarzic 2016/11/15 04:45:07 Done.
106 unicode: {}
107 },
105 'blacklist': { 108 'blacklist': {
106 list: {'subtype': unicode} 109 list: {'subtype': unicode}
107 }, 110 },
108 'channel': { 111 'channel': {
109 unicode: { 112 unicode: {
110 'enum_map': { 113 'enum_map': {
111 'trunk': 'version_info::Channel::UNKNOWN', 114 'trunk': 'version_info::Channel::UNKNOWN',
112 'canary': 'version_info::Channel::CANARY', 115 'canary': 'version_info::Channel::CANARY',
113 'dev': 'version_info::Channel::DEV', 116 'dev': 'version_info::Channel::DEV',
114 'beta': 'version_info::Channel::BETA', 117 'beta': 'version_info::Channel::BETA',
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 193 }
191 }, 194 },
192 'session_types': { 195 'session_types': {
193 list: { 196 list: {
194 'enum_map': { 197 'enum_map': {
195 'regular': 'FeatureSessionType::REGULAR', 198 'regular': 'FeatureSessionType::REGULAR',
196 'kiosk': 'FeatureSessionType::KIOSK', 199 'kiosk': 'FeatureSessionType::KIOSK',
197 } 200 }
198 } 201 }
199 }, 202 },
203 'source': {
204 unicode: {}
205 },
200 'whitelist': { 206 'whitelist': {
201 list: {'subtype': unicode} 207 list: {'subtype': unicode}
202 }, 208 },
203 }) 209 })
204 210
205 FEATURE_CLASSES = ['APIFeature', 'BehaviorFeature', 211 FEATURE_CLASSES = ['APIFeature', 'BehaviorFeature',
206 'ManifestFeature', 'PermissionFeature'] 212 'ManifestFeature', 'PermissionFeature']
207 213
208 def HasProperty(property_name, value): 214 def HasProperty(property_name, value):
209 return property_name in value 215 return property_name in value
(...skipping 11 matching lines...) Expand all
221 ], 227 ],
222 'APIFeature': [ 228 'APIFeature': [
223 (partial(HasProperty, 'contexts'), 229 (partial(HasProperty, 'contexts'),
224 'APIFeatures must specify at least one context') 230 'APIFeatures must specify at least one context')
225 ], 231 ],
226 'ManifestFeature': [ 232 'ManifestFeature': [
227 (partial(HasProperty, 'extension_types'), 233 (partial(HasProperty, 'extension_types'),
228 'ManifestFeatures must specify at least one extension type'), 234 'ManifestFeatures must specify at least one extension type'),
229 (partial(DoesNotHaveProperty, 'contexts'), 235 (partial(DoesNotHaveProperty, 'contexts'),
230 'ManifestFeatures do not support contexts.'), 236 'ManifestFeatures do not support contexts.'),
237 (partial(DoesNotHaveProperty, 'alias'),
238 'ManifestFeatures do not support alias.'),
239 (partial(DoesNotHaveProperty, 'source'),
240 'ManifestFeatures do not support source.'),
231 ], 241 ],
232 'BehaviorFeature': [], 242 'BehaviorFeature': [
243 (partial(DoesNotHaveProperty, 'alias'),
244 'BehaviorFeatures do not support alias.'),
245 (partial(DoesNotHaveProperty, 'source'),
246 'BehaviorFeatures do not support source.'),
247 ],
233 'PermissionFeature': [ 248 'PermissionFeature': [
234 (partial(HasProperty, 'extension_types'), 249 (partial(HasProperty, 'extension_types'),
235 'PermissionFeatures must specify at least one extension type'), 250 'PermissionFeatures must specify at least one extension type'),
236 (partial(DoesNotHaveProperty, 'contexts'), 251 (partial(DoesNotHaveProperty, 'contexts'),
237 'PermissionFeatures do not support contexts.'), 252 'PermissionFeatures do not support contexts.'),
253 (partial(DoesNotHaveProperty, 'alias'),
254 'PermissionFeatures do not support alias.'),
255 (partial(DoesNotHaveProperty, 'source'),
256 'PermissionFeatures do not support source.'),
238 ], 257 ],
239 }) 258 })
240 259
241 # These keys are used to find the parents of different features, but are not 260 # These keys are used to find the parents of different features, but are not
242 # compiled into the features themselves. 261 # compiled into the features themselves.
243 IGNORED_KEYS = ['default_parent'] 262 IGNORED_KEYS = ['default_parent']
244 263
245 # By default, if an error is encountered, assert to stop the compilation. This 264 # By default, if an error is encountered, assert to stop the compilation. This
246 # can be disabled for testing. 265 # can be disabled for testing.
247 ENABLE_ASSERTIONS = True 266 ENABLE_ASSERTIONS = True
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 parser.add_argument('source_files', type=str, nargs='+', 630 parser.add_argument('source_files', type=str, nargs='+',
612 help='The source features.json files') 631 help='The source features.json files')
613 args = parser.parse_args() 632 args = parser.parse_args()
614 if args.feature_class not in FEATURE_CLASSES: 633 if args.feature_class not in FEATURE_CLASSES:
615 raise NameError('Unknown feature class: %s' % args.feature_class) 634 raise NameError('Unknown feature class: %s' % args.feature_class)
616 c = FeatureCompiler(args.chrome_root, args.source_files, args.feature_class, 635 c = FeatureCompiler(args.chrome_root, args.source_files, args.feature_class,
617 args.provider_class, args.out_root, 636 args.provider_class, args.out_root,
618 args.out_base_filename) 637 args.out_base_filename)
619 c.Compile() 638 c.Compile()
620 c.Write() 639 c.Write()
OLDNEW
« extensions/common/features/feature.h ('K') | « extensions/renderer/script_context.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698