Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: client/dom/scripts/dartdomgenerator.py

Issue 9403004: Wrapperless dart:html generator (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Final version to check in. changes generator script but doesn't check in an active version of the … Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | client/dom/scripts/dartgenerator.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 _html_strip_webkit_prefix_classes = [
32 'Animation',
33 'AnimationEvent',
34 'AnimationList',
35 'BlobBuilder',
36 'CSSKeyframeRule',
37 'CSSKeyframesRule',
38 'CSSMatrix',
39 'CSSTransformValue',
40 'Flags',
41 'LoseContext',
42 'Point',
43 'TransitionEvent']
32 44
33 def GenerateDOM(systems, output_dir): 45 def HasAncestor(interface, names_to_match, database):
34 # TODO(sra): Make this entry point also generate HTML. 46 for parent in interface.parents:
47 if (parent.type.id in names_to_match or
48 (database.HasInterface(parent.type.id) and
49 HasAncestor(database.GetInterface(parent.type.id), names_to_match,
50 database))):
51 return True
52 return False
53
54 def _MakeHtmlRenames(common_database):
55 html_renames = {}
56
57 for interface in common_database.GetInterfaces():
58 if (interface.id.startswith("HTML") and
59 HasAncestor(interface, ['Element', 'Document'], common_database)):
60 html_renames[interface.id] = interface.id[4:]
61
62 for subclass in _html_strip_webkit_prefix_classes:
63 html_renames['WebKit' + subclass] = subclass
64
65 # TODO(jacobr): we almost want to add this commented out line back.
66 # html_renames['HTMLCollection'] = 'ElementList'
67 # html_renames['NodeList'] = 'ElementList'
68 # html_renames['HTMLOptionsCollection'] = 'ElementList'
69 html_renames['DOMWindow'] = 'Window'
70
71 return html_renames
72
73 def GenerateDOM(systems, generate_html_systems, output_dir, use_database_cache):
35 current_dir = os.path.dirname(__file__) 74 current_dir = os.path.dirname(__file__)
36 75
37 generator = dartgenerator.DartGenerator( 76 generator = dartgenerator.DartGenerator(
38 auxiliary_dir=os.path.join(current_dir, '..', 'src'), 77 auxiliary_dir=os.path.join(current_dir, '..', 'src'),
39 template_dir=os.path.join(current_dir, '..', 'templates'), 78 template_dir=os.path.join(current_dir, '..', 'templates'),
40 base_package='') 79 base_package='')
41 generator.LoadAuxiliary() 80 generator.LoadAuxiliary()
42 81
43 common_database = database.Database( 82 common_database = database.Database(
44 os.path.join(current_dir, '..', 'database')) 83 os.path.join(current_dir, '..', 'database'))
45 common_database.Load() 84 if use_database_cache:
85 common_database.LoadFromCache()
86 else:
87 common_database.Load()
46 # Remove these types since they are mapped directly to dart. 88 # Remove these types since they are mapped directly to dart.
47 common_database.DeleteInterface('DOMStringMap') 89 common_database.DeleteInterface('DOMStringMap')
48 common_database.DeleteInterface('DOMStringList') 90 common_database.DeleteInterface('DOMStringList')
91
49 generator.RenameTypes(common_database, { 92 generator.RenameTypes(common_database, {
50 # W3C -> Dart renames 93 # W3C -> Dart renames
51 'AbstractView': 'Window', 94 'AbstractView': 'Window',
52 'Function': 'EventListener', 95 'Function': 'EventListener',
53 'DOMStringMap': 'Map<String, String>', 96 'DOMStringMap': 'Map<String, String>',
54 'DOMStringList': 'List<String>', 97 'DOMStringList': 'List<String>',
55 }) 98 }, False)
56 generator.FilterMembersWithUnidentifiedTypes(common_database) 99 generator.FilterMembersWithUnidentifiedTypes(common_database)
57 webkit_database = common_database.Clone() 100 webkit_database = common_database.Clone()
58 # FIXME: get rid of _original_idl_types map in dartgenerator.py and 101 # FIXME: get rid of _original_idl_types map in dartgenerator.py and
59 # call ConvertToDartTypes before cloning. 102 # call ConvertToDartTypes before cloning.
60 generator.ConvertToDartTypes(common_database) 103 generator.ConvertToDartTypes(common_database)
61 generator.ConvertToDartTypes(webkit_database) 104 generator.ConvertToDartTypes(webkit_database)
62 105
63 generated_output_dir = os.path.join(output_dir, 'generated') 106 generated_output_dir = os.path.join(output_dir,
107 '../html/generated' if generate_html_systems else 'generated')
64 if os.path.exists(generated_output_dir): 108 if os.path.exists(generated_output_dir):
65 _logger.info('Cleaning output directory %s' % generated_output_dir) 109 _logger.info('Cleaning output directory %s' % generated_output_dir)
66 shutil.rmtree(generated_output_dir) 110 shutil.rmtree(generated_output_dir)
67 111
68 112
69 # Generate Dart interfaces for the WebKit DOM. 113 # Generate Dart interfaces for the WebKit DOM.
70 webkit_output_dir = generated_output_dir 114 webkit_output_dir = generated_output_dir
71 generator.FilterInterfaces(database = webkit_database, 115 generator.FilterInterfaces(database = webkit_database,
72 or_annotations = ['WebKit', 'Dart'], 116 or_annotations = ['WebKit', 'Dart'],
73 exclude_displaced = ['WebKit'], 117 exclude_displaced = ['WebKit'],
74 exclude_suppressed = ['WebKit', 'Dart']) 118 exclude_suppressed = ['WebKit', 'Dart'])
75 generator.RenameTypes(webkit_database, _webkit_renames) 119 generator.RenameTypes(webkit_database, _webkit_renames, False)
120
121 if generate_html_systems:
122 html_renames = _MakeHtmlRenames(common_database)
123 generator.RenameTypes(webkit_database, html_renames, True)
124 html_renames_inverse = dict((v,k) for k, v in html_renames.iteritems())
125 else:
126 html_renames_inverse = {}
127
128 webkit_renames_inverse = dict((v,k) for k, v in _webkit_renames.iteritems())
76 129
77 generator.Generate(database = webkit_database, 130 generator.Generate(database = webkit_database,
78 output_dir = webkit_output_dir, 131 output_dir = webkit_output_dir,
79 lib_dir = output_dir, 132 lib_dir = output_dir,
80 module_source_preference = ['WebKit', 'Dart'], 133 module_source_preference = ['WebKit', 'Dart'],
81 source_filter = ['WebKit', 'Dart'], 134 source_filter = ['WebKit', 'Dart'],
82 super_database = common_database, 135 super_database = common_database,
83 common_prefix = 'common', 136 common_prefix = 'common',
84 super_map = _webkit_renames_inverse, 137 super_map = webkit_renames_inverse,
138 html_map = html_renames_inverse,
85 systems = systems) 139 systems = systems)
86 140
87 generator.Flush() 141 generator.Flush()
88 142
143 if 'frog' in systems:
144 _logger.info('Copy dom_frog to frog/')
145 subprocess.call(['cd .. ; ../tools/copy_dart.py frog dom_frog.dart'],
146 shell=True);
147
148 if 'htmlfrog' in systems:
149 _logger.info('Copy html_frog to ../html/frog/')
150 subprocess.call(['cd ../../html ; ../tools/copy_dart.py frog html_frog.dart' ],
151 shell=True);
152
89 def main(): 153 def main():
90 parser = optparse.OptionParser() 154 parser = optparse.OptionParser()
91 parser.add_option('--systems', dest='systems', 155 parser.add_option('--systems', dest='systems',
92 action='store', type='string', 156 action='store', type='string',
93 default='frog,dummy,wrapping,htmlfrog', 157 default='frog,dummy,wrapping',
94 help='Systems to generate (frog, native, dummy, ' 158 help='Systems to generate (frog, native, dummy, '
95 'htmlfrog)') 159 'htmlfrog, htmldartium)')
96 parser.add_option('--output-dir', dest='output_dir', 160 parser.add_option('--output-dir', dest='output_dir',
97 action='store', type='string', 161 action='store', type='string',
98 default=None, 162 default=None,
99 help='Directory to put the generated files') 163 help='Directory to put the generated files')
164 parser.add_option('--use-database-cache', dest='use_database_cache',
165 action='store',
166 default=False,
167 help='''Use the cached database from the previous run to
168 improve startup performance''')
100 (options, args) = parser.parse_args() 169 (options, args) = parser.parse_args()
101 170
102 current_dir = os.path.dirname(__file__) 171 current_dir = os.path.dirname(__file__)
103 output_dir = options.output_dir or os.path.join(current_dir, '..')
104 systems = options.systems.split(',') 172 systems = options.systems.split(',')
173 num_html_systems = ('htmlfrog' in systems) + ('htmldartium' in systems)
174 if num_html_systems > 0 and num_html_systems < len(systems):
175 print 'Cannot generate html and dom bindings at the same time'
176 sys.exit(-1)
177
178 use_database_cache = options.use_database_cache
179 generate_html_systems = ('htmlfrog' in systems) or ('htmldartium' in systems)
180 output_dir = options.output_dir or (
181 os.path.join(current_dir, '../../html') if generate_html_systems else
182 os.path.join(current_dir, '..'))
105 183
106 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) 184 logging.config.fileConfig(os.path.join(current_dir, 'logging.conf'))
107 GenerateDOM(systems, output_dir)
108 185
109 # Copy Frog DOM to frog/dom_frog.dart. 186 GenerateDOM(systems, generate_html_systems, output_dir, use_database_cache)
110 if 'frog' in systems:
111 _logger.info('Copy dom_frog to frog/')
112 subprocess.call(['cd .. ; ../tools/copy_dart.py frog dom_frog.dart'],
113 shell=True);
114 187
115 # Copy dummy DOM where dartc build expects it. 188 # Copy dummy DOM where dartc build expects it.
116 if 'dummy' in systems: 189 if 'dummy' in systems:
117 # TODO(sra): Make other tools pick this up directly, or do a copy_dart into 190 # TODO(sra): Make other tools pick this up directly, or do a copy_dart into
118 # a specific directory. 191 # a specific directory.
119 source = os.path.join(output_dir, 'dom_dummy.dart') 192 source = os.path.join(output_dir, 'dom_dummy.dart')
120 target = os.path.join(output_dir, 'dom.dart') 193 target = os.path.join(output_dir, 'dom.dart')
121 shutil.copyfile(source, target) 194 shutil.copyfile(source, target)
122 195
123 if __name__ == '__main__': 196 if __name__ == '__main__':
124 sys.exit(main()) 197 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | client/dom/scripts/dartgenerator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698