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

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

Issue 11826048: Revert 176015 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « tools/json_schema_compiler/code.py ('k') | tools/json_schema_compiler/model.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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 if split_schema[0] != 'api': 62 if split_schema[0] != 'api':
63 continue 63 continue
64 else: 64 else:
65 referenced_schema = split_schema[1] 65 referenced_schema = split_schema[1]
66 66
67 referenced_schema_path = os.path.join( 67 referenced_schema_path = os.path.join(
68 os.path.dirname(schema), referenced_schema + '.json') 68 os.path.dirname(schema), referenced_schema + '.json')
69 referenced_api_defs = json_schema.Load(referenced_schema_path) 69 referenced_api_defs = json_schema.Load(referenced_schema_path)
70 70
71 for namespace in referenced_api_defs: 71 for namespace in referenced_api_defs:
72 api_model.AddNamespace( 72 api_model.AddNamespace(namespace,
73 namespace,
74 os.path.relpath(referenced_schema_path, opts.root)) 73 os.path.relpath(referenced_schema_path, opts.root))
75 74
76 # Gets the relative path from opts.root to the schema to correctly determine 75 # Gets the relative path from opts.root to the schema to correctly determine
77 # the include path. 76 # the include path.
78 relpath = os.path.relpath(schema, opts.root) 77 relpath = os.path.relpath(schema, opts.root)
79 namespace = api_model.AddNamespace(target_namespace, 78 namespace = api_model.AddNamespace(target_namespace, relpath)
80 relpath,
81 include_compiler_options=True)
82 if not namespace: 79 if not namespace:
83 continue 80 continue
84 81
85 if short_filename != namespace.unix_name: 82 if short_filename != namespace.unix_name:
86 sys.exit("Filename %s is illegal. Name files using unix_hacker style." % 83 sys.exit("Filename %s is illegal. Name files using unix_hacker style." %
87 filename) 84 filename)
88 85
89 # The output filename must match the input filename for gyp to deal with it 86 # The output filename must match the input filename for gyp to deal with it
90 # properly. 87 # properly.
91 out_file = namespace.unix_name 88 out_file = namespace.unix_name
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 api_defs = [] 123 api_defs = []
127 for filename in filenames: 124 for filename in filenames:
128 schema = os.path.normpath(filename) 125 schema = os.path.normpath(filename)
129 schema_filename, schema_extension = os.path.splitext(schema) 126 schema_filename, schema_extension = os.path.splitext(schema)
130 api_defs.extend(load_schema(schema)) 127 api_defs.extend(load_schema(schema))
131 128
132 api_model = model.Model() 129 api_model = model.Model()
133 relpath = os.path.relpath(os.path.normpath(filenames[0]), root) 130 relpath = os.path.relpath(os.path.normpath(filenames[0]), root)
134 131
135 for target_namespace, schema_filename in zip(api_defs, filenames): 132 for target_namespace, schema_filename in zip(api_defs, filenames):
136 namespace = api_model.AddNamespace(target_namespace, 133 namespace = api_model.AddNamespace(target_namespace, relpath)
137 relpath,
138 include_compiler_options=True)
139 path, filename = os.path.split(schema_filename) 134 path, filename = os.path.split(schema_filename)
140 short_filename, extension = os.path.splitext(filename) 135 short_filename, extension = os.path.splitext(filename)
141 136
142 # Filenames are checked against the unix_names of the namespaces they 137 # Filenames are checked against the unix_names of the namespaces they
143 # generate because the gyp uses the names of the JSON files to generate 138 # generate because the gyp uses the names of the JSON files to generate
144 # the names of the .cc and .h files. We want these to be using unix_names. 139 # the names of the .cc and .h files. We want these to be using unix_names.
145 if namespace.unix_name != short_filename: 140 if namespace.unix_name != short_filename:
146 sys.exit("Filename %s is illegal. Name files using unix_hacker style." % 141 sys.exit("Filename %s is illegal. Name files using unix_hacker style." %
147 schema_filename) 142 schema_filename)
148 143
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 193
199 if not args: 194 if not args:
200 sys.exit(0) # This is OK as a no-op 195 sys.exit(0) # This is OK as a no-op
201 dest_dir = opts.destdir 196 dest_dir = opts.destdir
202 root_namespace = opts.namespace 197 root_namespace = opts.namespace
203 198
204 if opts.bundle: 199 if opts.bundle:
205 handle_bundle_schema(args, dest_dir, opts.root, root_namespace) 200 handle_bundle_schema(args, dest_dir, opts.root, root_namespace)
206 else: 201 else:
207 handle_single_schema(args[0], dest_dir, opts.root, root_namespace) 202 handle_single_schema(args[0], dest_dir, opts.root, root_namespace)
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/code.py ('k') | tools/json_schema_compiler/model.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698