Index: client/dom/scripts/dartdomgenerator.py |
diff --git a/client/dom/scripts/dartdomgenerator.py b/client/dom/scripts/dartdomgenerator.py |
index 950f5d95b60fdaf6e4a6ef88a42dc37e5087913c..7d8337e63b1a36e2b5cc617e4ab5cd808e797868 100755 |
--- a/client/dom/scripts/dartdomgenerator.py |
+++ b/client/dom/scripts/dartdomgenerator.py |
@@ -28,10 +28,49 @@ _webkit_renames = { |
'Window': 'DOMWindow', |
'WorkerGlobalScope': 'WorkerContext'} |
-_webkit_renames_inverse = dict((v,k) for k, v in _webkit_renames.iteritems()) |
- |
-def GenerateDOM(systems, output_dir): |
- # TODO(sra): Make this entry point also generate HTML. |
+_html_strip_webkit_prefix_classes = [ |
+ 'Animation', |
+ 'AnimationEvent', |
+ 'AnimationList', |
+ 'BlobBuilder', |
+ 'CSSKeyframeRule', |
+ 'CSSKeyframesRule', |
+ 'CSSMatrix', |
+ 'CSSTransformValue', |
+ 'Flags', |
+ 'LoseContext', |
+ 'Point', |
+ 'TransitionEvent'] |
+ |
+def HasAncestor(interface, names_to_match, database): |
+ for parent in interface.parents: |
+ if (parent.type.id in names_to_match or |
+ (database.HasInterface(parent.type.id) and |
+ HasAncestor(database.GetInterface(parent.type.id), names_to_match, |
+ database))): |
+ return True |
+ return False |
+ |
+def _MakeHtmlRenames(common_database): |
+ html_renames = {} |
+ |
+ for interface in common_database.GetInterfaces(): |
+ if (interface.id.startswith("HTML") and |
+ HasAncestor(interface, ['Element', 'Document'], common_database)): |
+ html_renames[interface.id] = interface.id[4:] |
+ |
+ for subclass in _html_strip_webkit_prefix_classes: |
+ html_renames['WebKit' + subclass] = subclass |
+ |
+ # TODO(jacobr): we almost want to add this commented out line back. |
+ # html_renames['HTMLCollection'] = 'ElementList' |
+ # html_renames['NodeList'] = 'ElementList' |
+ # html_renames['HTMLOptionsCollection'] = 'ElementList' |
+ html_renames['DOMWindow'] = 'Window' |
+ |
+ return html_renames |
+ |
+def GenerateDOM(systems, generate_html_systems, output_dir, use_database_cache): |
current_dir = os.path.dirname(__file__) |
generator = dartgenerator.DartGenerator( |
@@ -42,17 +81,21 @@ def GenerateDOM(systems, output_dir): |
common_database = database.Database( |
os.path.join(current_dir, '..', 'database')) |
- common_database.Load() |
+ if use_database_cache: |
+ common_database.LoadFromCache() |
+ else: |
+ common_database.Load() |
# Remove these types since they are mapped directly to dart. |
common_database.DeleteInterface('DOMStringMap') |
common_database.DeleteInterface('DOMStringList') |
+ |
generator.RenameTypes(common_database, { |
# W3C -> Dart renames |
'AbstractView': 'Window', |
'Function': 'EventListener', |
'DOMStringMap': 'Map<String, String>', |
'DOMStringList': 'List<String>', |
- }) |
+ }, False) |
generator.FilterMembersWithUnidentifiedTypes(common_database) |
webkit_database = common_database.Clone() |
# FIXME: get rid of _original_idl_types map in dartgenerator.py and |
@@ -60,7 +103,8 @@ def GenerateDOM(systems, output_dir): |
generator.ConvertToDartTypes(common_database) |
generator.ConvertToDartTypes(webkit_database) |
- generated_output_dir = os.path.join(output_dir, 'generated') |
+ generated_output_dir = os.path.join(output_dir, |
+ '../html/generated' if generate_html_systems else 'generated') |
if os.path.exists(generated_output_dir): |
_logger.info('Cleaning output directory %s' % generated_output_dir) |
shutil.rmtree(generated_output_dir) |
@@ -72,7 +116,16 @@ def GenerateDOM(systems, output_dir): |
or_annotations = ['WebKit', 'Dart'], |
exclude_displaced = ['WebKit'], |
exclude_suppressed = ['WebKit', 'Dart']) |
- generator.RenameTypes(webkit_database, _webkit_renames) |
+ generator.RenameTypes(webkit_database, _webkit_renames, False) |
+ |
+ if generate_html_systems: |
+ html_renames = _MakeHtmlRenames(common_database) |
+ generator.RenameTypes(webkit_database, html_renames, True) |
+ html_renames_inverse = dict((v,k) for k, v in html_renames.iteritems()) |
+ else: |
+ html_renames_inverse = {} |
+ |
+ webkit_renames_inverse = dict((v,k) for k, v in _webkit_renames.iteritems()) |
generator.Generate(database = webkit_database, |
output_dir = webkit_output_dir, |
@@ -81,36 +134,56 @@ def GenerateDOM(systems, output_dir): |
source_filter = ['WebKit', 'Dart'], |
super_database = common_database, |
common_prefix = 'common', |
- super_map = _webkit_renames_inverse, |
+ super_map = webkit_renames_inverse, |
+ html_map = html_renames_inverse, |
systems = systems) |
generator.Flush() |
+ if 'frog' in systems: |
+ _logger.info('Copy dom_frog to frog/') |
+ subprocess.call(['cd .. ; ../tools/copy_dart.py frog dom_frog.dart'], |
+ shell=True); |
+ |
+ if 'htmlfrog' in systems: |
+ _logger.info('Copy html_frog to ../html/frog/') |
+ subprocess.call(['cd ../../html ; ../tools/copy_dart.py frog html_frog.dart'], |
+ shell=True); |
+ |
def main(): |
parser = optparse.OptionParser() |
parser.add_option('--systems', dest='systems', |
action='store', type='string', |
- default='frog,dummy,wrapping,htmlfrog', |
+ default='frog,dummy,wrapping', |
help='Systems to generate (frog, native, dummy, ' |
- 'htmlfrog)') |
+ 'htmlfrog, htmldartium)') |
parser.add_option('--output-dir', dest='output_dir', |
action='store', type='string', |
default=None, |
help='Directory to put the generated files') |
+ parser.add_option('--use-database-cache', dest='use_database_cache', |
+ action='store', |
+ default=False, |
+ help='''Use the cached database from the previous run to |
+ improve startup performance''') |
(options, args) = parser.parse_args() |
current_dir = os.path.dirname(__file__) |
- output_dir = options.output_dir or os.path.join(current_dir, '..') |
systems = options.systems.split(',') |
+ num_html_systems = ('htmlfrog' in systems) + ('htmldartium' in systems) |
+ if num_html_systems > 0 and num_html_systems < len(systems): |
+ print 'Cannot generate html and dom bindings at the same time' |
+ sys.exit(-1) |
+ |
+ use_database_cache = options.use_database_cache |
+ generate_html_systems = ('htmlfrog' in systems) or ('htmldartium' in systems) |
+ output_dir = options.output_dir or ( |
+ os.path.join(current_dir, '../../html') if generate_html_systems else |
+ os.path.join(current_dir, '..')) |
logging.config.fileConfig(os.path.join(current_dir, 'logging.conf')) |
- GenerateDOM(systems, output_dir) |
- # Copy Frog DOM to frog/dom_frog.dart. |
- if 'frog' in systems: |
- _logger.info('Copy dom_frog to frog/') |
- subprocess.call(['cd .. ; ../tools/copy_dart.py frog dom_frog.dart'], |
- shell=True); |
+ GenerateDOM(systems, generate_html_systems, output_dir, use_database_cache) |
# Copy dummy DOM where dartc build expects it. |
if 'dummy' in systems: |