Changeset 173498 in webkit


Ignore:
Timestamp:
Sep 10, 2014 5:01:47 PM (10 years ago)
Author:
commit-queue@webkit.org
Message:

import-w3c-tests doesn't handle relative paths to support files in ref files correctly
https://bugs.webkit.org/show_bug.cgi?id=135929

Patch by Rebecca Hauck <rhauck@adobe.com> on 2014-09-10
Reviewed by Bem Jones-Bey.

The recent refactor of the W3C test repo falsified a bunch of assmumptions that
were made when this script was originally written with respect to relative paths
in ref files. This patch updates import-w3c-tests to update paths in ref files if
they move relative to the test file.

  • Scripts/webkitpy/w3c/test_converter.py:

(convert_for_webkit):
(_W3CTestConverter.init):
(_W3CTestConverter.convert_reference_relpaths):
(_W3CTestConverter.convert_style_data):
(_W3CTestConverter.convert_attributes_if_needed):

  • Scripts/webkitpy/w3c/test_importer.py:

(TestImporter.find_importable_tests):
(TestImporter.import_tests):

  • Scripts/webkitpy/w3c/test_parser.py:

(TestParser.load_file):
(TestParser.analyze_test):
(TestParser.support_files):

Location:
trunk/Tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r173456 r173498  
     12014-09-10  Rebecca Hauck  <rhauck@adobe.com>
     2
     3        import-w3c-tests doesn't handle relative paths to support files in ref files correctly
     4        https://bugs.webkit.org/show_bug.cgi?id=135929
     5
     6        Reviewed by Bem Jones-Bey.
     7
     8        The recent refactor of the W3C test repo falsified a bunch of assmumptions that
     9        were made when this script was originally written with respect to relative paths
     10        in ref files. This patch updates import-w3c-tests to update paths in ref files if
     11        they move relative to the test file.
     12
     13
     14        * Scripts/webkitpy/w3c/test_converter.py:
     15        (convert_for_webkit):
     16        (_W3CTestConverter.__init__):
     17        (_W3CTestConverter.convert_reference_relpaths):
     18        (_W3CTestConverter.convert_style_data):
     19        (_W3CTestConverter.convert_attributes_if_needed):
     20        * Scripts/webkitpy/w3c/test_importer.py:
     21        (TestImporter.find_importable_tests):
     22        (TestImporter.import_tests):
     23        * Scripts/webkitpy/w3c/test_parser.py:
     24        (TestParser.load_file):
     25        (TestParser.analyze_test):
     26        (TestParser.support_files):
     27
    1282014-09-10  Michael Catanzaro  <mcatanzaro@igalia.com>
    229
  • trunk/Tools/Scripts/webkitpy/w3c/test_converter.py

    r156074 r173498  
    3838
    3939
    40 def convert_for_webkit(new_path, filename, host=Host()):
     40def convert_for_webkit(new_path, filename, reference_support_info, host=Host()):
    4141    """ Converts a file's |contents| so it will function correctly in its |new_path| in Webkit.
    4242
    4343    Returns the list of modified properties and the modified text if the file was modifed, None otherwise."""
    4444    contents = host.filesystem.read_binary_file(filename)
    45     converter = _W3CTestConverter(new_path, filename, host)
     45    converter = _W3CTestConverter(new_path, filename, reference_support_info, host)
    4646    if filename.endswith('.css'):
    4747        return converter.add_webkit_prefix_to_unprefixed_properties(contents)
     
    5353
    5454class _W3CTestConverter(HTMLParser):
    55     def __init__(self, new_path, filename, host=Host()):
     55    def __init__(self, new_path, filename, reference_support_info, host=Host()):
    5656        HTMLParser.__init__(self)
    5757
     
    6565        self.style_data = []
    6666        self.filename = filename
     67        self.reference_support_info = reference_support_info
    6768
    6869        resources_path = self.path_from_webkit_root('LayoutTests', 'resources')
     
    127128        return (converted_properties, ''.join(text_chunks))
    128129
     130    def convert_reference_relpaths(self, text):
     131        """ Searches |text| for instances of files in reference_support_info and updates the relative path to be correct for the new ref file location"""
     132        converted = text
     133        for path in self.reference_support_info['files']:
     134            if text.find(path) != -1:
     135                # FIXME: This doesn't handle an edge case where simply removing the relative path doesn't work.
     136                # See http://webkit.org/b/135677 for details.
     137                new_path = re.sub(self.reference_support_info['reference_relpath'], '', path, 1)
     138                converted = re.sub(path, new_path, text)
     139
     140        return converted
     141
    129142    def convert_style_data(self, data):
    130143        converted = self.add_webkit_prefix_to_unprefixed_properties(data)
    131144        if converted[0]:
    132145            self.converted_properties.extend(list(converted[0]))
    133         return converted[1]
     146
     147        if self.reference_support_info is None or self.reference_support_info == {}:
     148            return converted[1]
     149
     150        return self.convert_reference_relpaths(converted[1])
    134151
    135152    def convert_attributes_if_needed(self, tag, attrs):
     
    149166                converted = re.sub(attr[1], new_style, converted)
    150167
     168        src_tags = ('script', 'img', 'frame', 'iframe', 'input', 'layer', 'textarea', 'video', 'audio')
     169        if tag in src_tags and self.reference_support_info is not None and  self.reference_support_info != {}:
     170            for attr_name, attr_value in attrs:
     171                if attr_name == 'src':
     172                    converted = self.convert_reference_relpaths(attr_value)
     173
    151174        self.converted_data.append(converted)
    152175
  • trunk/Tools/Scripts/webkitpy/w3c/test_importer.py

    r172803 r173498  
    208208                    ref_file += os.path.splitext(test_basename)[1]
    209209
    210                     copy_list.append({'src': test_info['reference'], 'dest': ref_file})
     210                    copy_list.append({'src': test_info['reference'], 'dest': ref_file, 'reference_support_info': test_info['reference_support_info']})
    211211                    copy_list.append({'src': test_info['test'], 'dest': filename})
    212212
    213                     # Update any support files that need to move as well to remain relative to the -expected file.
    214                     if 'refsupport' in test_info.keys():
    215                         for support_file in test_info['refsupport']:
    216                             source_file = os.path.join(os.path.dirname(test_info['reference']), support_file)
    217                             source_file = os.path.normpath(source_file)
    218 
    219                             # Keep the dest as it was
    220                             to_copy = {'src': source_file, 'dest': support_file}
    221 
    222                             # Only add it once
    223                             if not(to_copy in copy_list):
    224                                 copy_list.append(to_copy)
    225213                elif 'jstest' in test_info.keys():
    226214                    jstests += 1
     
    231219                    copy_list.append({'src': fullpath, 'dest': filename})
    232220
    233             if not total_tests:
    234                 # We can skip the support directory if no tests were found.
    235                 if 'support' in dirs:
    236                     dirs.remove('support')
    237 
    238221            if copy_list:
    239222                # Only add this directory to the list if there's something to import
     
    283266
    284267                new_filepath = os.path.join(new_path, file_to_copy['dest'])
     268                if 'reference_support_info' in file_to_copy.keys() and file_to_copy['reference_support_info'] != {}:
     269                    reference_support_info = file_to_copy['reference_support_info']
     270                else:
     271                    reference_support_info = None
    285272
    286273                if not(os.path.exists(os.path.dirname(new_filepath))):
     
    301288                if 'html' in str(mimetype[0]) or 'xml' in str(mimetype[0])  or 'css' in str(mimetype[0]):
    302289                    try:
    303                         converted_file = convert_for_webkit(new_path, filename=orig_filepath)
     290                        converted_file = convert_for_webkit(new_path, filename=orig_filepath, reference_support_info=reference_support_info)
    304291                    except:
    305292                        _log.warn('Failed converting %s', orig_filepath)
    306293                        failed_conversion_files.append(orig_filepath)
     294                        converted_file = None
    307295
    308296                    if not converted_file:
  • trunk/Tools/Scripts/webkitpy/w3c/test_parser.py

    r152133 r173498  
    5050        self.load_file(filename)
    5151
    52     def load_file(self, filename):
     52    def load_file(self, filename, is_ref=False):
    5353        if self.filesystem.isfile(filename):
    5454            try:
    55                 self.test_doc = Parser(self.filesystem.read_binary_file(filename))
     55                doc = Parser(self.filesystem.read_binary_file(filename))
    5656            except:
    5757                # FIXME: Figure out what to do if we can't parse the file.
    5858                _log.error("Failed to parse %s", filename)
    59                 self.test_doc is None
     59                doc = None
    6060        else:
    6161            if self.filesystem.isdir(filename):
    6262                # FIXME: Figure out what is triggering this and what to do about it.
    6363                _log.error("Trying to load %s, which is a directory", filename)
    64             self.test_doc = None
    65         self.ref_doc = None
     64            doc = None
     65
     66        if is_ref:
     67            self.ref_doc = doc
     68        else:
     69            self.test_doc = doc
    6670
    6771    def analyze_test(self, test_contents=None, ref_contents=None):
     
    7074        test_info = None
    7175
    72         if test_contents is None and self.test_doc is None:
    73             return test_info
    74 
    75         if test_contents is not None:
    76             self.test_doc = Parser(test_contents)
    77 
    78         if ref_contents is not None:
    79             self.ref_doc = Parser(ref_contents)
    80 
    8176        # First check if it's a reftest
    82 
    8377        matches = self.reference_links_of_type('match') + self.reference_links_of_type('mismatch')
    8478        if matches:
     
    9690
    9791            if self.ref_doc is None:
    98                 self.ref_doc = self.load_file(ref_file)
     92                self.load_file(ref_file, True)
    9993
    10094            test_info = {'test': self.filename, 'reference': ref_file}
    10195
    102             # If the ref file path is relative, we need to check it for
    103             # relative paths also because when it lands in WebKit, it will be
    104             # moved down into the test dir.
    105             #
    106             # Note: The test files themselves are not checked for support files
    107             # outside their directories as the convention in the CSSWG is to
    108             # put all support files in the same dir or subdir as the test.
    109             #
    110             # All non-test files in the test's directory tree are normally
    111             # copied as part of the import as they are assumed to be required
    112             # support files.
    113             #
    114             # *But*, there is exactly one case in the entire css2.1 suite where
    115             # a test depends on a file that lives in a different directory,
    116             # which depends on another file that lives outside of its
    117             # directory. This code covers that case :)
    118             if matches[0]['href'].startswith('..'):
    119                 support_files = self.support_files(self.ref_doc)
    120                 test_info['refsupport'] = support_files
     96            # If the ref file does not live in the same directory as the test file, check it for support files
     97            test_info['reference_support_info'] = {}
     98            if self.filesystem.dirname(ref_file) != self.filesystem.dirname(self.filename):
     99                reference_support_files = self.support_files(self.ref_doc)
     100                if len(reference_support_files) > 0:
     101                    reference_relpath = self.filesystem.relpath(self.filesystem.dirname(self.filename), self.filesystem.dirname(ref_file)) + self.filesystem.sep
     102                    test_info['reference_support_info'] = {'reference_relpath': reference_relpath, 'files': reference_support_files}
    121103
    122104        elif self.is_jstest():
     
    157139        paths = src_paths + href_paths + urls
    158140        for path in paths:
    159             if not(path.startswith('http:')) and not(path.startswith('mailto:')):
     141            uri_scheme_pattern = re.compile(r"[A-Za-z][A-Za-z+.-]*:")
     142            if uri_scheme_pattern.match(path):
    160143                support_files.append(path)
    161144
Note: See TracChangeset for help on using the changeset viewer.