| 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 18 matching lines...) Expand all Loading... |
| 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 | 36 |
| 37 from webkitpy.common.webkit_finder import WebKitFinder | 37 from webkitpy.common.webkit_finder import WebKitFinder |
| 38 from webkitpy.layout_tests.models.test_expectations import TestExpectationParser | 38 from webkitpy.layout_tests.models.test_expectations import TestExpectationParser |
| 39 from webkitpy.w3c.test_parser import TestParser | |
| 40 | 39 |
| 41 _log = logging.getLogger(__name__) | 40 _log = logging.getLogger(__name__) |
| 42 | 41 |
| 43 | 42 |
| 44 class TestCopier(object): | 43 class TestCopier(object): |
| 45 | 44 |
| 46 def __init__(self, host, source_repo_path, dest_dir_name='external'): | 45 def __init__(self, host, source_repo_path, dest_dir_name='external'): |
| 47 """Initializes variables to prepare for copying and converting files. | 46 """Initializes variables to prepare for copying and converting files. |
| 48 | 47 |
| 49 Args: | 48 Args: |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 """Walks through the source directory to find what tests should be impor
ted. | 85 """Walks through the source directory to find what tests should be impor
ted. |
| 87 | 86 |
| 88 This function sets self.import_list, which contains information about ho
w many | 87 This function sets self.import_list, which contains information about ho
w many |
| 89 tests are being imported, and their source and destination paths. | 88 tests are being imported, and their source and destination paths. |
| 90 """ | 89 """ |
| 91 paths_to_skip = self.find_paths_to_skip() | 90 paths_to_skip = self.find_paths_to_skip() |
| 92 | 91 |
| 93 for root, dirs, files in self.filesystem.walk(self.source_repo_path): | 92 for root, dirs, files in self.filesystem.walk(self.source_repo_path): |
| 94 cur_dir = root.replace(self.dir_above_repo + '/', '') + '/' | 93 cur_dir = root.replace(self.dir_above_repo + '/', '') + '/' |
| 95 _log.debug('Scanning %s...', cur_dir) | 94 _log.debug('Scanning %s...', cur_dir) |
| 96 total_tests = 0 | |
| 97 reftests = 0 | |
| 98 jstests = 0 | |
| 99 | 95 |
| 100 # Files in 'tools' are not for browser testing, so we skip them. | 96 # Files in 'tools' are not for browser testing, so we skip them. |
| 101 # See: http://web-platform-tests.org/writing-tests/general-guideline
s.html#tools | 97 # See: http://web-platform-tests.org/writing-tests/general-guideline
s.html#tools |
| 102 dirs_to_skip = ('.git', 'test-plan', 'tools') | 98 dirs_to_skip = ('.git', 'test-plan', 'tools') |
| 103 | 99 |
| 104 # We copy all files in 'support', including HTML without metadata. | |
| 105 # See: http://web-platform-tests.org/writing-tests/general-guideline
s.html#support-files | |
| 106 dirs_to_include = ('resources', 'support') | |
| 107 | |
| 108 if dirs: | 100 if dirs: |
| 109 for name in dirs_to_skip: | 101 for name in dirs_to_skip: |
| 110 if name in dirs: | 102 if name in dirs: |
| 111 dirs.remove(name) | 103 dirs.remove(name) |
| 112 | 104 |
| 113 for path in paths_to_skip: | 105 for path in paths_to_skip: |
| 114 path_base = path.replace(self.dest_dir_name + '/', '') | 106 path_base = path.replace(self.dest_dir_name + '/', '') |
| 115 path_base = path_base.replace(cur_dir, '') | 107 path_base = path_base.replace(cur_dir, '') |
| 116 path_full = self.filesystem.join(root, path_base) | 108 path_full = self.filesystem.join(root, path_base) |
| 117 if path_base in dirs: | 109 if path_base in dirs: |
| (...skipping 22 matching lines...) Expand all Loading... |
| 140 _log.debug('Skipping: %s', path_full) | 132 _log.debug('Skipping: %s', path_full) |
| 141 _log.debug(' Reason: Hidden files and perl scripts are not
necessary.') | 133 _log.debug(' Reason: Hidden files and perl scripts are not
necessary.') |
| 142 continue | 134 continue |
| 143 | 135 |
| 144 if filename == 'OWNERS' or filename == 'reftest.list': | 136 if filename == 'OWNERS' or filename == 'reftest.list': |
| 145 # See http://crbug.com/584660 and http://crbug.com/582838. | 137 # See http://crbug.com/584660 and http://crbug.com/582838. |
| 146 _log.debug('Skipping: %s', path_full) | 138 _log.debug('Skipping: %s', path_full) |
| 147 _log.debug(' Reason: This file may cause Chromium presubmit
to fail.') | 139 _log.debug(' Reason: This file may cause Chromium presubmit
to fail.') |
| 148 continue | 140 continue |
| 149 | 141 |
| 150 mimetype = mimetypes.guess_type(path_full) | 142 copy_list.append({'src': path_full, 'dest': filename}) |
| 151 if ('html' not in str(mimetype[0]) and | |
| 152 'application/xhtml+xml' not in str(mimetype[0]) and | |
| 153 'application/xml' not in str(mimetype[0])): | |
| 154 copy_list.append({'src': path_full, 'dest': filename}) | |
| 155 continue | |
| 156 | |
| 157 if self.filesystem.basename(root) in dirs_to_include: | |
| 158 copy_list.append({'src': path_full, 'dest': filename}) | |
| 159 continue | |
| 160 | |
| 161 test_parser = TestParser(path_full, self.host) | |
| 162 test_info = test_parser.analyze_test() | |
| 163 if test_info is None: | |
| 164 copy_list.append({'src': path_full, 'dest': filename}) | |
| 165 continue | |
| 166 | |
| 167 if 'reference' in test_info.keys(): | |
| 168 ref_path_full = test_info['reference'] | |
| 169 if not self.filesystem.exists(ref_path_full): | |
| 170 _log.warning('Skipping: %s', path_full) | |
| 171 _log.warning(' Reason: Ref file "%s" was not found.', r
ef_path_full) | |
| 172 continue | |
| 173 | |
| 174 reftests += 1 | |
| 175 total_tests += 1 | |
| 176 copy_list.append({'src': test_info['test'], 'dest': filename
}) | |
| 177 | |
| 178 elif 'jstest' in test_info.keys(): | |
| 179 jstests += 1 | |
| 180 total_tests += 1 | |
| 181 copy_list.append({'src': path_full, 'dest': filename, 'is_js
test': True}) | |
| 182 | 143 |
| 183 if copy_list: | 144 if copy_list: |
| 184 # Only add this directory to the list if there's something to im
port | 145 # Only add this directory to the list if there's something to im
port |
| 185 self.import_list.append({'dirname': root, 'copy_list': copy_list
, | 146 self.import_list.append({'dirname': root, 'copy_list': copy_list
}) |
| 186 'reftests': reftests, 'jstests': jstest
s, 'total_tests': total_tests}) | |
| 187 | 147 |
| 188 def find_paths_to_skip(self): | 148 def find_paths_to_skip(self): |
| 189 paths_to_skip = set() | 149 paths_to_skip = set() |
| 190 port = self.host.port_factory.get() | 150 port = self.host.port_factory.get() |
| 191 w3c_import_expectations_path = self.webkit_finder.path_from_webkit_base(
'LayoutTests', 'W3CImportExpectations') | 151 w3c_import_expectations_path = self.webkit_finder.path_from_webkit_base(
'LayoutTests', 'W3CImportExpectations') |
| 192 w3c_import_expectations = self.filesystem.read_text_file(w3c_import_expe
ctations_path) | 152 w3c_import_expectations = self.filesystem.read_text_file(w3c_import_expe
ctations_path) |
| 193 parser = TestExpectationParser(port, all_tests=(), is_lint_mode=False) | 153 parser = TestExpectationParser(port, all_tests=(), is_lint_mode=False) |
| 194 expectation_lines = parser.parse(w3c_import_expectations_path, w3c_impor
t_expectations) | 154 expectation_lines = parser.parse(w3c_import_expectations_path, w3c_impor
t_expectations) |
| 195 for line in expectation_lines: | 155 for line in expectation_lines: |
| 196 if 'SKIP' in line.expectations: | 156 if 'SKIP' in line.expectations: |
| 197 if line.specifiers: | 157 if line.specifiers: |
| 198 _log.warning('W3CImportExpectations:%s should not have any s
pecifiers', line.line_numbers) | 158 _log.warning('W3CImportExpectations:%s should not have any s
pecifiers', line.line_numbers) |
| 199 continue | 159 continue |
| 200 paths_to_skip.add(line.name) | 160 paths_to_skip.add(line.name) |
| 201 return paths_to_skip | 161 return paths_to_skip |
| 202 | 162 |
| 203 def import_tests(self): | 163 def import_tests(self): |
| 204 """Reads |self.import_list|, and converts and copies files to their dest
ination.""" | 164 """Reads |self.import_list|, and converts and copies files to their dest
ination.""" |
| 205 total_imported_tests = 0 | |
| 206 total_imported_reftests = 0 | |
| 207 total_imported_jstests = 0 | |
| 208 | |
| 209 for dir_to_copy in self.import_list: | 165 for dir_to_copy in self.import_list: |
| 210 total_imported_tests += dir_to_copy['total_tests'] | |
| 211 total_imported_reftests += dir_to_copy['reftests'] | |
| 212 total_imported_jstests += dir_to_copy['jstests'] | |
| 213 | |
| 214 if not dir_to_copy['copy_list']: | 166 if not dir_to_copy['copy_list']: |
| 215 continue | 167 continue |
| 216 | 168 |
| 217 orig_path = dir_to_copy['dirname'] | 169 orig_path = dir_to_copy['dirname'] |
| 218 | 170 |
| 219 relative_dir = self.filesystem.relpath(orig_path, self.source_repo_p
ath) | 171 relative_dir = self.filesystem.relpath(orig_path, self.source_repo_p
ath) |
| 220 dest_dir = self.filesystem.join(self.destination_directory, relative
_dir) | 172 dest_dir = self.filesystem.join(self.destination_directory, relative
_dir) |
| 221 | 173 |
| 222 if not self.filesystem.exists(dest_dir): | 174 if not self.filesystem.exists(dest_dir): |
| 223 self.filesystem.maybe_make_directory(dest_dir) | 175 self.filesystem.maybe_make_directory(dest_dir) |
| 224 | 176 |
| 225 copied_files = [] | 177 copied_files = [] |
| 226 | 178 |
| 227 for file_to_copy in dir_to_copy['copy_list']: | 179 for file_to_copy in dir_to_copy['copy_list']: |
| 228 copied_file = self.copy_file(file_to_copy, dest_dir) | 180 copied_file = self.copy_file(file_to_copy, dest_dir) |
| 229 if copied_file: | 181 if copied_file: |
| 230 copied_files.append(copied_file) | 182 copied_files.append(copied_file) |
| 231 | 183 |
| 232 _log.info('') | 184 _log.info('') |
| 233 _log.info('Import complete') | 185 _log.info('Import complete') |
| 234 _log.info('') | 186 _log.info('') |
| 235 _log.info('IMPORTED %d TOTAL TESTS', total_imported_tests) | |
| 236 _log.info('Imported %d reftests', total_imported_reftests) | |
| 237 _log.info('Imported %d JS tests', total_imported_jstests) | |
| 238 _log.info('Imported %d pixel/manual tests', total_imported_tests - total
_imported_jstests - total_imported_reftests) | |
| 239 _log.info('') | |
| 240 | 187 |
| 241 if self._prefixed_properties: | 188 if self._prefixed_properties: |
| 242 _log.info('Properties needing prefixes (by count):') | 189 _log.info('Properties needing prefixes (by count):') |
| 243 for prefixed_property in sorted(self._prefixed_properties, key=lambd
a p: self._prefixed_properties[p]): | 190 for prefixed_property in sorted(self._prefixed_properties, key=lambd
a p: self._prefixed_properties[p]): |
| 244 _log.info(' %s: %s', prefixed_property, self._prefixed_properti
es[prefixed_property]) | 191 _log.info(' %s: %s', prefixed_property, self._prefixed_properti
es[prefixed_property]) |
| 245 | 192 |
| 246 def copy_file(self, file_to_copy, dest_dir): | 193 def copy_file(self, file_to_copy, dest_dir): |
| 247 """Converts and copies a file, if it should be copied. | 194 """Converts and copies a file, if it should be copied. |
| 248 | 195 |
| 249 Args: | 196 Args: |
| (...skipping 28 matching lines...) Expand all Loading... |
| 278 # In other words, there's no sense in overwriting identical files, but | 225 # In other words, there's no sense in overwriting identical files, but |
| 279 # there's no harm in copying the identical thing. | 226 # there's no harm in copying the identical thing. |
| 280 _log.debug(' copying %s', relpath) | 227 _log.debug(' copying %s', relpath) |
| 281 | 228 |
| 282 if not self.import_in_place: | 229 if not self.import_in_place: |
| 283 self.filesystem.copyfile(source_path, dest_path) | 230 self.filesystem.copyfile(source_path, dest_path) |
| 284 if self.filesystem.read_binary_file(source_path)[:2] == '#!': | 231 if self.filesystem.read_binary_file(source_path)[:2] == '#!': |
| 285 self.filesystem.make_executable(dest_path) | 232 self.filesystem.make_executable(dest_path) |
| 286 | 233 |
| 287 return dest_path.replace(self._webkit_root, '') | 234 return dest_path.replace(self._webkit_root, '') |
| OLD | NEW |