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

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

Issue 23534063: Make SchemaLoader independent of current working directory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use two separate paths Created 7 years, 2 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 20 matching lines...) Expand all
31 # Names of supported code generators, as specified on the command-line. 31 # Names of supported code generators, as specified on the command-line.
32 # First is default. 32 # First is default.
33 GENERATORS = ['cpp', 'cpp-bundle', 'dart'] 33 GENERATORS = ['cpp', 'cpp-bundle', 'dart']
34 34
35 def GenerateSchema(generator, 35 def GenerateSchema(generator,
36 filenames, 36 filenames,
37 root, 37 root,
38 destdir, 38 destdir,
39 root_namespace, 39 root_namespace,
40 dart_overrides_dir): 40 dart_overrides_dir):
41 schema_loader = SchemaLoader(os.path.dirname(os.path.relpath( 41 schema_loader = SchemaLoader(
42 os.path.normpath(filenames[0]), root))) 42 os.path.dirname(os.path.relpath(os.path.normpath(filenames[0]), root)),
43 os.path.dirname(filenames[0]))
43 # Merge the source files into a single list of schemas. 44 # Merge the source files into a single list of schemas.
44 api_defs = [] 45 api_defs = []
45 for filename in filenames: 46 for filename in filenames:
46 schema = os.path.normpath(filename) 47 schema = os.path.normpath(filename)
47 schema_filename, schema_extension = os.path.splitext(schema) 48 schema_filename, schema_extension = os.path.splitext(schema)
48 path, short_filename = os.path.split(schema_filename) 49 path, short_filename = os.path.split(schema_filename)
49 api_def = schema_loader.LoadSchema(schema) 50 api_def = schema_loader.LoadSchema(short_filename + schema_extension)
not at google - send to devlin 2013/09/27 16:10:20 if you use os.path.split(schema)[1] rather than (s
msimonides 2013/09/30 07:18:48 Done.
50 51
51 # If compiling the C++ model code, delete 'nocompile' nodes. 52 # If compiling the C++ model code, delete 'nocompile' nodes.
52 if generator == 'cpp': 53 if generator == 'cpp':
53 api_def = json_schema.DeleteNodes(api_def, 'nocompile') 54 api_def = json_schema.DeleteNodes(api_def, 'nocompile')
54 api_defs.extend(api_def) 55 api_defs.extend(api_def)
55 56
56 api_model = Model() 57 api_model = Model()
57 58
58 # For single-schema compilation make sure that the first (i.e. only) schema 59 # For single-schema compilation make sure that the first (i.e. only) schema
59 # is the default one. 60 # is the default one.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 # Unless in bundle mode, only one file should be specified. 148 # Unless in bundle mode, only one file should be specified.
148 if opts.generator != 'cpp-bundle' and len(filenames) > 1: 149 if opts.generator != 'cpp-bundle' and len(filenames) > 1:
149 # TODO(sashab): Could also just use filenames[0] here and not complain. 150 # TODO(sashab): Could also just use filenames[0] here and not complain.
150 raise Exception( 151 raise Exception(
151 "Unless in bundle mode, only one file can be specified at a time.") 152 "Unless in bundle mode, only one file can be specified at a time.")
152 153
153 result = GenerateSchema(opts.generator, filenames, opts.root, opts.destdir, 154 result = GenerateSchema(opts.generator, filenames, opts.root, opts.destdir,
154 opts.namespace, opts.dart_overrides_dir) 155 opts.namespace, opts.dart_overrides_dir)
155 if not opts.destdir: 156 if not opts.destdir:
156 print result 157 print result
OLDNEW
« no previous file with comments | « no previous file | tools/json_schema_compiler/schema_loader.py » ('j') | tools/json_schema_compiler/schema_loader.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698