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

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

Issue 183763032: Add an implementation path option to json_schema_compiler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add default impl_dir Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « build/json_schema_compile.gypi ('k') | tools/json_schema_compiler/cpp_bundle_generator.py » ('j') | 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 20 matching lines...) Expand all
31 31
32 # Names of supported code generators, as specified on the command-line. 32 # Names of supported code generators, as specified on the command-line.
33 # First is default. 33 # First is default.
34 GENERATORS = ['cpp', 'cpp-bundle', 'dart', 'ppapi'] 34 GENERATORS = ['cpp', 'cpp-bundle', 'dart', 'ppapi']
35 35
36 def GenerateSchema(generator, 36 def GenerateSchema(generator,
37 filenames, 37 filenames,
38 root, 38 root,
39 destdir, 39 destdir,
40 root_namespace, 40 root_namespace,
41 dart_overrides_dir): 41 dart_overrides_dir,
42 impl_dir):
42 schema_loader = SchemaLoader( 43 schema_loader = SchemaLoader(
43 os.path.dirname(os.path.relpath(os.path.normpath(filenames[0]), root)), 44 os.path.dirname(os.path.relpath(os.path.normpath(filenames[0]), root)),
44 os.path.dirname(filenames[0])) 45 os.path.dirname(filenames[0]))
45 # Merge the source files into a single list of schemas. 46 # Merge the source files into a single list of schemas.
46 api_defs = [] 47 api_defs = []
47 for filename in filenames: 48 for filename in filenames:
48 schema = os.path.normpath(filename) 49 schema = os.path.normpath(filename)
49 api_def = schema_loader.LoadSchema(os.path.split(schema)[1]) 50 api_def = schema_loader.LoadSchema(os.path.split(schema)[1])
50 51
51 # If compiling the C++ model code, delete 'nocompile' nodes. 52 # If compiling the C++ model code, delete 'nocompile' nodes.
(...skipping 23 matching lines...) Expand all
75 type_generator = CppTypeGenerator(api_model, 76 type_generator = CppTypeGenerator(api_model,
76 schema_loader, 77 schema_loader,
77 default_namespace=default_namespace) 78 default_namespace=default_namespace)
78 79
79 if generator == 'cpp-bundle': 80 if generator == 'cpp-bundle':
80 cpp_bundle_generator = CppBundleGenerator(root, 81 cpp_bundle_generator = CppBundleGenerator(root,
81 api_model, 82 api_model,
82 api_defs, 83 api_defs,
83 type_generator, 84 type_generator,
84 root_namespace, 85 root_namespace,
85 namespace.source_file_dir) 86 namespace.source_file_dir,
87 impl_dir)
86 generators = [ 88 generators = [
87 ('generated_api.cc', cpp_bundle_generator.api_cc_generator), 89 ('generated_api.cc', cpp_bundle_generator.api_cc_generator),
88 ('generated_api.h', cpp_bundle_generator.api_h_generator), 90 ('generated_api.h', cpp_bundle_generator.api_h_generator),
89 ('generated_schemas.cc', cpp_bundle_generator.schemas_cc_generator), 91 ('generated_schemas.cc', cpp_bundle_generator.schemas_cc_generator),
90 ('generated_schemas.h', cpp_bundle_generator.schemas_h_generator) 92 ('generated_schemas.h', cpp_bundle_generator.schemas_h_generator)
91 ] 93 ]
92 elif generator == 'cpp': 94 elif generator == 'cpp':
93 cpp_generator = CppGenerator(type_generator, root_namespace) 95 cpp_generator = CppGenerator(type_generator, root_namespace)
94 generators = [ 96 generators = [
95 ('%s.h' % short_filename, cpp_generator.h_generator), 97 ('%s.h' % short_filename, cpp_generator.h_generator),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 parser.add_option('-d', '--destdir', 133 parser.add_option('-d', '--destdir',
132 help='root directory to output generated files.') 134 help='root directory to output generated files.')
133 parser.add_option('-n', '--namespace', default='generated_api_schemas', 135 parser.add_option('-n', '--namespace', default='generated_api_schemas',
134 help='C++ namespace for generated files. e.g extensions::api.') 136 help='C++ namespace for generated files. e.g extensions::api.')
135 parser.add_option('-g', '--generator', default=GENERATORS[0], 137 parser.add_option('-g', '--generator', default=GENERATORS[0],
136 choices=GENERATORS, 138 choices=GENERATORS,
137 help='The generator to use to build the output code. Supported values are' 139 help='The generator to use to build the output code. Supported values are'
138 ' %s' % GENERATORS) 140 ' %s' % GENERATORS)
139 parser.add_option('-D', '--dart-overrides-dir', dest='dart_overrides_dir', 141 parser.add_option('-D', '--dart-overrides-dir', dest='dart_overrides_dir',
140 help='Adds custom dart from files in the given directory (Dart only).') 142 help='Adds custom dart from files in the given directory (Dart only).')
143 parser.add_option('-i', '--impl-dir', dest='impl_dir',
144 help='The root path of all API implementations')
141 145
142 (opts, filenames) = parser.parse_args() 146 (opts, filenames) = parser.parse_args()
143 147
144 if not filenames: 148 if not filenames:
145 sys.exit(0) # This is OK as a no-op 149 sys.exit(0) # This is OK as a no-op
146 150
147 # Unless in bundle mode, only one file should be specified. 151 # Unless in bundle mode, only one file should be specified.
148 if opts.generator != 'cpp-bundle' and len(filenames) > 1: 152 if opts.generator != 'cpp-bundle' and len(filenames) > 1:
149 # TODO(sashab): Could also just use filenames[0] here and not complain. 153 # TODO(sashab): Could also just use filenames[0] here and not complain.
150 raise Exception( 154 raise Exception(
151 "Unless in bundle mode, only one file can be specified at a time.") 155 "Unless in bundle mode, only one file can be specified at a time.")
152 156
153 result = GenerateSchema(opts.generator, filenames, opts.root, opts.destdir, 157 result = GenerateSchema(opts.generator, filenames, opts.root, opts.destdir,
154 opts.namespace, opts.dart_overrides_dir) 158 opts.namespace, opts.dart_overrides_dir,
159 opts.impl_dir)
155 if not opts.destdir: 160 if not opts.destdir:
156 print result 161 print result
OLDNEW
« no previous file with comments | « build/json_schema_compile.gypi ('k') | tools/json_schema_compiler/cpp_bundle_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698