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 logging.config | 10 import logging.config |
| 11 import optparse |
11 import os | 12 import os |
12 import shutil | 13 import shutil |
13 import sys | 14 import sys |
14 | 15 |
15 DOM_LIBRARY = 'dom.dart' | 16 DOM_LIBRARY = 'dom.dart' |
16 DOM_DEFAULT_LIBRARY = 'wrapping_dom.dart' | 17 DOM_DEFAULT_LIBRARY = 'wrapping_dom.dart' |
| 18 DEFAULT_SYSTEM = 'wrapping' |
17 | 19 |
18 _logger = logging.getLogger('dartdomgenerator') | 20 _logger = logging.getLogger('dartdomgenerator') |
19 | 21 |
20 _webkit_renames = { | 22 _webkit_renames = { |
21 # W3C -> WebKit name conversion | 23 # W3C -> WebKit name conversion |
22 # TODO(vsm): Maybe Store these renames in the IDLs. | 24 # TODO(vsm): Maybe Store these renames in the IDLs. |
23 'ApplicationCache': 'DOMApplicationCache', | 25 'ApplicationCache': 'DOMApplicationCache', |
24 'BarProp': 'BarInfo', | 26 'BarProp': 'BarInfo', |
25 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext', | 27 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext', |
26 'FormData': 'DOMFormData', | 28 'FormData': 'DOMFormData', |
27 'Selection': 'DOMSelection', | 29 'Selection': 'DOMSelection', |
28 'SharedWorkerGlobalScope': 'SharedWorkerContext', | 30 'SharedWorkerGlobalScope': 'SharedWorkerContext', |
29 'Window': 'DOMWindow', | 31 'Window': 'DOMWindow', |
30 'WorkerGlobalScope': 'WorkerContext'} | 32 'WorkerGlobalScope': 'WorkerContext'} |
31 | 33 |
32 _webkit_renames_inverse = dict((v,k) for k, v in _webkit_renames.iteritems()) | 34 _webkit_renames_inverse = dict((v,k) for k, v in _webkit_renames.iteritems()) |
33 | 35 |
34 def GenerateDOM(output_dir): | 36 def GenerateDOM(systems, output_dir): |
35 # TODO(sra): Make this entry point also generate HTML. | 37 # TODO(sra): Make this entry point also generate HTML. |
36 current_dir = os.path.dirname(__file__) | 38 current_dir = os.path.dirname(__file__) |
37 | 39 |
38 generator = dartgenerator.DartGenerator( | 40 generator = dartgenerator.DartGenerator( |
39 auxiliary_dir=os.path.join(current_dir, '..', 'src'), | 41 auxiliary_dir=os.path.join(current_dir, '..', 'src'), |
40 template_dir=os.path.join(current_dir, '..', 'templates'), | 42 template_dir=os.path.join(current_dir, '..', 'templates'), |
41 base_package='') | 43 base_package='') |
42 generator.LoadAuxiliary() | 44 generator.LoadAuxiliary() |
43 | 45 |
44 common_database = database.Database( | 46 common_database = database.Database( |
(...skipping 27 matching lines...) Expand all Loading... |
72 exclude_suppressed = ['WebKit', 'Dart']) | 74 exclude_suppressed = ['WebKit', 'Dart']) |
73 generator.RenameTypes(webkit_database, _webkit_renames) | 75 generator.RenameTypes(webkit_database, _webkit_renames) |
74 | 76 |
75 generator.Generate(database = webkit_database, | 77 generator.Generate(database = webkit_database, |
76 output_dir = webkit_output_dir, | 78 output_dir = webkit_output_dir, |
77 lib_dir = output_dir, | 79 lib_dir = output_dir, |
78 module_source_preference = ['WebKit', 'Dart'], | 80 module_source_preference = ['WebKit', 'Dart'], |
79 source_filter = ['WebKit', 'Dart'], | 81 source_filter = ['WebKit', 'Dart'], |
80 super_database = common_database, | 82 super_database = common_database, |
81 common_prefix = 'common', | 83 common_prefix = 'common', |
82 super_map = _webkit_renames_inverse) | 84 super_map = _webkit_renames_inverse, |
| 85 systems = systems) |
83 | 86 |
84 generator.Flush() | 87 generator.Flush() |
85 | 88 |
86 # Install default DOM library. | 89 def main(): |
87 default = os.path.join(output_dir, DOM_DEFAULT_LIBRARY) | 90 parser = optparse.OptionParser() |
88 target = os.path.join(output_dir, DOM_LIBRARY) | 91 parser.add_option('--systems', dest='systems', |
89 shutil.copyfile(default, target) | 92 action='store', type='string', |
| 93 default='frog,wrapping', |
| 94 help='Systems to generate (frog, native, wrapping)') |
| 95 parser.add_option('--output-dir', dest='output_dir', |
| 96 action='store', type='string', |
| 97 default=None, |
| 98 help='Directory to put the generated files') |
| 99 (options, args) = parser.parse_args() |
90 | 100 |
91 def main(): | |
92 current_dir = os.path.dirname(__file__) | 101 current_dir = os.path.dirname(__file__) |
| 102 output_dir = options.output_dir or os.path.join(current_dir, '..') |
| 103 systems = options.systems.split(',') |
| 104 |
93 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) | 105 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) |
94 GenerateDOM(os.path.join(current_dir, '..')) | 106 GenerateDOM(systems, output_dir) |
| 107 |
| 108 if DEFAULT_SYSTEM in systems: |
| 109 # Install default DOM library. |
| 110 default = os.path.join(output_dir, DOM_DEFAULT_LIBRARY) |
| 111 target = os.path.join(output_dir, DOM_LIBRARY) |
| 112 shutil.copyfile(default, target) |
95 | 113 |
96 if __name__ == '__main__': | 114 if __name__ == '__main__': |
97 sys.exit(main()) | 115 sys.exit(main()) |
OLD | NEW |