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 css_code_generator | 8 import css_code_generator |
| 9 import os |
| 10 import sys |
| 11 |
| 12 # Setup all paths to find our PYTHON code |
| 13 dart_dir = os.path.abspath(os.path.normpath(os.path.join(os.path.dirname(__file_
_), '..', '..', '..'))) |
| 14 sys.path.insert(1, os.path.join(dart_dir, 'tools/dom/new_scripts')) |
| 15 sys.path.insert(1, os.path.join(dart_dir, 'third_party/WebCore/bindings/scripts'
)) |
| 16 sys.path.insert(1, os.path.join(dart_dir, 'third_party')) |
| 17 sys.path.insert(1, os.path.join(dart_dir, 'tools/dom/scripts')) |
| 18 |
9 import dartgenerator | 19 import dartgenerator |
10 import database | 20 import database |
11 import fremontcutbuilder | 21 import fremontcutbuilder |
12 import logging | 22 import logging |
13 import monitored | 23 import monitored |
14 import multiemitter | 24 import multiemitter |
15 import optparse | 25 import optparse |
16 import os | |
17 import shutil | 26 import shutil |
18 import subprocess | 27 import subprocess |
19 import sys | 28 import time |
20 from dartmetadata import DartMetadata | 29 from dartmetadata import DartMetadata |
21 from generator import TypeRegistry | 30 from generator import TypeRegistry |
22 from htmleventgenerator import HtmlEventGenerator | 31 from htmleventgenerator import HtmlEventGenerator |
23 from htmlrenamer import HtmlRenamer | 32 from htmlrenamer import HtmlRenamer |
24 from systemhtml import DartLibraryEmitter, Dart2JSBackend,\ | 33 from systemhtml import DartLibraryEmitter, Dart2JSBackend,\ |
25 HtmlDartInterfaceGenerator, DartLibrary, DartLibraries,\ | 34 HtmlDartInterfaceGenerator, DartLibrary, DartLibraries,\ |
26 HTML_LIBRARY_NAMES | 35 HTML_LIBRARY_NAMES |
27 from systemnative import CPPLibraryEmitter, DartiumBackend, \ | 36 from systemnative import CPPLibraryEmitter, DartiumBackend, \ |
28 GetNativeLibraryEmitter | 37 GetNativeLibraryEmitter |
29 from templateloader import TemplateLoader | 38 from templateloader import TemplateLoader |
30 | 39 |
31 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) | 40 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) |
| 41 |
32 import utils | 42 import utils |
33 | 43 |
| 44 |
34 _logger = logging.getLogger('dartdomgenerator') | 45 _logger = logging.getLogger('dartdomgenerator') |
35 | 46 |
36 class GeneratorOptions(object): | 47 class GeneratorOptions(object): |
37 def __init__(self, templates, database, type_registry, renamer, | 48 def __init__(self, templates, database, type_registry, renamer, |
38 metadata): | 49 metadata): |
39 self.templates = templates | 50 self.templates = templates |
40 self.database = database | 51 self.database = database |
41 self.type_registry = type_registry | 52 self.type_registry = type_registry |
42 self.renamer = renamer | 53 self.renamer = renamer |
43 self.metadata = metadata; | 54 self.metadata = metadata; |
44 | 55 |
45 def LoadDatabase(database_dir, use_database_cache): | 56 def LoadDatabase(database_dir, use_database_cache): |
46 common_database = database.Database(database_dir) | 57 common_database = database.Database(database_dir) |
47 if use_database_cache: | 58 if use_database_cache: |
48 common_database.LoadFromCache() | 59 common_database.LoadFromCache() |
49 else: | 60 else: |
50 common_database.Load() | 61 common_database.Load() |
51 return common_database | 62 return common_database |
52 | 63 |
53 def GenerateFromDatabase(common_database, dart2js_output_dir, | 64 def GenerateFromDatabase(common_database, dart2js_output_dir, |
54 dartium_output_dir, update_dom_metadata=False): | 65 dartium_output_dir, update_dom_metadata=False, |
| 66 logging_level=logging.WARNING): |
| 67 start_time = time.time() |
| 68 |
55 current_dir = os.path.dirname(__file__) | 69 current_dir = os.path.dirname(__file__) |
56 auxiliary_dir = os.path.join(current_dir, '..', 'src') | 70 auxiliary_dir = os.path.join(current_dir, '..', 'src') |
57 template_dir = os.path.join(current_dir, '..', 'templates') | 71 template_dir = os.path.join(current_dir, '..', 'templates') |
58 | 72 |
59 generator = dartgenerator.DartGenerator() | 73 _logger.setLevel(logging_level) |
| 74 |
| 75 generator = dartgenerator.DartGenerator(logging_level) |
60 generator.LoadAuxiliary(auxiliary_dir) | 76 generator.LoadAuxiliary(auxiliary_dir) |
61 | 77 |
62 generator.FilterMembersWithUnidentifiedTypes(common_database) | 78 generator.FilterMembersWithUnidentifiedTypes(common_database) |
63 webkit_database = common_database.Clone() | 79 webkit_database = common_database.Clone() |
64 | 80 |
65 # Generate Dart interfaces for the WebKit DOM. | 81 # Generate Dart interfaces for the WebKit DOM. |
66 generator.FilterInterfaces(database = webkit_database, | 82 generator.FilterInterfaces(database = webkit_database, |
67 or_annotations = ['WebKit', 'Dart'], | 83 or_annotations = ['WebKit', 'Dart'], |
68 exclude_displaced = ['WebKit'], | 84 exclude_displaced = ['WebKit'], |
69 exclude_suppressed = ['WebKit', 'Dart']) | 85 exclude_suppressed = ['WebKit', 'Dart']) |
70 generator.FixEventTargets(webkit_database) | 86 generator.FixEventTargets(webkit_database) |
71 generator.AddMissingArguments(webkit_database) | 87 generator.AddMissingArguments(webkit_database) |
72 | 88 |
73 emitters = multiemitter.MultiEmitter() | 89 emitters = multiemitter.MultiEmitter(logging_level) |
74 metadata = DartMetadata( | 90 metadata = DartMetadata( |
75 os.path.join(current_dir, '..', 'dom.json'), | 91 os.path.join(current_dir, '..', 'dom.json'), |
76 os.path.join(current_dir, '..', 'docs', 'docs.json')) | 92 os.path.join(current_dir, '..', 'docs', 'docs.json'), |
| 93 logging_level) |
77 renamer = HtmlRenamer(webkit_database, metadata) | 94 renamer = HtmlRenamer(webkit_database, metadata) |
78 type_registry = TypeRegistry(webkit_database, renamer) | 95 type_registry = TypeRegistry(webkit_database, renamer) |
79 | 96 |
| 97 print 'GenerateFromDatabase %s seconds' % round((time.time() - start_time), 2) |
| 98 |
80 def RunGenerator(dart_libraries, dart_output_dir, | 99 def RunGenerator(dart_libraries, dart_output_dir, |
81 template_loader, backend_factory): | 100 template_loader, backend_factory): |
82 options = GeneratorOptions( | 101 options = GeneratorOptions( |
83 template_loader, webkit_database, type_registry, renamer, | 102 template_loader, webkit_database, type_registry, renamer, |
84 metadata) | 103 metadata) |
85 dart_library_emitter = DartLibraryEmitter( | 104 dart_library_emitter = DartLibraryEmitter( |
86 emitters, dart_output_dir, dart_libraries) | 105 emitters, dart_output_dir, dart_libraries) |
87 event_generator = HtmlEventGenerator(webkit_database, renamer, metadata, | 106 event_generator = HtmlEventGenerator(webkit_database, renamer, metadata, |
88 template_loader) | 107 template_loader) |
89 | 108 |
90 def generate_interface(interface): | 109 def generate_interface(interface): |
91 backend = backend_factory(interface) | 110 backend = backend_factory(interface) |
92 interface_generator = HtmlDartInterfaceGenerator( | 111 interface_generator = HtmlDartInterfaceGenerator( |
93 options, dart_library_emitter, event_generator, interface, backend) | 112 options, dart_library_emitter, event_generator, interface, backend) |
94 interface_generator.Generate() | 113 interface_generator.Generate() |
95 | 114 |
96 generator.Generate(webkit_database, common_database, generate_interface) | 115 generator.Generate(webkit_database, common_database, generate_interface) |
97 | 116 |
98 dart_library_emitter.EmitLibraries(auxiliary_dir) | 117 dart_library_emitter.EmitLibraries(auxiliary_dir) |
99 | 118 |
100 if dart2js_output_dir: | 119 if dart2js_output_dir: |
101 template_paths = ['html/dart2js', 'html/impl', 'html/interface', ''] | 120 template_paths = ['html/dart2js', 'html/impl', 'html/interface', ''] |
102 template_loader = TemplateLoader(template_dir, | 121 template_loader = TemplateLoader(template_dir, |
103 template_paths, | 122 template_paths, |
104 {'DARTIUM': False, 'DART2JS': True}) | 123 {'DARTIUM': False, 'DART2JS': True}) |
105 backend_options = GeneratorOptions( | 124 backend_options = GeneratorOptions( |
106 template_loader, webkit_database, type_registry, renamer, | 125 template_loader, webkit_database, type_registry, renamer, |
107 metadata) | 126 metadata) |
108 backend_factory = lambda interface:\ | 127 backend_factory = lambda interface:\ |
109 Dart2JSBackend(interface, backend_options) | 128 Dart2JSBackend(interface, backend_options, logging_level) |
110 | 129 |
111 dart_output_dir = os.path.join(dart2js_output_dir, 'dart') | 130 dart_output_dir = os.path.join(dart2js_output_dir, 'dart') |
112 dart_libraries = DartLibraries( | 131 dart_libraries = DartLibraries( |
113 HTML_LIBRARY_NAMES, template_loader, 'dart2js', dart2js_output_dir) | 132 HTML_LIBRARY_NAMES, template_loader, 'dart2js', dart2js_output_dir) |
114 | 133 |
115 RunGenerator(dart_libraries, dart_output_dir, | 134 print '\nGenerating dart2js:\n' |
116 template_loader, backend_factory) | 135 start_time = time.time() |
| 136 |
| 137 RunGenerator(dart_libraries, dart_output_dir, template_loader, |
| 138 backend_factory) |
| 139 |
| 140 print 'Generated dart2js in %s seconds' % round(time.time() - start_time, 2) |
117 | 141 |
118 if dartium_output_dir: | 142 if dartium_output_dir: |
119 template_paths = ['html/dartium', 'html/impl', 'html/interface', ''] | 143 template_paths = ['html/dartium', 'html/impl', 'html/interface', ''] |
120 template_loader = TemplateLoader(template_dir, | 144 template_loader = TemplateLoader(template_dir, |
121 template_paths, | 145 template_paths, |
122 {'DARTIUM': True, 'DART2JS': False}) | 146 {'DARTIUM': True, 'DART2JS': False}) |
123 backend_options = GeneratorOptions( | 147 backend_options = GeneratorOptions( |
124 template_loader, webkit_database, type_registry, renamer, | 148 template_loader, webkit_database, type_registry, renamer, |
125 metadata) | 149 metadata) |
126 cpp_output_dir = os.path.join(dartium_output_dir, 'cpp') | 150 cpp_output_dir = os.path.join(dartium_output_dir, 'cpp') |
127 cpp_library_emitter = CPPLibraryEmitter(emitters, cpp_output_dir) | 151 cpp_library_emitter = CPPLibraryEmitter(emitters, cpp_output_dir) |
128 dart_output_dir = os.path.join(dartium_output_dir, 'dart') | 152 dart_output_dir = os.path.join(dartium_output_dir, 'dart') |
129 native_library_emitter = \ | 153 native_library_emitter = \ |
130 GetNativeLibraryEmitter(emitters, template_loader, | 154 GetNativeLibraryEmitter(emitters, template_loader, |
131 dartium_output_dir, dart_output_dir, | 155 dartium_output_dir, dart_output_dir, |
132 auxiliary_dir) | 156 auxiliary_dir) |
133 backend_factory = lambda interface:\ | 157 backend_factory = lambda interface:\ |
134 DartiumBackend(interface, native_library_emitter, | 158 DartiumBackend(interface, native_library_emitter, |
135 cpp_library_emitter, backend_options) | 159 cpp_library_emitter, backend_options) |
136 dart_libraries = DartLibraries( | 160 dart_libraries = DartLibraries( |
137 HTML_LIBRARY_NAMES, template_loader, 'dartium', dartium_output_dir) | 161 HTML_LIBRARY_NAMES, template_loader, 'dartium', dartium_output_dir) |
| 162 |
| 163 print '\nGenerating dartium:\n' |
| 164 start_time = time.time() |
| 165 |
138 RunGenerator(dart_libraries, dart_output_dir, | 166 RunGenerator(dart_libraries, dart_output_dir, |
139 template_loader, backend_factory) | 167 template_loader, backend_factory) |
| 168 print 'Generated dartium in %s seconds' % round(time.time() - start_time, 2) |
| 169 |
140 cpp_library_emitter.EmitDerivedSources( | 170 cpp_library_emitter.EmitDerivedSources( |
141 template_loader.Load('cpp_derived_sources.template'), | 171 template_loader.Load('cpp_derived_sources.template'), |
142 dartium_output_dir) | 172 dartium_output_dir) |
143 cpp_library_emitter.EmitResolver( | 173 cpp_library_emitter.EmitResolver( |
144 template_loader.Load('cpp_resolver.template'), dartium_output_dir) | 174 template_loader.Load('cpp_resolver.template'), dartium_output_dir) |
145 cpp_library_emitter.EmitClassIdTable( | 175 cpp_library_emitter.EmitClassIdTable( |
146 webkit_database, dartium_output_dir, type_registry, renamer) | 176 webkit_database, dartium_output_dir, type_registry, renamer) |
147 emitters.Flush() | 177 emitters.Flush() |
148 | 178 |
149 if update_dom_metadata: | 179 if update_dom_metadata: |
150 metadata.Flush() | 180 metadata.Flush() |
151 | 181 |
152 monitored.FinishMonitoring(dart2js_output_dir) | 182 monitored.FinishMonitoring(dart2js_output_dir, _logger) |
153 | 183 |
154 def GenerateSingleFile(library_path, output_dir, generated_output_dir=None): | 184 def GenerateSingleFile(library_path, output_dir, generated_output_dir=None): |
155 library_dir = os.path.dirname(library_path) | 185 library_dir = os.path.dirname(library_path) |
156 library_filename = os.path.basename(library_path) | 186 library_filename = os.path.basename(library_path) |
157 copy_dart_script = os.path.relpath('../../copy_dart.py', | 187 copy_dart_script = os.path.relpath('../../copy_dart.py', |
158 library_dir) | 188 library_dir) |
159 output_dir = os.path.relpath(output_dir, library_dir) | 189 output_dir = os.path.relpath(output_dir, library_dir) |
160 command = ' '.join(['cd', library_dir, ';', | 190 command = ' '.join(['cd', library_dir, ';', |
161 copy_dart_script, output_dir, library_filename]) | 191 copy_dart_script, output_dir, library_filename]) |
162 subprocess.call([command], shell=True) | 192 subprocess.call([command], shell=True) |
(...skipping 22 matching lines...) Expand all Loading... |
185 help='Directory to put the generated files') | 215 help='Directory to put the generated files') |
186 parser.add_option('--use-database-cache', dest='use_database_cache', | 216 parser.add_option('--use-database-cache', dest='use_database_cache', |
187 action='store_true', | 217 action='store_true', |
188 default=False, | 218 default=False, |
189 help='''Use the cached database from the previous run to | 219 help='''Use the cached database from the previous run to |
190 improve startup performance''') | 220 improve startup performance''') |
191 parser.add_option('--update-dom-metadata', dest='update_dom_metadata', | 221 parser.add_option('--update-dom-metadata', dest='update_dom_metadata', |
192 action='store_true', | 222 action='store_true', |
193 default=False, | 223 default=False, |
194 help='''Update the metadata list of DOM APIs''') | 224 help='''Update the metadata list of DOM APIs''') |
| 225 parser.add_option('--blink-parser', dest='blink_parser', |
| 226 action='store_true', default=False, |
| 227 help='Use New Blink IDL parser.') |
| 228 parser.add_option('--verbose', dest='logging_level', |
| 229 action='store_false', default=logging.WARNING, |
| 230 help='Output all informational messages') |
| 231 parser.add_option('--logging', dest='logging', type='int', |
| 232 action='store', default=logging.NOTSET, |
| 233 help='Level of logging 20 is Info, 30 is Warnings, 40 is Err
ors') |
| 234 |
195 (options, args) = parser.parse_args() | 235 (options, args) = parser.parse_args() |
196 | 236 |
197 current_dir = os.path.dirname(__file__) | 237 current_dir = os.path.dirname(__file__) |
198 database_dir = os.path.join(current_dir, '..', 'database') | 238 database_dir = os.path.join(current_dir, '..', 'database') |
199 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) | 239 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) |
200 systems = options.systems.split(',') | 240 systems = options.systems.split(',') |
201 | 241 |
202 output_dir = options.output_dir or os.path.join( | 242 output_dir = options.output_dir or os.path.join( |
203 current_dir, '..', '..', utils.GetBuildDir(utils.GuessOS()), | 243 current_dir, '..', '..', utils.GetBuildDir(utils.GuessOS()), |
204 'generated') | 244 'generated') |
205 | 245 |
206 dart2js_output_dir = None | 246 dart2js_output_dir = None |
207 if 'htmldart2js' in systems: | 247 if 'htmldart2js' in systems: |
208 dart2js_output_dir = os.path.join(output_dir, 'dart2js') | 248 dart2js_output_dir = os.path.join(output_dir, 'dart2js') |
209 dartium_output_dir = None | 249 dartium_output_dir = None |
210 if 'htmldartium' in systems: | 250 if 'htmldartium' in systems: |
211 dartium_output_dir = os.path.join(output_dir, 'dartium') | 251 dartium_output_dir = os.path.join(output_dir, 'dartium') |
212 | 252 |
| 253 logging_level = options.logging_level \ |
| 254 if options.logging == logging.NOTSET else options.logging |
| 255 |
| 256 start_time = time.time() |
| 257 |
213 UpdateCssProperties() | 258 UpdateCssProperties() |
| 259 |
214 if options.rebuild: | 260 if options.rebuild: |
215 # Parse the IDL and create the database. | 261 # Parse the IDL and create the database. |
216 database = fremontcutbuilder.main(options.parallel) | 262 database = fremontcutbuilder.main(options.parallel, options.blink_parser, |
| 263 logging_level=logging_level) |
217 else: | 264 else: |
| 265 # TODO(terry): Should be able to remove this... |
218 # Load the previously generated database. | 266 # Load the previously generated database. |
219 database = LoadDatabase(database_dir, options.use_database_cache) | 267 if not options.blink_parser: |
| 268 database = LoadDatabase(database_dir, options.use_database_cache) |
| 269 |
220 GenerateFromDatabase(database, dart2js_output_dir, dartium_output_dir, | 270 GenerateFromDatabase(database, dart2js_output_dir, dartium_output_dir, |
221 options.update_dom_metadata) | 271 options.update_dom_metadata, logging_level) |
| 272 |
| 273 file_generation_start_time = time.time() |
222 | 274 |
223 if 'htmldart2js' in systems: | 275 if 'htmldart2js' in systems: |
224 _logger.info('Generating dart2js single files.') | 276 _logger.info('Generating dart2js single files.') |
| 277 |
225 for library_name in HTML_LIBRARY_NAMES: | 278 for library_name in HTML_LIBRARY_NAMES: |
226 GenerateSingleFile( | 279 GenerateSingleFile( |
227 os.path.join(dart2js_output_dir, '%s_dart2js.dart' % library_name), | 280 os.path.join(dart2js_output_dir, '%s_dart2js.dart' % library_name), |
228 os.path.join('..', '..', '..', 'sdk', 'lib', library_name, 'dart2js')) | 281 os.path.join('..', '..', '..', 'sdk', 'lib', library_name, 'dart2js')) |
| 282 |
229 if 'htmldartium' in systems: | 283 if 'htmldartium' in systems: |
230 _logger.info('Generating dartium single files.') | 284 _logger.info('Generating dartium single files.') |
| 285 file_generation_start_time = time.time() |
| 286 |
231 for library_name in HTML_LIBRARY_NAMES: | 287 for library_name in HTML_LIBRARY_NAMES: |
232 GenerateSingleFile( | 288 GenerateSingleFile( |
233 os.path.join(dartium_output_dir, '%s_dartium.dart' % library_name), | 289 os.path.join(dartium_output_dir, '%s_dartium.dart' % library_name), |
234 os.path.join('..', '..', '..', 'sdk', 'lib', library_name, 'dartium')) | 290 os.path.join('..', '..', '..', 'sdk', 'lib', library_name, 'dartium')) |
235 GenerateSingleFile( | 291 GenerateSingleFile( |
236 os.path.join(dartium_output_dir, '_blink_dartium.dart'), | 292 os.path.join(dartium_output_dir, '_blink_dartium.dart'), |
237 os.path.join('..', '..', '..', 'sdk', 'lib', '_blink', 'dartium')) | 293 os.path.join('..', '..', '..', 'sdk', 'lib', '_blink', 'dartium')) |
238 | 294 |
| 295 print '\nGenerating single file %s seconds' % round(time.time() - file_generat
ion_start_time, 2) |
| 296 |
| 297 end_time = time.time() |
| 298 |
| 299 print '\nDone (dartdomgenerator) %s seconds' % round(end_time - start_time, 2) |
| 300 |
239 if __name__ == '__main__': | 301 if __name__ == '__main__': |
240 sys.exit(main()) | 302 sys.exit(main()) |
OLD | NEW |