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 |
(...skipping 19 matching lines...) Expand all Loading... |
30 # TODO(vsm): Maybe Store these renames in the IDLs. | 30 # TODO(vsm): Maybe Store these renames in the IDLs. |
31 'ApplicationCache': 'DOMApplicationCache', | 31 'ApplicationCache': 'DOMApplicationCache', |
32 'BarProp': 'BarInfo', | 32 'BarProp': 'BarInfo', |
33 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext', | 33 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext', |
34 'FormData': 'DOMFormData', | 34 'FormData': 'DOMFormData', |
35 'Selection': 'DOMSelection', | 35 'Selection': 'DOMSelection', |
36 'SharedWorkerGlobalScope': 'SharedWorkerContext', | 36 'SharedWorkerGlobalScope': 'SharedWorkerContext', |
37 'Window': 'DOMWindow', | 37 'Window': 'DOMWindow', |
38 'WorkerGlobalScope': 'WorkerContext'} | 38 'WorkerGlobalScope': 'WorkerContext'} |
39 | 39 |
40 def Generate(system_names, database_dir, use_database_cache, dom_output_dir, | 40 def Generate(system_names, database_dir, use_database_cache, |
41 html_output_dir): | 41 html_output_dir): |
42 current_dir = os.path.dirname(__file__) | 42 current_dir = os.path.dirname(__file__) |
43 auxiliary_dir = os.path.join(current_dir, '..', 'src') | 43 auxiliary_dir = os.path.join(current_dir, '..', 'src') |
44 template_dir = os.path.join(current_dir, '..', 'templates') | 44 template_dir = os.path.join(current_dir, '..', 'templates') |
45 | 45 |
46 generator = dartgenerator.DartGenerator() | 46 generator = dartgenerator.DartGenerator() |
47 generator.LoadAuxiliary(auxiliary_dir) | 47 generator.LoadAuxiliary(auxiliary_dir) |
48 | 48 |
49 common_database = database.Database(database_dir) | 49 common_database = database.Database(database_dir) |
50 if use_database_cache: | 50 if use_database_cache: |
(...skipping 21 matching lines...) Expand all Loading... |
72 output_dir) | 72 output_dir) |
73 | 73 |
74 def Generate(system): | 74 def Generate(system): |
75 generator.Generate(webkit_database, system, | 75 generator.Generate(webkit_database, system, |
76 super_database=common_database, | 76 super_database=common_database, |
77 webkit_renames=_webkit_renames) | 77 webkit_renames=_webkit_renames) |
78 | 78 |
79 emitters = multiemitter.MultiEmitter() | 79 emitters = multiemitter.MultiEmitter() |
80 | 80 |
81 for system_name in system_names: | 81 for system_name in system_names: |
82 if system_name in ['htmldart2js', 'htmldartium']: | 82 renamer = HtmlRenamer(webkit_database) |
83 renamer = HtmlRenamer(webkit_database) | 83 type_registry = TypeRegistry(webkit_database, renamer) |
84 type_registry = TypeRegistry(webkit_database, renamer) | 84 if system_name == 'htmldart2js': |
85 if system_name == 'htmldart2js': | |
86 options = CreateGeneratorOptions( | |
87 ['html/dart2js', 'html/impl', 'html', ''], | |
88 {'DARTIUM': False, 'DART2JS': True}, | |
89 type_registry, html_output_dir, renamer) | |
90 backend = HtmlDart2JSSystem(options) | |
91 else: | |
92 options = CreateGeneratorOptions( | |
93 ['dom/native', 'html/dartium', 'html/impl', ''], | |
94 {'DARTIUM': True, 'DART2JS': False}, | |
95 type_registry, html_output_dir, renamer) | |
96 backend = NativeImplementationSystem(options, auxiliary_dir) | |
97 options = CreateGeneratorOptions( | 85 options = CreateGeneratorOptions( |
98 ['html/interface', 'html/impl', 'html', ''], {}, | 86 ['html/dart2js', 'html/impl', 'html', ''], |
| 87 {'DARTIUM': False, 'DART2JS': True}, |
99 type_registry, html_output_dir, renamer) | 88 type_registry, html_output_dir, renamer) |
100 html_system = HtmlInterfacesSystem(options, backend) | 89 backend = HtmlDart2JSSystem(options) |
101 Generate(html_system) | |
102 else: | 90 else: |
103 type_registry = TypeRegistry(webkit_database) | |
104 options = CreateGeneratorOptions( | 91 options = CreateGeneratorOptions( |
105 ['dom/interface', 'dom', ''], {}, type_registry, dom_output_dir) | 92 ['dom/native', 'html/dartium', 'html/impl', ''], |
106 interface_system = InterfacesSystem(options) | 93 {'DARTIUM': True, 'DART2JS': False}, |
107 if system_name == 'dummy': | 94 type_registry, html_output_dir, renamer) |
108 options = CreateGeneratorOptions( | 95 backend = NativeImplementationSystem(options, auxiliary_dir) |
109 ['dom/dummy', 'dom', ''], {}, type_registry, dom_output_dir) | 96 options = CreateGeneratorOptions( |
110 implementation_system = dartgenerator.DummyImplementationSystem( | 97 ['html/interface', 'html/impl', 'html', ''], {}, |
111 options) | 98 type_registry, html_output_dir, renamer) |
112 elif system_name == 'dart2js': | 99 html_system = HtmlInterfacesSystem(options, backend) |
113 options = CreateGeneratorOptions( | 100 Generate(html_system) |
114 ['dom/dart2js', 'dom', ''], {}, type_registry, dom_output_dir) | |
115 implementation_system = Dart2JSSystem(options) | |
116 else: | |
117 raise Exception('Unsupported system_name %s' % system_name) | |
118 | |
119 # Makes interface files available for listing in the library for the | |
120 # implementation system. | |
121 implementation_system._interface_system = interface_system | |
122 Generate(interface_system) | |
123 Generate(implementation_system) | |
124 | 101 |
125 _logger.info('Flush...') | 102 _logger.info('Flush...') |
126 emitters.Flush() | 103 emitters.Flush() |
127 | 104 |
128 def GenerateSingleFile(systems): | 105 def GenerateSingleFile(systems): |
129 if 'dart2js' in systems: | |
130 _logger.info('Copy dom_dart2js to dart2js/') | |
131 subprocess.call(['cd ../generated ; ' | |
132 '../../../tools/copy_dart.py ../dart2js dom_dart2js.dart'], | |
133 shell=True) | |
134 | |
135 if 'htmldart2js' in systems: | 106 if 'htmldart2js' in systems: |
136 _logger.info('Copy html_dart2js to ../html/dart2js/') | 107 _logger.info('Copy html_dart2js to ../html/dart2js/') |
137 subprocess.call(['cd ../../html/generated ; ' | 108 subprocess.call(['cd ../../html/generated ; ' |
138 '../../../tools/copy_dart.py ../dart2js html_dart2js.dart']
, | 109 '../../../tools/copy_dart.py ../dart2js html_dart2js.dart']
, |
139 shell=True) | 110 shell=True) |
140 | 111 |
141 if 'htmldartium' in systems: | 112 if 'htmldartium' in systems: |
142 _logger.info('Copy html_dartium to ../html/dartium/') | 113 _logger.info('Copy html_dartium to ../html/dartium/') |
143 subprocess.call(['cd ../../html/generated ; ' | 114 subprocess.call(['cd ../../html/generated ; ' |
144 '../../../tools/copy_dart.py ../dartium html_dartium.dart']
, | 115 '../../../tools/copy_dart.py ../dartium html_dartium.dart']
, |
145 shell=True) | 116 shell=True) |
146 | 117 |
147 # Copy dummy DOM where dartc build expects it. | |
148 if 'dummy' in systems: | |
149 _logger.info('Copy dom_dummy to dom.dart') | |
150 subprocess.call(['cd ../generated ; ' | |
151 '../../../tools/copy_dart.py dummy dom_dummy.dart ;' | |
152 'cp dummy/dom_dummy.dart ../dom.dart'], | |
153 shell=True) | |
154 | |
155 def main(): | 118 def main(): |
156 parser = optparse.OptionParser() | 119 parser = optparse.OptionParser() |
157 parser.add_option('--systems', dest='systems', | 120 parser.add_option('--systems', dest='systems', |
158 action='store', type='string', | 121 action='store', type='string', |
159 default='dart2js,dummy,htmldart2js,htmldartium', | 122 default='htmldart2js,htmldartium', |
160 help='Systems to generate (dart2js, dummy, ' | 123 help='Systems to generate (' |
161 'htmldart2js, htmldartium)') | 124 'htmldart2js, htmldartium)') |
162 parser.add_option('--output-dir', dest='output_dir', | 125 parser.add_option('--output-dir', dest='output_dir', |
163 action='store', type='string', | 126 action='store', type='string', |
164 default=None, | 127 default=None, |
165 help='Directory to put the generated files') | 128 help='Directory to put the generated files') |
166 parser.add_option('--use-database-cache', dest='use_database_cache', | 129 parser.add_option('--use-database-cache', dest='use_database_cache', |
167 action='store_true', | 130 action='store_true', |
168 default=False, | 131 default=False, |
169 help='''Use the cached database from the previous run to | 132 help='''Use the cached database from the previous run to |
170 improve startup performance''') | 133 improve startup performance''') |
171 (options, args) = parser.parse_args() | 134 (options, args) = parser.parse_args() |
172 | 135 |
173 current_dir = os.path.dirname(__file__) | 136 current_dir = os.path.dirname(__file__) |
174 database_dir = os.path.join(current_dir, '..', 'database') | 137 database_dir = os.path.join(current_dir, '..', 'database') |
175 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) | 138 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) |
176 systems = options.systems.split(',') | 139 systems = options.systems.split(',') |
177 | 140 |
178 dom_output_dir = options.output_dir or os.path.join(current_dir, | |
179 '../generated') | |
180 html_output_dir = options.output_dir or os.path.join(current_dir, | 141 html_output_dir = options.output_dir or os.path.join(current_dir, |
181 '../../html/generated') | 142 '../../html/generated') |
182 Generate(systems, database_dir, options.use_database_cache, | 143 Generate(systems, database_dir, options.use_database_cache, |
183 dom_output_dir, html_output_dir) | 144 html_output_dir) |
184 GenerateSingleFile(systems) | 145 GenerateSingleFile(systems) |
185 | 146 |
186 if __name__ == '__main__': | 147 if __name__ == '__main__': |
187 sys.exit(main()) | 148 sys.exit(main()) |
OLD | NEW |