| OLD | NEW |
| 1 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 1 # Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions | 4 # modification, are permitted provided that the following conditions |
| 5 # are met: | 5 # are met: |
| 6 # | 6 # |
| 7 # 1. Redistributions of source code must retain the above | 7 # 1. Redistributions of source code must retain the above |
| 8 # copyright notice, this list of conditions and the following | 8 # copyright notice, this list of conditions and the following |
| 9 # disclaimer. | 9 # disclaimer. |
| 10 # 2. Redistributions in binary form must reproduce the above | 10 # 2. Redistributions in binary form must reproduce the above |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 # SUCH DAMAGE. | 26 # SUCH DAMAGE. |
| 27 | 27 |
| 28 """Logic for converting and copying files from a W3C repo. | 28 """Logic for converting and copying files from a W3C repo. |
| 29 | 29 |
| 30 This module is responsible for modifying and copying a subset of the tests from | 30 This module is responsible for modifying and copying a subset of the tests from |
| 31 a local W3C repository source directory into a destination directory. | 31 a local W3C repository source directory into a destination directory. |
| 32 """ | 32 """ |
| 33 | 33 |
| 34 import logging | 34 import logging |
| 35 import mimetypes | 35 import mimetypes |
| 36 import re | |
| 37 | 36 |
| 38 from webkitpy.common.webkit_finder import WebKitFinder | 37 from webkitpy.common.webkit_finder import WebKitFinder |
| 39 from webkitpy.layout_tests.models.test_expectations import TestExpectationParser | 38 from webkitpy.layout_tests.models.test_expectations import TestExpectationParser |
| 40 from webkitpy.w3c.test_parser import TestParser | 39 from webkitpy.w3c.test_parser import TestParser |
| 41 from webkitpy.w3c.test_converter import convert_for_webkit | |
| 42 | 40 |
| 43 _log = logging.getLogger(__name__) | 41 _log = logging.getLogger(__name__) |
| 44 | 42 |
| 45 | 43 |
| 46 class TestCopier(object): | 44 class TestCopier(object): |
| 47 | 45 |
| 48 def __init__(self, host, source_repo_path, dest_dir_name='external'): | 46 def __init__(self, host, source_repo_path, dest_dir_name='external'): |
| 49 """Initializes variables to prepare for copying and converting files. | 47 """Initializes variables to prepare for copying and converting files. |
| 50 | 48 |
| 51 Args: | 49 Args: |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 dest_path = self.filesystem.join(dest_dir, file_to_copy['dest']) | 262 dest_path = self.filesystem.join(dest_dir, file_to_copy['dest']) |
| 265 | 263 |
| 266 if self.filesystem.isdir(source_path): | 264 if self.filesystem.isdir(source_path): |
| 267 _log.error('%s refers to a directory', source_path) | 265 _log.error('%s refers to a directory', source_path) |
| 268 return None | 266 return None |
| 269 | 267 |
| 270 if not self.filesystem.exists(source_path): | 268 if not self.filesystem.exists(source_path): |
| 271 _log.error('%s not found. Possible error in the test.', source_path) | 269 _log.error('%s not found. Possible error in the test.', source_path) |
| 272 return None | 270 return None |
| 273 | 271 |
| 274 reference_support_info = file_to_copy.get('reference_support_info') or N
one | |
| 275 | |
| 276 if not self.filesystem.exists(self.filesystem.dirname(dest_path)): | 272 if not self.filesystem.exists(self.filesystem.dirname(dest_path)): |
| 277 if not self.import_in_place: | 273 if not self.import_in_place: |
| 278 self.filesystem.maybe_make_directory(self.filesystem.dirname(des
t_path)) | 274 self.filesystem.maybe_make_directory(self.filesystem.dirname(des
t_path)) |
| 279 | 275 |
| 280 relpath = self.filesystem.relpath(dest_path, self.layout_tests_dir) | 276 relpath = self.filesystem.relpath(dest_path, self.layout_tests_dir) |
| 281 # FIXME: Maybe doing a file diff is in order here for existing files? | 277 # FIXME: Maybe doing a file diff is in order here for existing files? |
| 282 # In other words, there's no sense in overwriting identical files, but | 278 # In other words, there's no sense in overwriting identical files, but |
| 283 # there's no harm in copying the identical thing. | 279 # there's no harm in copying the identical thing. |
| 284 _log.debug(' copying %s', relpath) | 280 _log.debug(' copying %s', relpath) |
| 285 | 281 |
| 286 if self.should_try_to_convert(file_to_copy, source_path, dest_dir): | 282 if not self.import_in_place: |
| 287 converted_file = convert_for_webkit( | 283 self.filesystem.copyfile(source_path, dest_path) |
| 288 dest_dir, filename=source_path, | 284 if self.filesystem.read_binary_file(source_path)[:2] == '#!': |
| 289 reference_support_info=reference_support_info, | 285 self.filesystem.make_executable(dest_path) |
| 290 host=self.host) | |
| 291 for prefixed_property in converted_file[0]: | |
| 292 self._prefixed_properties.setdefault(prefixed_property, 0) | |
| 293 self._prefixed_properties[prefixed_property] += 1 | |
| 294 | |
| 295 self.filesystem.write_text_file(dest_path, converted_file[1]) | |
| 296 else: | |
| 297 if not self.import_in_place: | |
| 298 self.filesystem.copyfile(source_path, dest_path) | |
| 299 if self.filesystem.read_binary_file(source_path)[:2] == '#!': | |
| 300 self.filesystem.make_executable(dest_path) | |
| 301 | 286 |
| 302 return dest_path.replace(self._webkit_root, '') | 287 return dest_path.replace(self._webkit_root, '') |
| 303 | |
| 304 @staticmethod | |
| 305 def should_try_to_convert(file_to_copy, source_path, dest_dir): | |
| 306 """Checks whether we should try to modify the file when importing.""" | |
| 307 if file_to_copy.get('is_jstest', False): | |
| 308 return False | |
| 309 | |
| 310 # Conversion is not necessary for any tests in wpt now; see http://crbug
.com/654081. | |
| 311 # Note, we want to move away from converting files, see http://crbug.com
/663773. | |
| 312 if not re.search(r'[/\\]external[/\\]wpt[/\\]css[/\\]', dest_dir): | |
| 313 return False | |
| 314 | |
| 315 # Only HTML, XHTML and CSS files should be converted. | |
| 316 mimetype, _ = mimetypes.guess_type(source_path) | |
| 317 return mimetype in ('text/html', 'application/xhtml+xml', 'text/css') | |
| OLD | NEW |