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

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/w3c/test_importer.py

Issue 2542963002: W3C Importer: Consolidate and simplify logic for deciding what not to convert. (Closed)
Patch Set: Rebase Created 4 years 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
OLDNEW
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 * Also upon completion, if we are not importing the files in place, each 59 * Also upon completion, if we are not importing the files in place, each
60 directory where files are imported will have a w3c-import.log file written wi th 60 directory where files are imported will have a w3c-import.log file written wi th
61 a timestamp, the list of CSS properties used that require prefixes, the list 61 a timestamp, the list of CSS properties used that require prefixes, the list
62 of imported files, and guidance for future test modification and maintenance. 62 of imported files, and guidance for future test modification and maintenance.
63 On subsequent imports, this file is read to determine if files have been 63 On subsequent imports, this file is read to determine if files have been
64 removed in the newer changesets. The script removes these files accordingly. 64 removed in the newer changesets. The script removes these files accordingly.
65 """ 65 """
66 66
67 import logging 67 import logging
68 import mimetypes 68 import mimetypes
69 import re
69 import optparse 70 import optparse
70 import os 71 import os
71 import sys 72 import sys
72 73
73 from webkitpy.common.host import Host 74 from webkitpy.common.host import Host
74 from webkitpy.common.webkit_finder import WebKitFinder 75 from webkitpy.common.webkit_finder import WebKitFinder
75 from webkitpy.layout_tests.models.test_expectations import TestExpectationParser 76 from webkitpy.layout_tests.models.test_expectations import TestExpectationParser
76 from webkitpy.w3c.test_parser import TestParser 77 from webkitpy.w3c.test_parser import TestParser
77 from webkitpy.w3c.test_converter import convert_for_webkit 78 from webkitpy.w3c.test_converter import convert_for_webkit
78 79
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 398
398 relpath = self.filesystem.relpath(dest_path, self.layout_tests_dir) 399 relpath = self.filesystem.relpath(dest_path, self.layout_tests_dir)
399 if not self.options.overwrite and self.filesystem.exists(dest_path): 400 if not self.options.overwrite and self.filesystem.exists(dest_path):
400 _log.info(' skipping %s', relpath) 401 _log.info(' skipping %s', relpath)
401 else: 402 else:
402 # FIXME: Maybe doing a file diff is in order here for existing files ? 403 # FIXME: Maybe doing a file diff is in order here for existing files ?
403 # In other words, there's no sense in overwriting identical files, b ut 404 # In other words, there's no sense in overwriting identical files, b ut
404 # there's no harm in copying the identical thing. 405 # there's no harm in copying the identical thing.
405 _log.info(' %s', relpath) 406 _log.info(' %s', relpath)
406 407
407 # Only HTML, XML, or CSS should be converted. 408 if self.should_try_to_convert(file_to_copy, source_path, dest_dir):
408 # FIXME: Eventually, so should JS when support is added for this type of conversion.
409 mimetype = mimetypes.guess_type(source_path)
410 if 'is_jstest' not in file_to_copy and (
411 'html' in str(mimetype[0]) or 'xml' in str(mimetype[0]) or 'css' in str(mimetype[0])):
412 converted_file = convert_for_webkit( 409 converted_file = convert_for_webkit(
413 dest_dir, filename=source_path, 410 dest_dir, filename=source_path,
414 reference_support_info=reference_support_info, 411 reference_support_info=reference_support_info,
415 host=self.host) 412 host=self.host)
413 for prefixed_property in converted_file[0]:
414 self._prefixed_properties.setdefault(prefixed_property, 0)
415 self._prefixed_properties[prefixed_property] += 1
416 416
417 if not converted_file: 417 if not self.options.dry_run:
418 if not self.import_in_place and not self.options.dry_run: 418 self.filesystem.write_text_file(dest_path, converted_file[1])
419 self.filesystem.copyfile(source_path, dest_path) # The file was unmodified.
420 else:
421 for prefixed_property in converted_file[0]:
422 self._prefixed_properties.setdefault(prefixed_property, 0)
423 self._prefixed_properties[prefixed_property] += 1
424
425 if not self.options.dry_run:
426 self.filesystem.write_text_file(dest_path, converted_file[1] )
427 else: 419 else:
428 if not self.import_in_place and not self.options.dry_run: 420 if not self.import_in_place and not self.options.dry_run:
429 self.filesystem.copyfile(source_path, dest_path) 421 self.filesystem.copyfile(source_path, dest_path)
430 if self.filesystem.read_binary_file(source_path)[:2] == '#!': 422 if self.filesystem.read_binary_file(source_path)[:2] == '#!':
431 self.filesystem.make_executable(dest_path) 423 self.filesystem.make_executable(dest_path)
432 424
433 return dest_path.replace(self._webkit_root, '') 425 return dest_path.replace(self._webkit_root, '')
434 426
427 @staticmethod
428 def should_try_to_convert(file_to_copy, source_path, dest_dir):
429 """Checks whether we should try to modify the file when importing."""
430 if file_to_copy.get('is_jstest', False):
431 return False
432
433 # Conversion is not necessary for any tests in wpt now; see http://crbug .com/654081.
434 # Note, we want to move away from converting files, see http://crbug.com /663773.
435 if re.search(r'[/\\]imported[/\\]wpt[/\\]', dest_dir):
436 return False
437
438 # Only HTML, XHTML and CSS files should be converted.
439 mimetype, _ = mimetypes.guess_type(source_path)
440 return mimetype in ('text/html', 'application/xhtml+xml', 'text/css')
441
435 def path_too_long(self, source_path): 442 def path_too_long(self, source_path):
436 """Checks whether a source path is too long to import. 443 """Checks whether a source path is too long to import.
437 444
438 Args: 445 Args:
439 Absolute path of file to be imported. 446 Absolute path of file to be imported.
440 447
441 Returns: 448 Returns:
442 True if the path is too long to import, False if it's OK. 449 True if the path is too long to import, False if it's OK.
443 """ 450 """
444 path_from_repo_base = os.path.relpath(source_path, self.source_repo_path ) 451 path_from_repo_base = os.path.relpath(source_path, self.source_repo_path )
445 return len(path_from_repo_base) > MAX_PATH_LENGTH 452 return len(path_from_repo_base) > MAX_PATH_LENGTH
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698