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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 include_rules): | 44 include_rules): |
45 # Merge the source files into a single list of schemas. | 45 # Merge the source files into a single list of schemas. |
46 api_defs = [] | 46 api_defs = [] |
47 for file_path in file_paths: | 47 for file_path in file_paths: |
48 schema = os.path.normpath(file_path) | 48 schema = os.path.normpath(file_path) |
49 schema_loader = SchemaLoader( | 49 schema_loader = SchemaLoader( |
50 os.path.dirname(os.path.relpath(schema, root)), | 50 os.path.dirname(os.path.relpath(schema, root)), |
51 os.path.dirname(file_path), | 51 os.path.dirname(file_path), |
52 include_rules, | 52 include_rules, |
53 cpp_namespace_pattern) | 53 cpp_namespace_pattern) |
54 api_def = schema_loader.LoadSchema(os.path.split(schema)[1]) | 54 api_def = schema_loader.LoadSchema(schema) |
55 | 55 |
56 # If compiling the C++ model code, delete 'nocompile' nodes. | 56 # If compiling the C++ model code, delete 'nocompile' nodes. |
57 if generator_name == 'cpp': | 57 if generator_name == 'cpp': |
58 api_def = json_schema.DeleteNodes(api_def, 'nocompile') | 58 api_def = json_schema.DeleteNodes(api_def, 'nocompile') |
59 api_defs.extend(api_def) | 59 api_defs.extend(api_def) |
60 | 60 |
61 api_model = Model() | 61 api_model = Model() |
62 | 62 |
63 # For single-schema compilation make sure that the first (i.e. only) schema | 63 # For single-schema compilation make sure that the first (i.e. only) schema |
64 # is the default one. | 64 # is the default one. |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 include_rules = [] | 189 include_rules = [] |
190 if opts.include_rules: | 190 if opts.include_rules: |
191 include_rules = map(split_path_and_namespace, | 191 include_rules = map(split_path_and_namespace, |
192 shlex.split(opts.include_rules)) | 192 shlex.split(opts.include_rules)) |
193 | 193 |
194 result = GenerateSchema(opts.generator, file_paths, opts.root, opts.destdir, | 194 result = GenerateSchema(opts.generator, file_paths, opts.root, opts.destdir, |
195 opts.namespace, opts.dart_overrides_dir, | 195 opts.namespace, opts.dart_overrides_dir, |
196 opts.impl_dir, include_rules) | 196 opts.impl_dir, include_rules) |
197 if not opts.destdir: | 197 if not opts.destdir: |
198 print result | 198 print result |
OLD | NEW |