| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 schema_filename, schema_extension = os.path.splitext(schema) | 46 schema_filename, schema_extension = os.path.splitext(schema) |
| 47 api_defs = load_schema(schema) | 47 api_defs = load_schema(schema) |
| 48 | 48 |
| 49 api_model = model.Model() | 49 api_model = model.Model() |
| 50 | 50 |
| 51 for target_namespace in api_defs: | 51 for target_namespace in api_defs: |
| 52 referenced_schemas = target_namespace.get('dependencies', []) | 52 referenced_schemas = target_namespace.get('dependencies', []) |
| 53 # Load type dependencies into the model. | 53 # Load type dependencies into the model. |
| 54 # TODO(miket): do we need this in IDL? | 54 # TODO(miket): do we need this in IDL? |
| 55 for referenced_schema in referenced_schemas: | 55 for referenced_schema in referenced_schemas: |
| 56 referenced_schema_path = os.path.join( | 56 parts = referenced_schema.split(':') |
| 57 os.path.dirname(schema), referenced_schema + '.json') | 57 api_name = parts[-1] |
| 58 referenced_api_defs = json_schema.Load(referenced_schema_path) | 58 if len(parts) == 1 or parts[0] == 'api': |
| 59 referenced_schema_path = os.path.join( |
| 60 os.path.dirname(schema), api_name + '.json') |
| 61 referenced_api_defs = json_schema.Load(referenced_schema_path) |
| 59 | 62 |
| 60 for namespace in referenced_api_defs: | 63 for namespace in referenced_api_defs: |
| 61 api_model.AddNamespace(namespace, | 64 api_model.AddNamespace(namespace, |
| 62 os.path.relpath(referenced_schema_path, opts.root)) | 65 os.path.relpath(referenced_schema_path, opts.root)) |
| 63 | 66 |
| 64 # Gets the relative path from opts.root to the schema to correctly determine | 67 # Gets the relative path from opts.root to the schema to correctly determine |
| 65 # the include path. | 68 # the include path. |
| 66 relpath = os.path.relpath(schema, opts.root) | 69 relpath = os.path.relpath(schema, opts.root) |
| 67 namespace = api_model.AddNamespace(target_namespace, relpath) | 70 namespace = api_model.AddNamespace(target_namespace, relpath) |
| 68 if not namespace: | 71 if not namespace: |
| 69 continue | 72 continue |
| 70 | 73 |
| 71 # The output filename must match the input filename for gyp to deal with it | 74 # The output filename must match the input filename for gyp to deal with it |
| 72 # properly. | 75 # properly. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 171 |
| 169 if not args: | 172 if not args: |
| 170 sys.exit(0) # This is OK as a no-op | 173 sys.exit(0) # This is OK as a no-op |
| 171 dest_dir = opts.destdir | 174 dest_dir = opts.destdir |
| 172 root_namespace = opts.namespace | 175 root_namespace = opts.namespace |
| 173 | 176 |
| 174 if opts.bundle: | 177 if opts.bundle: |
| 175 handle_bundle_schema(args, dest_dir, opts.root, root_namespace) | 178 handle_bundle_schema(args, dest_dir, opts.root, root_namespace) |
| 176 else: | 179 else: |
| 177 handle_single_schema(args[0], dest_dir, opts.root, root_namespace) | 180 handle_single_schema(args[0], dest_dir, opts.root, root_namespace) |
| OLD | NEW |