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

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

Issue 10700039: Update the JSON Schema Compiler to take dependencies of the form type:name. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: --find() ++split() Created 8 years, 5 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 """Generator for C++ structs from api json files. 5 """Generator for C++ structs from api json files.
6 6
7 The purpose of this tool is to remove the need for hand-written code that 7 The purpose of this tool is to remove the need for hand-written code that
8 converts to and from base::Value types when receiving javascript api calls. 8 converts to and from base::Value types when receiving javascript api calls.
9 Originally written for generating code for extension apis. Reference schemas 9 Originally written for generating code for extension apis. Reference schemas
10 are in chrome/common/extensions/api. 10 are in chrome/common/extensions/api.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 path, short_filename = os.path.split(schema_filename) 50 path, short_filename = os.path.split(schema_filename)
51 api_defs = json_schema.DeleteNocompileNodes(load_schema(schema)) 51 api_defs = json_schema.DeleteNocompileNodes(load_schema(schema))
52 52
53 api_model = model.Model() 53 api_model = model.Model()
54 54
55 for target_namespace in api_defs: 55 for target_namespace in api_defs:
56 referenced_schemas = target_namespace.get('dependencies', []) 56 referenced_schemas = target_namespace.get('dependencies', [])
57 # Load type dependencies into the model. 57 # Load type dependencies into the model.
58 # TODO(miket): do we need this in IDL? 58 # TODO(miket): do we need this in IDL?
59 for referenced_schema in referenced_schemas: 59 for referenced_schema in referenced_schemas:
60 split_schema = referenced_schema.split(':')
Aaron Boodman 2012/07/02 23:25:07 split(':', 1)
61 if len(split_schema) != 1:
Aaron Boodman 2012/07/02 23:25:07 nit: maybe > 1 ... i don't think python can split
62 if split_schema[0] != 'api':
63 continue
64 else:
65 referenced_schema = split_schema[1]
66
60 referenced_schema_path = os.path.join( 67 referenced_schema_path = os.path.join(
61 os.path.dirname(schema), referenced_schema + '.json') 68 os.path.dirname(schema), referenced_schema + '.json')
62 referenced_api_defs = json_schema.Load(referenced_schema_path) 69 referenced_api_defs = json_schema.Load(referenced_schema_path)
63 70
64 for namespace in referenced_api_defs: 71 for namespace in referenced_api_defs:
65 api_model.AddNamespace(namespace, 72 api_model.AddNamespace(namespace,
66 os.path.relpath(referenced_schema_path, opts.root)) 73 os.path.relpath(referenced_schema_path, opts.root))
67 74
68 # Gets the relative path from opts.root to the schema to correctly determine 75 # Gets the relative path from opts.root to the schema to correctly determine
69 # the include path. 76 # the include path.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 193
187 if not args: 194 if not args:
188 sys.exit(0) # This is OK as a no-op 195 sys.exit(0) # This is OK as a no-op
189 dest_dir = opts.destdir 196 dest_dir = opts.destdir
190 root_namespace = opts.namespace 197 root_namespace = opts.namespace
191 198
192 if opts.bundle: 199 if opts.bundle:
193 handle_bundle_schema(args, dest_dir, opts.root, root_namespace) 200 handle_bundle_schema(args, dest_dir, opts.root, root_namespace)
194 else: 201 else:
195 handle_single_schema(args[0], dest_dir, opts.root, root_namespace) 202 handle_single_schema(args[0], dest_dir, opts.root, root_namespace)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698