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

Side by Side Diff: headless/lib/browser/client_api_generator.py

Issue 2278123002: headless: Ensure all commands have parameters and return types (Closed)
Patch Set: Created 4 years, 3 months 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
« no previous file with comments | « no previous file | headless/lib/browser/client_api_generator_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 os.path 6 import os.path
7 import sys 7 import sys
8 import re 8 import re
9 try: 9 try:
10 import json 10 import json
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 Mark all commands and events in experimental domains as experimental 366 Mark all commands and events in experimental domains as experimental
367 and make sure experimental commands have at least empty parameters 367 and make sure experimental commands have at least empty parameters
368 and return values. 368 and return values.
369 """ 369 """
370 for domain in json_api['domains']: 370 for domain in json_api['domains']:
371 if domain.get('experimental', False): 371 if domain.get('experimental', False):
372 for command in domain.get('commands', []): 372 for command in domain.get('commands', []):
373 command['experimental'] = True 373 command['experimental'] = True
374 for event in domain.get('events', []): 374 for event in domain.get('events', []):
375 event['experimental'] = True 375 event['experimental'] = True
376
377
378 def EnsureCommandsHaveParametersAndReturnTypes(json_api):
379 """
380 Make sure all commands have at least empty parameters and return values. This
381 guarantees API compatibility if a previously experimental command is made
382 stable.
383 """
384 for domain in json_api['domains']:
376 for command in domain.get('commands', []): 385 for command in domain.get('commands', []):
377 if not command.get('experimental', False):
378 continue
379 if not 'parameters' in command: 386 if not 'parameters' in command:
380 command['parameters'] = [] 387 command['parameters'] = []
381 if not 'returns' in command: 388 if not 'returns' in command:
382 command['returns'] = [] 389 command['returns'] = []
383 for event in domain.get('events', []): 390 for event in domain.get('events', []):
384 if not event.get('experimental', False):
385 continue
386 if not 'parameters' in event: 391 if not 'parameters' in event:
387 event['parameters'] = [] 392 event['parameters'] = []
388 393
389 394
390 def Generate(jinja_env, output_dirname, json_api, class_name, file_types): 395 def Generate(jinja_env, output_dirname, json_api, class_name, file_types):
391 template_context = { 396 template_context = {
392 'api': json_api, 397 'api': json_api,
393 'join_arrays': JoinArrays, 398 'join_arrays': JoinArrays,
394 'resolve_type': ResolveType, 399 'resolve_type': ResolveType,
395 'type_definition': TypeDefinition, 400 'type_definition': TypeDefinition,
(...skipping 19 matching lines...) Expand all
415 domain_name = CamelCaseToHackerStyle(domain['domain']) 420 domain_name = CamelCaseToHackerStyle(domain['domain'])
416 output_file = '%s/%s.%s' % (output_dirname, domain_name, file_type) 421 output_file = '%s/%s.%s' % (output_dirname, domain_name, file_type)
417 with open(output_file, 'w') as f: 422 with open(output_file, 'w') as f:
418 f.write(template.render(template_context)) 423 f.write(template.render(template_context))
419 424
420 425
421 if __name__ == '__main__': 426 if __name__ == '__main__':
422 json_api, output_dirname = ParseArguments(sys.argv[1:]) 427 json_api, output_dirname = ParseArguments(sys.argv[1:])
423 jinja_env = InitializeJinjaEnv(output_dirname) 428 jinja_env = InitializeJinjaEnv(output_dirname)
424 PatchExperimentalCommandsAndEvents(json_api) 429 PatchExperimentalCommandsAndEvents(json_api)
430 EnsureCommandsHaveParametersAndReturnTypes(json_api)
425 SynthesizeCommandTypes(json_api) 431 SynthesizeCommandTypes(json_api)
426 SynthesizeEventTypes(json_api) 432 SynthesizeEventTypes(json_api)
427 PatchFullQualifiedRefs(json_api) 433 PatchFullQualifiedRefs(json_api)
428 CreateTypeDefinitions(json_api) 434 CreateTypeDefinitions(json_api)
429 Generate(jinja_env, output_dirname, json_api, 'types', ['cc', 'h']) 435 Generate(jinja_env, output_dirname, json_api, 'types', ['cc', 'h'])
430 Generate(jinja_env, output_dirname, json_api, 'type_conversions', ['h']) 436 Generate(jinja_env, output_dirname, json_api, 'type_conversions', ['h'])
431 GenerateDomains(jinja_env, output_dirname, json_api, 'domain', ['cc', 'h']) 437 GenerateDomains(jinja_env, output_dirname, json_api, 'domain', ['cc', 'h'])
OLDNEW
« no previous file with comments | « no previous file | headless/lib/browser/client_api_generator_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698