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

Side by Side Diff: Tools/Scripts/webkitpy/w3c/test_converter.py

Issue 22350002: Speed up test importing by doing all the regex matching in a single pass. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 4 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 | no next file » | 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/env python 1 #!/usr/bin/env python
2 2
3 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 3 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
4 # 4 #
5 # Redistribution and use in source and binary forms, with or without 5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions 6 # modification, are permitted provided that the following conditions
7 # are met: 7 # are met:
8 # 8 #
9 # 1. Redistributions of source code must retain the above 9 # 1. Redistributions of source code must retain the above
10 # copyright notice, this list of conditions and the following 10 # copyright notice, this list of conditions and the following
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 self._host = Host() 44 self._host = Host()
45 self._filesystem = self._host.filesystem 45 self._filesystem = self._host.filesystem
46 self._webkit_root = WebKitFinder(self._filesystem).webkit_base() 46 self._webkit_root = WebKitFinder(self._filesystem).webkit_base()
47 47
48 # These settings might vary between WebKit and Blink 48 # These settings might vary between WebKit and Blink
49 self._css_property_file = self.path_from_webkit_root('Source', 'core', ' css', 'CSSPropertyNames.in') 49 self._css_property_file = self.path_from_webkit_root('Source', 'core', ' css', 'CSSPropertyNames.in')
50 self._css_property_split_string = 'alias_for=' 50 self._css_property_split_string = 'alias_for='
51 51
52 self.prefixed_properties = self.read_webkit_prefixed_css_property_list() 52 self.prefixed_properties = self.read_webkit_prefixed_css_property_list()
53 53
54 prop_regex = '([\s{]|^)(' + "|".join(prop.replace('-webkit-', '') for pr op in self.prefixed_properties) + ')(\s+:|:)'
55 self.prop_re = re.compile(prop_regex)
56
54 def path_from_webkit_root(self, *comps): 57 def path_from_webkit_root(self, *comps):
55 return self._filesystem.abspath(self._filesystem.join(self._webkit_root, *comps)) 58 return self._filesystem.abspath(self._filesystem.join(self._webkit_root, *comps))
56 59
57 def read_webkit_prefixed_css_property_list(self): 60 def read_webkit_prefixed_css_property_list(self):
58 prefixed_properties = [] 61 prefixed_properties = []
59 unprefixed_properties = set() 62 unprefixed_properties = set()
60 63
61 contents = self._filesystem.read_text_file(self._css_property_file) 64 contents = self._filesystem.read_text_file(self._css_property_file)
62 for line in contents.splitlines(): 65 for line in contents.splitlines():
63 if re.match('^(#|//)', line): 66 if re.match('^(#|//)', line):
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 if not tag.contents: 153 if not tag.contents:
151 continue 154 continue
152 style_text = tag.contents[0] 155 style_text = tag.contents[0]
153 else: 156 else:
154 style_text = tag['style'] 157 style_text = tag['style']
155 158
156 updated_style_text = self.add_webkit_prefix_to_unprefixed_properties (style_text, filename) 159 updated_style_text = self.add_webkit_prefix_to_unprefixed_properties (style_text, filename)
157 160
158 # Rewrite tag only if changes were made. 161 # Rewrite tag only if changes were made.
159 if updated_style_text[0]: 162 if updated_style_text[0]:
160 converted_properties.extend(updated_style_text[0]) 163 converted_properties.extend(list(updated_style_text[0]))
161 164
162 new_tag = Tag(doc, tag.name, tag.attrs) 165 new_tag = Tag(doc, tag.name, tag.attrs)
163 new_tag.insert(0, updated_style_text[1]) 166 new_tag.insert(0, updated_style_text[1])
164 167
165 self.replace_tag(tag, new_tag) 168 self.replace_tag(tag, new_tag)
166 169
170 # FIXME: Doing the replace in the parsed document and then writing it ba ck out
171 # is normalizing the HTML, which may in fact alter the intent of some te sts.
172 # We should probably either just do basic string-replaces, or have some other
173 # way of flagging tests that are sensitive to being rewritten.
174 # https://bugs.webkit.org/show_bug.cgi?id=119159
175
167 return (converted_properties, doc.prettify()) 176 return (converted_properties, doc.prettify())
168 177
169 def add_webkit_prefix_to_unprefixed_properties(self, text, filename): 178 def add_webkit_prefix_to_unprefixed_properties(self, text, filename):
170 """ Searches |text| for instances of properties requiring the -webkit- p refix and adds the prefix to them. 179 """ Searches |text| for instances of properties requiring the -webkit- p refix and adds the prefix to them.
171 180
172 Returns the list of converted properties and the modified text.""" 181 Returns the list of converted properties and the modified text."""
173 182
174 converted_properties = [] 183 converted_properties = set()
184 text_chunks = []
185 cur_pos = 0
186 for m in self.prop_re.finditer(text):
187 text_chunks.extend([text[cur_pos:m.start()], m.group(1), '-webkit-', m.group(2), m.group(3)])
188 converted_properties.add(m.group(2))
189 cur_pos = m.end()
190 text_chunks.append(text[cur_pos:])
175 191
176 for raw_property in self.prefixed_properties: 192 for prop in converted_properties:
177 # FIXME: add in both the prefixed and unprefixed versions, rather th an just replacing them? 193 _log.info(' converting %s', prop)
178 # That might allow the imported test to work in other browsers more easily.
179
180 # Look for the various ways it might be in the CSS
181 # Match the the property preceded by either whitespace or left curly brace
182 # or at the beginning of the string (for inline style attribute)
183 pattern = '([\s{]|^)' + raw_property + '(\s+:|:)'
184 if re.search(pattern, text):
185 replacement_property = '-webkit-%s' % raw_property
186 _log.info('converting %s -> %s' % (raw_property, replacement_pro perty))
187 converted_properties.append(replacement_property)
188 text = re.sub(pattern, replacement_property + ':', text)
189 194
190 # FIXME: Handle the JS versions of these properties and GetComputedStyle , too. 195 # FIXME: Handle the JS versions of these properties and GetComputedStyle , too.
191 return (converted_properties, text) 196 return (converted_properties, text)
192 197
193 def replace_tag(self, old_tag, new_tag): 198 def replace_tag(self, old_tag, new_tag):
194 index = old_tag.parent.contents.index(old_tag) 199 index = old_tag.parent.contents.index(old_tag)
195 old_tag.parent.insert(index, new_tag) 200 old_tag.parent.insert(index, new_tag)
196 old_tag.extract() 201 old_tag.extract()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698