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

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: Created 7 years, 3 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(root, os.path.dirname(os.path.relpath(
42 os.path.normpath(filenames[0]), root))) 42 os.path.normpath(filenames[0]), root)))
43 # Merge the source files into a single list of schemas. 43 # Merge the source files into a single list of schemas.
44 api_defs = [] 44 api_defs = []
45 for filename in filenames: 45 for filename in filenames:
46 schema = os.path.normpath(filename) 46 schema = os.path.normpath(filename)
47 schema_filename, schema_extension = os.path.splitext(schema) 47 schema_filename, schema_extension = os.path.splitext(schema)
48 path, short_filename = os.path.split(schema_filename) 48 path, short_filename = os.path.split(schema_filename)
49 api_def = schema_loader.LoadSchema(schema) 49 api_def = schema_loader.LoadSchema(short_filename + schema_extension)
50 50
51 # If compiling the C++ model code, delete 'nocompile' nodes. 51 # If compiling the C++ model code, delete 'nocompile' nodes.
52 if generator == 'cpp': 52 if generator == 'cpp':
53 api_def = json_schema.DeleteNodes(api_def, 'nocompile') 53 api_def = json_schema.DeleteNodes(api_def, 'nocompile')
54 api_defs.extend(api_def) 54 api_defs.extend(api_def)
55 55
56 api_model = Model() 56 api_model = Model()
57 57
58 # For single-schema compilation make sure that the first (i.e. only) schema 58 # For single-schema compilation make sure that the first (i.e. only) schema
59 # is the default one. 59 # 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. 147 # Unless in bundle mode, only one file should be specified.
148 if opts.generator != 'cpp-bundle' and len(filenames) > 1: 148 if opts.generator != 'cpp-bundle' and len(filenames) > 1:
149 # TODO(sashab): Could also just use filenames[0] here and not complain. 149 # TODO(sashab): Could also just use filenames[0] here and not complain.
150 raise Exception( 150 raise Exception(
151 "Unless in bundle mode, only one file can be specified at a time.") 151 "Unless in bundle mode, only one file can be specified at a time.")
152 152
153 result = GenerateSchema(opts.generator, filenames, opts.root, opts.destdir, 153 result = GenerateSchema(opts.generator, filenames, opts.root, opts.destdir,
154 opts.namespace, opts.dart_overrides_dir) 154 opts.namespace, opts.dart_overrides_dir)
155 if not opts.destdir: 155 if not opts.destdir:
156 print result 156 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