OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 """This is the entry point to create Dart APIs from the IDL database.""" | 6 """This is the entry point to create Dart APIs from the IDL database.""" |
7 | 7 |
8 import dartgenerator | 8 import dartgenerator |
9 import database | 9 import database |
10 import fremontcutbuilder | 10 import fremontcutbuilder |
11 import logging.config | 11 import logging.config |
12 import multiemitter | 12 import multiemitter |
13 import optparse | 13 import optparse |
14 import os | 14 import os |
15 import shutil | 15 import shutil |
16 import subprocess | 16 import subprocess |
17 import sys | 17 import sys |
18 from generator import TypeRegistry | 18 from generator import TypeRegistry |
19 from htmleventgenerator import HtmlEventGenerator | 19 from htmleventgenerator import HtmlEventGenerator |
20 from htmlrenamer import HtmlRenamer | 20 from htmlrenamer import HtmlRenamer |
21 from systemhtml import DartLibraryEmitter, Dart2JSBackend,\ | 21 from systemhtml import DartLibraryEmitter, Dart2JSBackend,\ |
22 HtmlDartInterfaceGenerator, DartLibrary, DartLibraries | 22 HtmlDartInterfaceGenerator, DartLibrary, DartLibraries |
23 from systemnative import CPPLibraryEmitter, DartiumBackend | 23 from systemnative import CPPLibraryEmitter, DartiumBackend |
24 from templateloader import TemplateLoader | 24 from templateloader import TemplateLoader |
25 | 25 |
| 26 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) |
| 27 import utils |
| 28 |
26 _logger = logging.getLogger('dartdomgenerator') | 29 _logger = logging.getLogger('dartdomgenerator') |
27 | 30 |
28 _libraries = ['html', 'indexed_db', 'svg', 'web_audio'] | 31 _libraries = ['html', 'indexed_db', 'svg', 'web_audio'] |
29 | 32 |
30 class GeneratorOptions(object): | 33 class GeneratorOptions(object): |
31 def __init__(self, templates, database, type_registry, renamer): | 34 def __init__(self, templates, database, type_registry, renamer): |
32 self.templates = templates | 35 self.templates = templates |
33 self.database = database | 36 self.database = database |
34 self.type_registry = type_registry | 37 self.type_registry = type_registry |
35 self.renamer = renamer | 38 self.renamer = renamer |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 dartium_output_dir) | 134 dartium_output_dir) |
132 cpp_library_emitter.EmitResolver( | 135 cpp_library_emitter.EmitResolver( |
133 template_loader.Load('cpp_resolver.template'), dartium_output_dir) | 136 template_loader.Load('cpp_resolver.template'), dartium_output_dir) |
134 | 137 |
135 _logger.info('Flush...') | 138 _logger.info('Flush...') |
136 emitters.Flush() | 139 emitters.Flush() |
137 | 140 |
138 def GenerateSingleFile(library_path, output_dir, generated_output_dir=None): | 141 def GenerateSingleFile(library_path, output_dir, generated_output_dir=None): |
139 library_dir = os.path.dirname(library_path) | 142 library_dir = os.path.dirname(library_path) |
140 library_filename = os.path.basename(library_path) | 143 library_filename = os.path.basename(library_path) |
141 copy_dart_script = os.path.relpath('../../../../tools/copy_dart.py', | 144 copy_dart_script = os.path.relpath('../../copy_dart.py', |
142 library_dir) | 145 library_dir) |
143 output_dir = os.path.relpath(output_dir, library_dir) | 146 output_dir = os.path.relpath(output_dir, library_dir) |
144 command = ' '.join(['cd', library_dir, ';', | 147 command = ' '.join(['cd', library_dir, ';', |
145 copy_dart_script, output_dir, library_filename]) | 148 copy_dart_script, output_dir, library_filename]) |
146 subprocess.call([command], shell=True) | 149 subprocess.call([command], shell=True) |
147 | 150 |
148 def main(): | 151 def main(): |
149 parser = optparse.OptionParser() | 152 parser = optparse.OptionParser() |
150 parser.add_option('--parallel', dest='parallel', | 153 parser.add_option('--parallel', dest='parallel', |
151 action='store_true', default=False, | 154 action='store_true', default=False, |
(...skipping 14 matching lines...) Expand all Loading... |
166 default=False, | 169 default=False, |
167 help='''Use the cached database from the previous run to | 170 help='''Use the cached database from the previous run to |
168 improve startup performance''') | 171 improve startup performance''') |
169 (options, args) = parser.parse_args() | 172 (options, args) = parser.parse_args() |
170 | 173 |
171 current_dir = os.path.dirname(__file__) | 174 current_dir = os.path.dirname(__file__) |
172 database_dir = os.path.join(current_dir, '..', 'database') | 175 database_dir = os.path.join(current_dir, '..', 'database') |
173 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) | 176 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) |
174 systems = options.systems.split(',') | 177 systems = options.systems.split(',') |
175 | 178 |
176 output_dir = options.output_dir or os.path.join(current_dir, '../generated') | 179 output_dir = options.output_dir or os.path.join( |
| 180 current_dir, '..', '..', utils.GetBuildDir(utils.GuessOS(), None), |
| 181 'generated') |
177 | 182 |
178 dart2js_output_dir = None | 183 dart2js_output_dir = None |
179 if 'htmldart2js' in systems: | 184 if 'htmldart2js' in systems: |
180 dart2js_output_dir = os.path.join(output_dir, 'dart2js') | 185 dart2js_output_dir = os.path.join(output_dir, 'dart2js') |
181 dartium_output_dir = None | 186 dartium_output_dir = None |
182 if 'htmldartium' in systems: | 187 if 'htmldartium' in systems: |
183 dartium_output_dir = os.path.join(output_dir, 'dartium') | 188 dartium_output_dir = os.path.join(output_dir, 'dartium') |
184 | 189 |
185 if options.rebuild: | 190 if options.rebuild: |
186 # Parse the IDL and create the database. | 191 # Parse the IDL and create the database. |
187 database = fremontcutbuilder.main(options.parallel) | 192 database = fremontcutbuilder.main(options.parallel) |
188 else: | 193 else: |
189 # Load the previously generated database. | 194 # Load the previously generated database. |
190 database = LoadDatabase(database_dir, options.use_database_cache) | 195 database = LoadDatabase(database_dir, options.use_database_cache) |
191 GenerateFromDatabase(database, dart2js_output_dir, dartium_output_dir) | 196 GenerateFromDatabase(database, dart2js_output_dir, dartium_output_dir) |
192 | 197 |
193 _logger.info('Add documentation to generated classes.') | 198 _logger.info('Add documentation to generated classes.') |
194 html_to_json_script = os.path.relpath( | 199 html_to_json_script = os.path.relpath( |
195 '../../../../tools/html_json_doc/bin/html_json_doc.dart', | 200 '../../html_json_doc/bin/html_json_doc.dart', |
196 current_dir) | 201 current_dir) |
197 html_output_dir = os.path.join(output_dir, 'dart2js/dart/html/') | 202 html_output_dir = os.path.join(output_dir, 'dart2js/dart/html/') |
198 svg_output_dir = os.path.join(output_dir, 'dart2js/dart/svg/') | 203 svg_output_dir = os.path.join(output_dir, 'dart2js/dart/svg/') |
199 html_json_path = os.path.relpath('../docs/html_docs.json') | 204 html_json_path = os.path.relpath('../docs/html_docs.json') |
200 svg_json_path = os.path.relpath('../docs/svg_docs.json') | 205 svg_json_path = os.path.relpath('../docs/svg_docs.json') |
201 html_command = ' '.join(['dart', html_to_json_script, '--mode=json-to-html', | 206 |
202 html_output_dir, html_json_path]) | 207 path_to_dart = utils.DartBinary() |
203 svg_command = ' '.join(['dart', html_to_json_script, '--mode=json-to-html', | 208 html_command = ' '.join([path_to_dart, html_to_json_script, |
204 svg_output_dir, svg_json_path]) | 209 '--mode=json-to-html', html_output_dir, |
| 210 html_json_path]) |
| 211 svg_command = ' '.join([path_to_dart, html_to_json_script, |
| 212 '--mode=json-to-html', svg_output_dir, svg_json_path]) |
205 subprocess.call([html_command], shell=True) | 213 subprocess.call([html_command], shell=True) |
206 subprocess.call([svg_command], shell=True) | 214 subprocess.call([svg_command], shell=True) |
207 | 215 |
208 if 'htmldart2js' in systems: | 216 if 'htmldart2js' in systems: |
209 _logger.info('Generating dart2js single files.') | 217 _logger.info('Generating dart2js single files.') |
210 for library_name in _libraries: | 218 for library_name in _libraries: |
211 GenerateSingleFile( | 219 GenerateSingleFile( |
212 os.path.join(dart2js_output_dir, '%s_dart2js.dart' % library_name), | 220 os.path.join(dart2js_output_dir, '%s_dart2js.dart' % library_name), |
213 '../../%s/dart2js' % library_name) | 221 os.path.join('..', '..', '..', 'sdk', 'lib', library_name, 'dart2js')) |
214 if 'htmldartium' in systems: | 222 if 'htmldartium' in systems: |
215 _logger.info('Generating dartium single files.') | 223 _logger.info('Generating dartium single files.') |
216 for library_name in _libraries: | 224 for library_name in _libraries: |
217 GenerateSingleFile( | 225 GenerateSingleFile( |
218 os.path.join(dartium_output_dir, '%s_dartium.dart' % library_name), | 226 os.path.join(dartium_output_dir, '%s_dartium.dart' % library_name), |
219 '../../%s/dartium' % library_name) | 227 os.path.join('..', '..', '..', 'sdk', 'lib', library_name, 'dartium')) |
220 | 228 |
221 if __name__ == '__main__': | 229 if __name__ == '__main__': |
222 sys.exit(main()) | 230 sys.exit(main()) |
OLD | NEW |