OLD | NEW |
---|---|
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 Loading... | |
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 index = referenced_schema.find(':') | |
Aaron Boodman
2012/07/02 22:47:40
split() ?
| |
61 if index != -1: | |
62 if referenced_schema[:index] != 'api': | |
63 continue | |
64 | |
60 referenced_schema_path = os.path.join( | 65 referenced_schema_path = os.path.join( |
61 os.path.dirname(schema), referenced_schema + '.json') | 66 os.path.dirname(schema), referenced_schema + '.json') |
62 referenced_api_defs = json_schema.Load(referenced_schema_path) | 67 referenced_api_defs = json_schema.Load(referenced_schema_path) |
63 | 68 |
64 for namespace in referenced_api_defs: | 69 for namespace in referenced_api_defs: |
65 api_model.AddNamespace(namespace, | 70 api_model.AddNamespace(namespace, |
66 os.path.relpath(referenced_schema_path, opts.root)) | 71 os.path.relpath(referenced_schema_path, opts.root)) |
67 | 72 |
68 # Gets the relative path from opts.root to the schema to correctly determine | 73 # Gets the relative path from opts.root to the schema to correctly determine |
69 # the include path. | 74 # the include path. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 | 191 |
187 if not args: | 192 if not args: |
188 sys.exit(0) # This is OK as a no-op | 193 sys.exit(0) # This is OK as a no-op |
189 dest_dir = opts.destdir | 194 dest_dir = opts.destdir |
190 root_namespace = opts.namespace | 195 root_namespace = opts.namespace |
191 | 196 |
192 if opts.bundle: | 197 if opts.bundle: |
193 handle_bundle_schema(args, dest_dir, opts.root, root_namespace) | 198 handle_bundle_schema(args, dest_dir, opts.root, root_namespace) |
194 else: | 199 else: |
195 handle_single_schema(args[0], dest_dir, opts.root, root_namespace) | 200 handle_single_schema(args[0], dest_dir, opts.root, root_namespace) |
OLD | NEW |