Chromium Code Reviews| 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 logging.config | 11 import logging.config |
| 11 import multiemitter | 12 import multiemitter |
| 12 import optparse | 13 import optparse |
| 13 import os | 14 import os |
| 14 import shutil | 15 import shutil |
| 15 import subprocess | 16 import subprocess |
| 16 import sys | 17 import sys |
| 17 from generator import TypeRegistry | 18 from generator import TypeRegistry |
| 18 from htmlrenamer import HtmlRenamer | 19 from htmlrenamer import HtmlRenamer |
| 19 from systembase import GeneratorOptions | 20 from systembase import GeneratorOptions |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 31 # TODO(vsm): Maybe Store these renames in the IDLs. | 32 # TODO(vsm): Maybe Store these renames in the IDLs. |
| 32 'ApplicationCache': 'DOMApplicationCache', | 33 'ApplicationCache': 'DOMApplicationCache', |
| 33 'BarProp': 'BarInfo', | 34 'BarProp': 'BarInfo', |
| 34 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext', | 35 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext', |
| 35 'FormData': 'DOMFormData', | 36 'FormData': 'DOMFormData', |
| 36 'Selection': 'DOMSelection', | 37 'Selection': 'DOMSelection', |
| 37 'SharedWorkerGlobalScope': 'SharedWorkerContext', | 38 'SharedWorkerGlobalScope': 'SharedWorkerContext', |
| 38 'Window': 'DOMWindow', | 39 'Window': 'DOMWindow', |
| 39 'WorkerGlobalScope': 'WorkerContext'} | 40 'WorkerGlobalScope': 'WorkerContext'} |
| 40 | 41 |
| 42 # TODO(vsm): Remove once we fix Dartium to pass in the database directly. | |
| 41 def Generate(database_dir, use_database_cache, dart2js_output_dir=None, | 43 def Generate(database_dir, use_database_cache, dart2js_output_dir=None, |
| 42 dartium_output_dir=None): | 44 dartium_output_dir=None): |
| 45 database = LoadDatabase(database_dir, use_database_cache) | |
| 46 GenerateFromDatabase(database, dart2js_output_dir, dartium_output_dir) | |
| 47 | |
| 48 def LoadDatabase(database_dir, use_database_cache): | |
| 49 common_database = database.Database(database_dir) | |
| 50 if use_database_cache: | |
| 51 common_database.LoadFromCache() | |
| 52 else: | |
| 53 common_database.Load() | |
| 54 return common_database | |
| 55 | |
| 56 def GenerateFromDatabase(common_database, dart2js_output_dir, | |
| 57 dartium_output_dir): | |
| 43 current_dir = os.path.dirname(__file__) | 58 current_dir = os.path.dirname(__file__) |
| 44 auxiliary_dir = os.path.join(current_dir, '..', 'src') | 59 auxiliary_dir = os.path.join(current_dir, '..', 'src') |
| 45 template_dir = os.path.join(current_dir, '..', 'templates') | 60 template_dir = os.path.join(current_dir, '..', 'templates') |
| 46 | 61 |
| 47 generator = dartgenerator.DartGenerator() | 62 generator = dartgenerator.DartGenerator() |
| 48 generator.LoadAuxiliary(auxiliary_dir) | 63 generator.LoadAuxiliary(auxiliary_dir) |
| 49 | 64 |
| 50 common_database = database.Database(database_dir) | |
| 51 if use_database_cache: | |
| 52 common_database.LoadFromCache() | |
| 53 else: | |
| 54 common_database.Load() | |
| 55 | |
| 56 generator.FilterMembersWithUnidentifiedTypes(common_database) | 65 generator.FilterMembersWithUnidentifiedTypes(common_database) |
| 57 webkit_database = common_database.Clone() | 66 webkit_database = common_database.Clone() |
| 58 | 67 |
| 59 # Generate Dart interfaces for the WebKit DOM. | 68 # Generate Dart interfaces for the WebKit DOM. |
| 60 generator.FilterInterfaces(database = webkit_database, | 69 generator.FilterInterfaces(database = webkit_database, |
| 61 or_annotations = ['WebKit', 'Dart'], | 70 or_annotations = ['WebKit', 'Dart'], |
| 62 exclude_displaced = ['WebKit'], | 71 exclude_displaced = ['WebKit'], |
| 63 exclude_suppressed = ['WebKit', 'Dart']) | 72 exclude_suppressed = ['WebKit', 'Dart']) |
| 64 generator.RenameTypes(webkit_database, _webkit_renames, True) | 73 generator.RenameTypes(webkit_database, _webkit_renames, True) |
| 65 generator.FixEventTargets(webkit_database) | 74 generator.FixEventTargets(webkit_database) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 library_dir = os.path.dirname(library_path) | 135 library_dir = os.path.dirname(library_path) |
| 127 library_filename = os.path.basename(library_path) | 136 library_filename = os.path.basename(library_path) |
| 128 copy_dart_script = os.path.relpath('../../../tools/copy_dart.py', library_dir) | 137 copy_dart_script = os.path.relpath('../../../tools/copy_dart.py', library_dir) |
| 129 output_dir = os.path.relpath(output_dir, library_dir) | 138 output_dir = os.path.relpath(output_dir, library_dir) |
| 130 command = ' '.join(['cd', library_dir, ';', | 139 command = ' '.join(['cd', library_dir, ';', |
| 131 copy_dart_script, output_dir, library_filename]) | 140 copy_dart_script, output_dir, library_filename]) |
| 132 subprocess.call([command], shell=True) | 141 subprocess.call([command], shell=True) |
| 133 | 142 |
| 134 def main(): | 143 def main(): |
| 135 parser = optparse.OptionParser() | 144 parser = optparse.OptionParser() |
| 145 parser.add_option('--rebuild', dest='rebuild', | |
| 146 action='store_true', default=False, | |
| 147 help='Rebuild the database from IDL using fremontcut.') | |
| 136 parser.add_option('--systems', dest='systems', | 148 parser.add_option('--systems', dest='systems', |
| 137 action='store', type='string', | 149 action='store', type='string', |
| 138 default='htmldart2js,htmldartium', | 150 default='htmldart2js,htmldartium', |
| 139 help='Systems to generate (htmldart2js, htmldartium)') | 151 help='Systems to generate (htmldart2js, htmldartium)') |
| 140 parser.add_option('--output-dir', dest='output_dir', | 152 parser.add_option('--output-dir', dest='output_dir', |
| 141 action='store', type='string', | 153 action='store', type='string', |
| 142 default=None, | 154 default=None, |
| 143 help='Directory to put the generated files') | 155 help='Directory to put the generated files') |
| 144 parser.add_option('--use-database-cache', dest='use_database_cache', | 156 parser.add_option('--use-database-cache', dest='use_database_cache', |
| 145 action='store_true', | 157 action='store_true', |
| 146 default=False, | 158 default=False, |
| 147 help='''Use the cached database from the previous run to | 159 help='''Use the cached database from the previous run to |
| 148 improve startup performance''') | 160 improve startup performance''') |
| 149 (options, args) = parser.parse_args() | 161 (options, args) = parser.parse_args() |
| 150 | 162 |
| 151 current_dir = os.path.dirname(__file__) | 163 current_dir = os.path.dirname(__file__) |
| 152 database_dir = os.path.join(current_dir, '..', 'database') | 164 database_dir = os.path.join(current_dir, '..', 'database') |
| 153 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) | 165 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) |
| 154 systems = options.systems.split(',') | 166 systems = options.systems.split(',') |
| 155 | 167 |
| 156 output_dir = options.output_dir or os.path.join(current_dir, '../generated') | 168 output_dir = options.output_dir or os.path.join(current_dir, '../generated') |
| 157 dart2js_output_dir = None | 169 dart2js_output_dir = None |
| 158 if 'htmldart2js' in systems: | 170 if 'htmldart2js' in systems: |
| 159 dart2js_output_dir = os.path.join(output_dir, 'dart2js') | 171 dart2js_output_dir = os.path.join(output_dir, 'dart2js') |
| 160 dartium_output_dir = None | 172 dartium_output_dir = None |
| 161 if 'htmldartium' in systems: | 173 if 'htmldartium' in systems: |
| 162 dartium_output_dir = os.path.join(output_dir, 'dartium') | 174 dartium_output_dir = os.path.join(output_dir, 'dartium') |
| 163 | 175 |
| 164 Generate(database_dir, options.use_database_cache, dart2js_output_dir, | 176 if options.rebuild: |
| 165 dartium_output_dir) | 177 # Parse the IDL and create the database. |
| 178 database = fremontcutbuilder.main() | |
| 179 else: | |
| 180 # Load the previously generated database. | |
| 181 database = LoadDatabase(database_dir, options.use_database_cache) | |
| 182 GenerateFromDatabase(database, dart2js_output_dir, | |
|
Anton Muhin
2012/09/26 17:53:09
nit: fits single line?
vsm
2012/09/28 16:17:25
Done.
| |
| 183 dartium_output_dir) | |
| 166 | 184 |
| 167 if 'htmldart2js' in systems: | 185 if 'htmldart2js' in systems: |
| 168 _logger.info('Copy html_dart2js to dart2js/') | 186 _logger.info('Copy html_dart2js to dart2js/') |
| 169 GenerateSingleFile(os.path.join(dart2js_output_dir, 'html_dart2js.dart'), | 187 GenerateSingleFile(os.path.join(dart2js_output_dir, 'html_dart2js.dart'), |
| 170 '../dart2js') | 188 '../dart2js') |
| 171 if 'htmldartium' in systems: | 189 if 'htmldartium' in systems: |
| 172 _logger.info('Copy html_dartium to dartium/') | 190 _logger.info('Copy html_dartium to dartium/') |
| 173 GenerateSingleFile(os.path.join(dartium_output_dir, 'html_dartium.dart'), | 191 GenerateSingleFile(os.path.join(dartium_output_dir, 'html_dartium.dart'), |
| 174 '../dartium') | 192 '../dartium') |
| 175 | 193 |
| 176 if __name__ == '__main__': | 194 if __name__ == '__main__': |
| 177 sys.exit(main()) | 195 sys.exit(main()) |
| OLD | NEW |