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 10 matching lines...) Expand all Loading... | |
21 # TODO(vsm): Maybe Store these renames in the IDLs. | 21 # TODO(vsm): Maybe Store these renames in the IDLs. |
22 'ApplicationCache': 'DOMApplicationCache', | 22 'ApplicationCache': 'DOMApplicationCache', |
23 'BarProp': 'BarInfo', | 23 'BarProp': 'BarInfo', |
24 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext', | 24 'DedicatedWorkerGlobalScope': 'DedicatedWorkerContext', |
25 'FormData': 'DOMFormData', | 25 'FormData': 'DOMFormData', |
26 'Selection': 'DOMSelection', | 26 'Selection': 'DOMSelection', |
27 'SharedWorkerGlobalScope': 'SharedWorkerContext', | 27 'SharedWorkerGlobalScope': 'SharedWorkerContext', |
28 'Window': 'DOMWindow', | 28 'Window': 'DOMWindow', |
29 'WorkerGlobalScope': 'WorkerContext'} | 29 'WorkerGlobalScope': 'WorkerContext'} |
30 | 30 |
31 _webkit_renames_inverse = dict((v,k) for k, v in _webkit_renames.iteritems()) | 31 _webkit_renames_inverse = None |
nweiz
2012/02/15 21:36:00
This doesn't need to be defined top-level; it's on
Jacob
2012/02/17 00:44:23
Done.
| |
32 | 32 |
33 def GenerateDOM(systems, output_dir): | 33 _html_strip_webkit_prefix_classes = [ |
34 # TODO(sra): Make this entry point also generate HTML. | 34 'Animation', |
35 'AnimationEvent', | |
36 'AnimationList', | |
37 'BlobBuilder', | |
38 'CSSKeyframeRule', | |
39 'CSSKeyframesRule', | |
40 'CSSMatrix', | |
41 'CSSTransformValue', | |
42 'Flags', | |
43 'LoseContext', | |
44 'Point', | |
45 'TransitionEvent'] | |
46 | |
47 _html_renames = {} | |
48 _html_renames_inverse = {} | |
49 | |
50 def _AddHtmlRename(source, dest): | |
51 _html_renames[source] = dest | |
52 _html_renames_inverse[dest] = source | |
53 | |
54 def HasAncestor(interface, names_to_match, database): | |
55 for parent in interface.parents: | |
56 if (parent.type.id in names_to_match or | |
57 (database.HasInterface(parent.type.id) and | |
58 HasAncestor(database.GetInterface(parent.type.id), names_to_match, | |
59 database))): | |
60 return True | |
61 return False | |
62 | |
63 def GenerateDOM(systems, generate_html_systems, output_dir, use_database_cache): | |
35 current_dir = os.path.dirname(__file__) | 64 current_dir = os.path.dirname(__file__) |
36 | 65 |
37 generator = dartgenerator.DartGenerator( | 66 generator = dartgenerator.DartGenerator( |
38 auxiliary_dir=os.path.join(current_dir, '..', 'src'), | 67 auxiliary_dir=os.path.join(current_dir, '..', 'src'), |
39 template_dir=os.path.join(current_dir, '..', 'templates'), | 68 template_dir=os.path.join(current_dir, '..', 'templates'), |
40 base_package='') | 69 base_package='') |
41 generator.LoadAuxiliary() | 70 generator.LoadAuxiliary() |
42 | 71 |
43 common_database = database.Database( | 72 common_database = database.Database( |
44 os.path.join(current_dir, '..', 'database')) | 73 os.path.join(current_dir, '..', 'database')) |
45 common_database.Load() | 74 if use_database_cache: |
75 common_database.LoadFromCache() | |
76 else: | |
77 common_database.Load() | |
46 # Remove these types since they are mapped directly to dart. | 78 # Remove these types since they are mapped directly to dart. |
47 common_database.DeleteInterface('DOMStringMap') | 79 common_database.DeleteInterface('DOMStringMap') |
48 common_database.DeleteInterface('DOMStringList') | 80 common_database.DeleteInterface('DOMStringList') |
81 | |
82 _webkit_renames_inverse = dict((v,k) for k, v in _webkit_renames.iteritems()) | |
83 | |
49 generator.RenameTypes(common_database, { | 84 generator.RenameTypes(common_database, { |
50 # W3C -> Dart renames | 85 # W3C -> Dart renames |
51 'AbstractView': 'Window', | 86 'AbstractView': 'Window', |
52 'Function': 'EventListener', | 87 'Function': 'EventListener', |
53 'DOMStringMap': 'Map<String, String>', | 88 'DOMStringMap': 'Map<String, String>', |
54 'DOMStringList': 'List<String>', | 89 'DOMStringList': 'List<String>', |
55 }) | 90 }, False) |
56 generator.FilterMembersWithUnidentifiedTypes(common_database) | 91 generator.FilterMembersWithUnidentifiedTypes(common_database) |
57 generator.ConvertToDartTypes(common_database) | 92 generator.ConvertToDartTypes(common_database) |
58 webkit_database = common_database.Clone() | 93 webkit_database = common_database.Clone() |
59 | 94 |
60 generated_output_dir = os.path.join(output_dir, 'generated') | 95 generated_output_dir = os.path.join(output_dir, |
96 '../html/generated' if generate_html_systems else 'generated') | |
61 if os.path.exists(generated_output_dir): | 97 if os.path.exists(generated_output_dir): |
62 _logger.info('Cleaning output directory %s' % generated_output_dir) | 98 _logger.info('Cleaning output directory %s' % generated_output_dir) |
63 shutil.rmtree(generated_output_dir) | 99 shutil.rmtree(generated_output_dir) |
64 | 100 |
65 | 101 |
66 # Generate Dart interfaces for the WebKit DOM. | 102 # Generate Dart interfaces for the WebKit DOM. |
67 webkit_output_dir = generated_output_dir | 103 webkit_output_dir = generated_output_dir |
68 generator.FilterInterfaces(database = webkit_database, | 104 generator.FilterInterfaces(database = webkit_database, |
69 or_annotations = ['WebKit', 'Dart'], | 105 or_annotations = ['WebKit', 'Dart'], |
70 exclude_displaced = ['WebKit'], | 106 exclude_displaced = ['WebKit'], |
71 exclude_suppressed = ['WebKit', 'Dart']) | 107 exclude_suppressed = ['WebKit', 'Dart']) |
72 generator.RenameTypes(webkit_database, _webkit_renames) | 108 generator.RenameTypes(webkit_database, _webkit_renames, False) |
109 | |
110 if generate_html_systems: | |
111 | |
112 for interface in common_database.GetInterfaces(): | |
sra1
2012/02/16 04:43:28
It would be nice to move this out of the main flow
Jacob
2012/02/17 00:44:23
Done.
Jacob
2012/02/17 00:44:23
Done.
| |
113 if (interface.id.startswith("HTML") and | |
114 HasAncestor(interface, ['Element', 'Document'], common_database)): | |
115 _AddHtmlRename(interface.id, interface.id[4:]) | |
116 | |
117 for subclass in _html_strip_webkit_prefix_classes: | |
118 _AddHtmlRename('WebKit' + subclass, subclass) | |
119 | |
120 # TODO(jacobr): we almost want to add this commented out line back. | |
121 # _AddHtmlRename('HTMLCollection', 'ElementList') | |
122 # _AddHtmlRename('NodeList', 'ElementList') | |
123 # _AddHtmlRename('HTMLOptionsCollection', 'ElementList') | |
124 _AddHtmlRename('DOMWindow', 'Window') | |
125 generator.RenameTypes(webkit_database, _html_renames, True) | |
73 | 126 |
74 generator.Generate(database = webkit_database, | 127 generator.Generate(database = webkit_database, |
75 output_dir = webkit_output_dir, | 128 output_dir = webkit_output_dir, |
76 lib_dir = output_dir, | 129 lib_dir = output_dir, |
77 module_source_preference = ['WebKit', 'Dart'], | 130 module_source_preference = ['WebKit', 'Dart'], |
78 source_filter = ['WebKit', 'Dart'], | 131 source_filter = ['WebKit', 'Dart'], |
79 super_database = common_database, | 132 super_database = common_database, |
80 common_prefix = 'common', | 133 common_prefix = 'common', |
81 super_map = _webkit_renames_inverse, | 134 super_map = _webkit_renames_inverse, |
82 systems = systems) | 135 html_map = _html_renames_inverse, |
136 systems = systems, | |
137 generate_html_systems = generate_html_systems) | |
83 | 138 |
84 generator.Flush() | 139 generator.Flush() |
85 | 140 |
141 if 'frog' in systems: | |
142 _logger.info('Copy dom_frog to frog/') | |
143 subprocess.call(['cd .. ; ../tools/copy_dart.py frog dom_frog.dart'], | |
144 shell=True); | |
145 | |
146 if 'htmlfrog' in systems: | |
147 _logger.info('Copy html_frog to ../html/frog/') | |
148 subprocess.call(['cd ../../html ; ../tools/copy_dart.py frog html_frog.dart' ], | |
149 shell=True); | |
150 | |
86 def main(): | 151 def main(): |
87 parser = optparse.OptionParser() | 152 parser = optparse.OptionParser() |
88 parser.add_option('--systems', dest='systems', | 153 parser.add_option('--systems', dest='systems', |
89 action='store', type='string', | 154 action='store', type='string', |
90 default='frog,dummy,wrapping,htmlfrog', | 155 default='frog,dummy,wrapping', |
91 help='Systems to generate (frog, native, dummy, ' | 156 help='Systems to generate (frog, native, dummy, ' |
92 'htmlfrog)') | 157 'htmlfrog, htmldartium)') |
93 parser.add_option('--output-dir', dest='output_dir', | 158 parser.add_option('--output-dir', dest='output_dir', |
94 action='store', type='string', | 159 action='store', type='string', |
95 default=None, | 160 default=None, |
96 help='Directory to put the generated files') | 161 help='Directory to put the generated files') |
162 parser.add_option('--use-database-cache', dest='use_database_cache', | |
163 action='store', | |
164 default=False, | |
165 help='''Use the cached database from the previous run to | |
166 improve startup performance''') | |
97 (options, args) = parser.parse_args() | 167 (options, args) = parser.parse_args() |
98 | 168 |
99 current_dir = os.path.dirname(__file__) | 169 current_dir = os.path.dirname(__file__) |
100 output_dir = options.output_dir or os.path.join(current_dir, '..') | |
101 systems = options.systems.split(',') | 170 systems = options.systems.split(',') |
171 use_database_cache = options.use_database_cache | |
172 generate_html_systems = ('htmlfrog' in systems) or ('htmldartium' in systems) | |
173 output_dir = options.output_dir or ( | |
174 os.path.join(current_dir, '../../html') if generate_html_systems else | |
175 os.path.join(current_dir, '..')) | |
102 | 176 |
103 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) | 177 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) |
104 GenerateDOM(systems, output_dir) | 178 num_html_systems = ('htmlfrog' in systems) + ('htmldartium' in systems) |
sra1
2012/02/16 04:43:28
Move validation as early as feasible.
Jacob
2012/02/17 00:44:23
Done.
| |
179 if num_html_systems > 0 and num_html_systems < len(systems): | |
180 print 'Cannot generate html and dom bindings at the same time' | |
181 sys.exit(-1) | |
105 | 182 |
106 # Copy Frog DOM to frog/dom_frog.dart. | 183 GenerateDOM(systems, generate_html_systems, output_dir, use_database_cache) |
107 if 'frog' in systems: | |
108 _logger.info('Copy dom_frog to frog/') | |
109 subprocess.call(['cd .. ; ../tools/copy_dart.py frog dom_frog.dart'], | |
110 shell=True); | |
111 | 184 |
112 # Copy dummy DOM where dartc build expects it. | 185 # Copy dummy DOM where dartc build expects it. |
113 if 'dummy' in systems: | 186 if 'dummy' in systems: |
114 # TODO(sra): Make other tools pick this up directly, or do a copy_dart into | 187 # TODO(sra): Make other tools pick this up directly, or do a copy_dart into |
115 # a specific directory. | 188 # a specific directory. |
116 source = os.path.join(output_dir, 'dom_dummy.dart') | 189 source = os.path.join(output_dir, 'dom_dummy.dart') |
117 target = os.path.join(output_dir, 'dom.dart') | 190 target = os.path.join(output_dir, 'dom.dart') |
118 shutil.copyfile(source, target) | 191 shutil.copyfile(source, target) |
119 | 192 |
120 if __name__ == '__main__': | 193 if __name__ == '__main__': |
121 sys.exit(main()) | 194 sys.exit(main()) |
OLD | NEW |