| 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 30 matching lines...) Expand all Loading... |
| 41 if len(api_defs) != 1: | 41 if len(api_defs) != 1: |
| 42 sys.exit("File %s has multiple schemas. Files are only allowed to contain a" | 42 sys.exit("File %s has multiple schemas. Files are only allowed to contain a" |
| 43 " single schema." % schema) | 43 " single schema." % schema) |
| 44 | 44 |
| 45 return api_defs | 45 return api_defs |
| 46 | 46 |
| 47 def handle_single_schema(filename, dest_dir, root, root_namespace): | 47 def handle_single_schema(filename, dest_dir, root, root_namespace): |
| 48 schema = os.path.normpath(filename) | 48 schema = os.path.normpath(filename) |
| 49 schema_filename, schema_extension = os.path.splitext(schema) | 49 schema_filename, schema_extension = os.path.splitext(schema) |
| 50 path, short_filename = os.path.split(schema_filename) | 50 path, short_filename = os.path.split(schema_filename) |
| 51 api_defs = 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 referenced_schema_path = os.path.join( | 60 referenced_schema_path = os.path.join( |
| 61 os.path.dirname(schema), referenced_schema + '.json') | 61 os.path.dirname(schema), referenced_schema + '.json') |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 186 |
| 187 if not args: | 187 if not args: |
| 188 sys.exit(0) # This is OK as a no-op | 188 sys.exit(0) # This is OK as a no-op |
| 189 dest_dir = opts.destdir | 189 dest_dir = opts.destdir |
| 190 root_namespace = opts.namespace | 190 root_namespace = opts.namespace |
| 191 | 191 |
| 192 if opts.bundle: | 192 if opts.bundle: |
| 193 handle_bundle_schema(args, dest_dir, opts.root, root_namespace) | 193 handle_bundle_schema(args, dest_dir, opts.root, root_namespace) |
| 194 else: | 194 else: |
| 195 handle_single_schema(args[0], dest_dir, opts.root, root_namespace) | 195 handle_single_schema(args[0], dest_dir, opts.root, root_namespace) |
| OLD | NEW |