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

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

Issue 11747025: Run the JSON Schema Compiler's bundle compilation on JSON files. Previously it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix ms release build 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(namespace, 72 api_model.AddNamespace(
73 namespace,
73 os.path.relpath(referenced_schema_path, opts.root)) 74 os.path.relpath(referenced_schema_path, opts.root))
74 75
75 # Gets the relative path from opts.root to the schema to correctly determine 76 # Gets the relative path from opts.root to the schema to correctly determine
76 # the include path. 77 # the include path.
77 relpath = os.path.relpath(schema, opts.root) 78 relpath = os.path.relpath(schema, opts.root)
78 namespace = api_model.AddNamespace(target_namespace, relpath) 79 namespace = api_model.AddNamespace(target_namespace,
80 relpath,
81 include_compiler_options=True)
79 if not namespace: 82 if not namespace:
80 continue 83 continue
81 84
82 if short_filename != namespace.unix_name: 85 if short_filename != namespace.unix_name:
83 sys.exit("Filename %s is illegal. Name files using unix_hacker style." % 86 sys.exit("Filename %s is illegal. Name files using unix_hacker style." %
84 filename) 87 filename)
85 88
86 # The output filename must match the input filename for gyp to deal with it 89 # The output filename must match the input filename for gyp to deal with it
87 # properly. 90 # properly.
88 out_file = namespace.unix_name 91 out_file = namespace.unix_name
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 api_defs = [] 126 api_defs = []
124 for filename in filenames: 127 for filename in filenames:
125 schema = os.path.normpath(filename) 128 schema = os.path.normpath(filename)
126 schema_filename, schema_extension = os.path.splitext(schema) 129 schema_filename, schema_extension = os.path.splitext(schema)
127 api_defs.extend(load_schema(schema)) 130 api_defs.extend(load_schema(schema))
128 131
129 api_model = model.Model() 132 api_model = model.Model()
130 relpath = os.path.relpath(os.path.normpath(filenames[0]), root) 133 relpath = os.path.relpath(os.path.normpath(filenames[0]), root)
131 134
132 for target_namespace, schema_filename in zip(api_defs, filenames): 135 for target_namespace, schema_filename in zip(api_defs, filenames):
133 namespace = api_model.AddNamespace(target_namespace, relpath) 136 namespace = api_model.AddNamespace(target_namespace,
137 relpath,
138 include_compiler_options=True)
134 path, filename = os.path.split(schema_filename) 139 path, filename = os.path.split(schema_filename)
135 short_filename, extension = os.path.splitext(filename) 140 short_filename, extension = os.path.splitext(filename)
136 141
137 # Filenames are checked against the unix_names of the namespaces they 142 # Filenames are checked against the unix_names of the namespaces they
138 # generate because the gyp uses the names of the JSON files to generate 143 # generate because the gyp uses the names of the JSON files to generate
139 # the names of the .cc and .h files. We want these to be using unix_names. 144 # the names of the .cc and .h files. We want these to be using unix_names.
140 if namespace.unix_name != short_filename: 145 if namespace.unix_name != short_filename:
141 sys.exit("Filename %s is illegal. Name files using unix_hacker style." % 146 sys.exit("Filename %s is illegal. Name files using unix_hacker style." %
142 schema_filename) 147 schema_filename)
143 148
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 198
194 if not args: 199 if not args:
195 sys.exit(0) # This is OK as a no-op 200 sys.exit(0) # This is OK as a no-op
196 dest_dir = opts.destdir 201 dest_dir = opts.destdir
197 root_namespace = opts.namespace 202 root_namespace = opts.namespace
198 203
199 if opts.bundle: 204 if opts.bundle:
200 handle_bundle_schema(args, dest_dir, opts.root, root_namespace) 205 handle_bundle_schema(args, dest_dir, opts.root, root_namespace)
201 else: 206 else:
202 handle_single_schema(args[0], dest_dir, opts.root, root_namespace) 207 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