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

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

Issue 849103005: Cleanup most pylint errors in json_schema_compiler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 5 years, 11 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
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 cpp_namespace_pattern)) 78 cpp_namespace_pattern))
79 79
80 if default_namespace is None: 80 if default_namespace is None:
81 default_namespace = namespace 81 default_namespace = namespace
82 82
83 if src_path is None: 83 if src_path is None:
84 src_path = namespace.source_file_dir 84 src_path = namespace.source_file_dir
85 else: 85 else:
86 src_path = os.path.commonprefix((src_path, namespace.source_file_dir)) 86 src_path = os.path.commonprefix((src_path, namespace.source_file_dir))
87 87
88 path, filename = os.path.split(file_path) 88 _, filename = os.path.split(file_path)
89 filename_base, _ = os.path.splitext(filename) 89 filename_base, _ = os.path.splitext(filename)
90 90
91 # Construct the type generator with all the namespaces in this model. 91 # Construct the type generator with all the namespaces in this model.
92 type_generator = CppTypeGenerator(api_model, 92 type_generator = CppTypeGenerator(api_model,
93 schema_loader, 93 schema_loader,
94 default_namespace) 94 default_namespace)
95 if generator_name in ('cpp-bundle-registration', 'cpp-bundle-schema'): 95 if generator_name in ('cpp-bundle-registration', 'cpp-bundle-schema'):
96 cpp_bundle_generator = CppBundleGenerator(root, 96 cpp_bundle_generator = CppBundleGenerator(root,
97 api_model, 97 api_model,
98 api_defs, 98 api_defs,
(...skipping 17 matching lines...) Expand all
116 generators = [ 116 generators = [
117 ('%s.h' % filename_base, cpp_generator.h_generator), 117 ('%s.h' % filename_base, cpp_generator.h_generator),
118 ('%s.cc' % filename_base, cpp_generator.cc_generator) 118 ('%s.cc' % filename_base, cpp_generator.cc_generator)
119 ] 119 ]
120 elif generator_name == 'dart': 120 elif generator_name == 'dart':
121 generators = [ 121 generators = [
122 ('%s.dart' % namespace.unix_name, DartGenerator( 122 ('%s.dart' % namespace.unix_name, DartGenerator(
123 dart_overrides_dir)) 123 dart_overrides_dir))
124 ] 124 ]
125 else: 125 else:
126 raise Exception('Unrecognised generator %s' % generator) 126 raise Exception('Unrecognised generator %s' % generator_name)
127 127
128 output_code = [] 128 output_code = []
129 for filename, generator in generators: 129 for filename, generator in generators:
130 code = generator.Generate(namespace).Render() 130 code = generator.Generate(namespace).Render()
131 if destdir: 131 if destdir:
132 if generator_name == 'cpp-bundle-registration': 132 if generator_name == 'cpp-bundle-registration':
133 # Function registrations must be output to impl_dir, since they link in 133 # Function registrations must be output to impl_dir, since they link in
134 # API implementations. 134 # API implementations.
135 output_dir = os.path.join(destdir, impl_dir) 135 output_dir = os.path.join(destdir, impl_dir)
136 else: 136 else:
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/cc_generator.py ('k') | tools/json_schema_compiler/cpp_bundle_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698