193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#
393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# Redistribution and use in source and binary forms, with or without
493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# modification, are permitted provided that the following conditions
593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# are met:
693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#
793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# 1. Redistributions of source code must retain the above
893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#    copyright notice, this list of conditions and the following
993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#    disclaimer.
1093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# 2. Redistributions in binary form must reproduce the above
1193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#    copyright notice, this list of conditions and the following
1293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#    disclaimer in the documentation and/or other materials
1393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#    provided with the distribution.
1493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#
1593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
1693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
1993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
2093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
2493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
2593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# SUCH DAMAGE.
2793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
2893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)"""
2909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) This script imports a directory of W3C tests into WebKit.
3093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
3193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) This script will import the tests into WebKit following these rules:
3293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
3309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    - By default, all tests are imported under LayoutTests/w3c/[repo-name].
3493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
3509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    - By default, only reftests and jstest are imported. This can be overridden
3609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)      with a -a or --all argument
3793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
3809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    - Also by default, if test files by the same name already exist in the
3909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)      destination directory, they are overwritten with the idea that running
4009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)      this script would refresh files periodically.  This can also be
4109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)      overridden by a -n or --no-overwrite flag
4293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
4393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    - All files are converted to work in WebKit:
44197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch         1. Paths to testharness.js and vendor-prefix.js files are modified to
45197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch            point to Webkit's copy of them in LayoutTests/resources, using the
46197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch            correct relative path from the new location.
4709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)         2. All CSS properties requiring the -webkit-vendor prefix are prefixed
4809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            (the list of what needs prefixes is read from Source/WebCore/CSS/CSSProperties.in).
4909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)         3. Each reftest has its own copy of its reference file following
5009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            the naming conventions new-run-webkit-tests expects.
5109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)         4. If a reference files lives outside the directory of the test that
5209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            uses it, it is checked for paths to support files as it will be
5309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            imported into a different relative position to the test file
5409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            (in the same directory).
55197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch         5. Any tags with the class "instructions" have style="display:none" added
56197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch            to them. Some w3c tests contain instructions to manual testers which we
57197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch            want to strip out (the test result parser only recognizes pure testharness.js
58197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch            output and not those instructions).
5909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
6009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)     - Upon completion, script outputs the total number tests imported, broken
6109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)       down by test type
6209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
6309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)     - Also upon completion, if we are not importing the files in place, each
6409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)       directory where files are imported will have a w3c-import.log file written with
6509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)       a timestamp, the W3C Mercurial changeset if available, the list of CSS
6609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)       properties used that require prefixes, the list of imported files, and
6709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)       guidance for future test modification and maintenance. On subsequent
6809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)       imports, this file is read to determine if files have been
6909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)       removed in the newer changesets.  The script removes these files
7009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)       accordingly.
7193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)"""
7293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
7393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)# FIXME: Change this file to use the Host abstractions rather that os, sys, shutils, etc.
7493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
7593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)import datetime
7693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)import logging
7793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)import mimetypes
7893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)import optparse
7993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)import os
8093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)import shutil
8193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)import sys
8293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
8393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)from webkitpy.common.host import Host
845267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)from webkitpy.common.webkit_finder import WebKitFinder
8593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)from webkitpy.common.system.executive import ScriptError
8609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)from webkitpy.layout_tests.models.test_expectations import TestExpectationParser
8793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)from webkitpy.w3c.test_parser import TestParser
8806f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)from webkitpy.w3c.test_converter import convert_for_webkit
8993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
9093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
9193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)CHANGESET_NOT_AVAILABLE = 'Not Available'
9293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
9393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
9493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)_log = logging.getLogger(__name__)
9593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
9693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
9793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)def main(_argv, _stdout, _stderr):
9893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    options, args = parse_args()
9909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    dir_to_import = os.path.normpath(os.path.abspath(args[0]))
10093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    if len(args) == 1:
10109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        top_of_repo = dir_to_import
10293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    else:
10309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        top_of_repo = os.path.normpath(os.path.abspath(args[1]))
10493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
10509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if not os.path.exists(dir_to_import):
10609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        sys.exit('Directory %s not found!' % dir_to_import)
10709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if not os.path.exists(top_of_repo):
10809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        sys.exit('Repository directory %s not found!' % top_of_repo)
10909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if top_of_repo not in dir_to_import:
11009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        sys.exit('Repository directory %s must be a parent of %s' % (top_of_repo, dir_to_import))
11193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
11293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    configure_logging()
11309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    test_importer = TestImporter(Host(), dir_to_import, top_of_repo, options)
11493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    test_importer.do_import()
11593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
11693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
11793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)def configure_logging():
11893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    class LogHandler(logging.StreamHandler):
11993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
12093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        def format(self, record):
12193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            if record.levelno > logging.INFO:
12293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                return "%s: %s" % (record.levelname, record.getMessage())
12393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            return record.getMessage()
12493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
12593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    logger = logging.getLogger()
12693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    logger.setLevel(logging.INFO)
12793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    handler = LogHandler()
12893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    handler.setLevel(logging.INFO)
12993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    logger.addHandler(handler)
13093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    return handler
13193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
13293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
13393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)def parse_args():
13409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    parser = optparse.OptionParser(usage='usage: %prog [options] [dir_to_import] [top_of_repo]')
13593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    parser.add_option('-n', '--no-overwrite', dest='overwrite', action='store_false', default=True,
13609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        help='Flag to prevent duplicate test files from overwriting existing tests. By default, they will be overwritten.')
13793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    parser.add_option('-a', '--all', action='store_true', default=False,
13809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        help='Import all tests including reftests, JS tests, and manual/pixel tests. By default, only reftests and JS tests are imported.')
139f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles)    parser.add_option('-d', '--dest-dir', dest='destination', default='w3c',
14009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        help='Import into a specified directory relative to the LayoutTests root. By default, files are imported under LayoutTests/w3c.')
14109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    parser.add_option('--ignore-expectations', action='store_true', default=False,
14209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        help='Ignore the W3CImportExpectations file and import everything.')
14309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    parser.add_option('--dry-run', action='store_true', default=False,
14409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        help='Dryrun only (don\'t actually write any results).')
14593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
14693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    options, args = parser.parse_args()
14709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if len(args) > 2:
14893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        parser.error('Incorrect number of arguments')
14909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    elif len(args) == 0:
15009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        args = (os.getcwd(),)
15193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    return options, args
15293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
15393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
15493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)class TestImporter(object):
15593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
15609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    def __init__(self, host, dir_to_import, top_of_repo, options):
15793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        self.host = host
15809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        self.dir_to_import = dir_to_import
15909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        self.top_of_repo = top_of_repo
16093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        self.options = options
16193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
16293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        self.filesystem = self.host.filesystem
16309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        self.webkit_finder = WebKitFinder(self.filesystem)
16409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        self._webkit_root = self.webkit_finder.webkit_base()
16509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        self.layout_tests_dir = self.webkit_finder.path_from_webkit_base('LayoutTests')
16609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        self.destination_directory = self.filesystem.normpath(self.filesystem.join(self.layout_tests_dir, options.destination,
16709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                                                                                   self.filesystem.basename(self.top_of_repo)))
16809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        self.import_in_place = (self.dir_to_import == self.destination_directory)
1697242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        self.dir_above_repo = self.filesystem.dirname(self.top_of_repo)
17093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
17193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        self.changeset = CHANGESET_NOT_AVAILABLE
17293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
17393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        self.import_list = []
17493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
17593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    def do_import(self):
17609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        _log.info("Importing %s into %s", self.dir_to_import, self.destination_directory)
17709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        self.find_importable_tests(self.dir_to_import)
17893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        self.load_changeset()
17993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        self.import_tests()
18093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
18193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    def load_changeset(self):
18293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        """Returns the current changeset from mercurial or "Not Available"."""
18393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        try:
18493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            self.changeset = self.host.executive.run_command(['hg', 'tip']).split('changeset:')[1]
18593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        except (OSError, ScriptError):
18693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            self.changeset = CHANGESET_NOT_AVAILABLE
18793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
18893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    def find_importable_tests(self, directory):
18993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        # FIXME: use filesystem
19009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        paths_to_skip = self.find_paths_to_skip()
19109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
19293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        for root, dirs, files in os.walk(directory):
1937242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci            cur_dir = root.replace(self.dir_above_repo + '/', '') + '/'
194d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)            _log.info('  scanning ' + cur_dir + '...')
19593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            total_tests = 0
19693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            reftests = 0
19793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            jstests = 0
19893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
199e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)            DIRS_TO_SKIP = ('.git', '.hg')
20009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            if dirs:
20109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                for d in DIRS_TO_SKIP:
20209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                    if d in dirs:
20309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                        dirs.remove(d)
20409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
20509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                for path in paths_to_skip:
2067242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci                    path_base = path.replace(self.options.destination + '/', '')
2077242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci                    path_base = path_base.replace(cur_dir, '')
20809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                    path_full = self.filesystem.join(root, path_base)
20909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                    if path_base in dirs:
21009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                        dirs.remove(path_base)
21109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                        if not self.options.dry_run and self.import_in_place:
212d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                            _log.info("  pruning %s" % path_base)
21309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                            self.filesystem.rmtree(path_full)
2147242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci                        else:
2157242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci                            _log.info("  skipping %s" % path_base)
2167242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
21793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
21893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            copy_list = []
21993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
22093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            for filename in files:
22109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                path_full = self.filesystem.join(root, filename)
22209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                path_base = path_full.replace(self.layout_tests_dir + '/', '')
22309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                if path_base in paths_to_skip:
22409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                    if not self.options.dry_run and self.import_in_place:
225d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)                        _log.info("  pruning %s" % path_base)
22609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                        self.filesystem.remove(path_full)
22709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                        continue
2287242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci                    else:
2297242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci                        continue
23093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                # FIXME: This block should really be a separate function, but the early-continues make that difficult.
23193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
23293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                if filename.startswith('.') or filename.endswith('.pl'):
23393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    continue  # For some reason the w3c repo contains random perl scripts we don't care about.
23493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
23593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                fullpath = os.path.join(root, filename)
23693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
23793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                mimetype = mimetypes.guess_type(fullpath)
2387242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci                if not 'html' in str(mimetype[0]) and not 'application/xhtml+xml' in str(mimetype[0]) and not 'application/xml' in str(mimetype[0]):
23993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    copy_list.append({'src': fullpath, 'dest': filename})
24093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    continue
24193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
24209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                if root.endswith('resources'):
24309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                    copy_list.append({'src': fullpath, 'dest': filename})
24409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                    continue
24509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
24693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                test_parser = TestParser(vars(self.options), filename=fullpath)
24793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                test_info = test_parser.analyze_test()
24893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                if test_info is None:
24993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    continue
25093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
25193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                if 'reference' in test_info.keys():
25293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    reftests += 1
25393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    total_tests += 1
25493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    test_basename = os.path.basename(test_info['test'])
25593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
25693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    # Add the ref file, following WebKit style.
25793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    # FIXME: Ideally we'd support reading the metadata
25893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    # directly rather than relying  on a naming convention.
25993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    # Using a naming convention creates duplicate copies of the
26093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    # reference files.
26193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    ref_file = os.path.splitext(test_basename)[0] + '-expected'
26293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    ref_file += os.path.splitext(test_basename)[1]
26393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
26493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    copy_list.append({'src': test_info['reference'], 'dest': ref_file})
26593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    copy_list.append({'src': test_info['test'], 'dest': filename})
26693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
26793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    # Update any support files that need to move as well to remain relative to the -expected file.
26893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    if 'refsupport' in test_info.keys():
26993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                        for support_file in test_info['refsupport']:
27093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                            source_file = os.path.join(os.path.dirname(test_info['reference']), support_file)
27193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                            source_file = os.path.normpath(source_file)
27293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
27393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                            # Keep the dest as it was
27493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                            to_copy = {'src': source_file, 'dest': support_file}
27593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
27693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                            # Only add it once
27793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                            if not(to_copy in copy_list):
27893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                                copy_list.append(to_copy)
27993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                elif 'jstest' in test_info.keys():
28093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    jstests += 1
28193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    total_tests += 1
28293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    copy_list.append({'src': fullpath, 'dest': filename})
28393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                else:
28493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    total_tests += 1
28593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    copy_list.append({'src': fullpath, 'dest': filename})
28693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
28793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            if not total_tests:
28893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                # We can skip the support directory if no tests were found.
28993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                if 'support' in dirs:
29093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    dirs.remove('support')
29193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
29293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            if copy_list:
29393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                # Only add this directory to the list if there's something to import
29493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                self.import_list.append({'dirname': root, 'copy_list': copy_list,
29593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    'reftests': reftests, 'jstests': jstests, 'total_tests': total_tests})
29693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
29709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    def find_paths_to_skip(self):
29809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if self.options.ignore_expectations:
29909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            return set()
30009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
30109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        paths_to_skip = set()
30209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        port = self.host.port_factory.get()
30309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        w3c_import_expectations_path = self.webkit_finder.path_from_webkit_base('LayoutTests', 'W3CImportExpectations')
30409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        w3c_import_expectations = self.filesystem.read_text_file(w3c_import_expectations_path)
30509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        parser = TestExpectationParser(port, full_test_list=(), is_lint_mode=False)
30609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        expectation_lines = parser.parse(w3c_import_expectations_path, w3c_import_expectations)
30709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        for line in expectation_lines:
30809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            if 'SKIP' in line.expectations:
30909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                if line.specifiers:
31009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                    _log.warning("W3CImportExpectations:%s should not have any specifiers" % line.line_numbers)
31109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                    continue
31209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                paths_to_skip.add(line.name)
31309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return paths_to_skip
31409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
31593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    def import_tests(self):
31693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        total_imported_tests = 0
31793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        total_imported_reftests = 0
31893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        total_imported_jstests = 0
31993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        total_prefixed_properties = {}
32093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
32193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        for dir_to_copy in self.import_list:
32293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            total_imported_tests += dir_to_copy['total_tests']
32393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            total_imported_reftests += dir_to_copy['reftests']
32493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            total_imported_jstests += dir_to_copy['jstests']
32593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
32693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            prefixed_properties = []
32793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
32893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            if not dir_to_copy['copy_list']:
32993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                continue
33093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
33193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            orig_path = dir_to_copy['dirname']
33293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
33309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            subpath = os.path.relpath(orig_path, self.top_of_repo)
33493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            new_path = os.path.join(self.destination_directory, subpath)
33593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
33693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            if not(os.path.exists(new_path)):
33793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                os.makedirs(new_path)
33893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
33993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            copied_files = []
34093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
34193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            for file_to_copy in dir_to_copy['copy_list']:
34293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                # FIXME: Split this block into a separate function.
34393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                orig_filepath = os.path.normpath(file_to_copy['src'])
34493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
34593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                if os.path.isdir(orig_filepath):
34693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    # FIXME: Figure out what is triggering this and what to do about it.
34793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    _log.error('%s refers to a directory' % orig_filepath)
34893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    continue
34993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
35093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                if not(os.path.exists(orig_filepath)):
35193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    _log.warning('%s not found. Possible error in the test.', orig_filepath)
35293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    continue
35393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
35493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                new_filepath = os.path.join(new_path, file_to_copy['dest'])
35593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
35693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                if not(os.path.exists(os.path.dirname(new_filepath))):
35709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                    if not self.import_in_place and not self.options.dry_run:
35809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                        os.makedirs(os.path.dirname(new_filepath))
35993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
3607242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci                relpath = os.path.relpath(new_filepath, self.layout_tests_dir)
36193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                if not self.options.overwrite and os.path.exists(new_filepath):
3627242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci                    _log.info('  skipping %s' % relpath)
36393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                else:
36493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    # FIXME: Maybe doing a file diff is in order here for existing files?
36593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    # In other words, there's no sense in overwriting identical files, but
36693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    # there's no harm in copying the identical thing.
3677242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci                    _log.info('  %s' % relpath)
36893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
36993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                # Only html, xml, or css should be converted
37093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                # FIXME: Eventually, so should js when support is added for this type of conversion
37193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                mimetype = mimetypes.guess_type(orig_filepath)
37293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                if 'html' in str(mimetype[0]) or 'xml' in str(mimetype[0])  or 'css' in str(mimetype[0]):
37306f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)                    converted_file = convert_for_webkit(new_path, filename=orig_filepath)
37493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
37593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    if not converted_file:
37609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                        if not self.import_in_place and not self.options.dry_run:
37709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                            shutil.copyfile(orig_filepath, new_filepath)  # The file was unmodified.
37893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                    else:
37993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                        for prefixed_property in converted_file[0]:
38093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                            total_prefixed_properties.setdefault(prefixed_property, 0)
38193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                            total_prefixed_properties[prefixed_property] += 1
38293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
38393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                        prefixed_properties.extend(set(converted_file[0]) - set(prefixed_properties))
38409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                        if not self.options.dry_run:
38509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                            outfile = open(new_filepath, 'wb')
38609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                            outfile.write(converted_file[1])
38709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                            outfile.close()
38893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                else:
38909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                    if not self.import_in_place and not self.options.dry_run:
39009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)                        shutil.copyfile(orig_filepath, new_filepath)
39193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
39293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)                copied_files.append(new_filepath.replace(self._webkit_root, ''))
39393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
394d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        _log.info('')
39593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        _log.info('Import complete')
396d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        _log.info('')
39793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        _log.info('IMPORTED %d TOTAL TESTS', total_imported_tests)
39893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        _log.info('Imported %d reftests', total_imported_reftests)
39993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        _log.info('Imported %d JS tests', total_imported_jstests)
40093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        _log.info('Imported %d pixel/manual tests', total_imported_tests - total_imported_jstests - total_imported_reftests)
40193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        _log.info('')
4027242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci
4037242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci        if total_prefixed_properties:
4047242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci            _log.info('Properties needing prefixes (by count):')
4057242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci            for prefixed_property in sorted(total_prefixed_properties, key=lambda p: total_prefixed_properties[p]):
4067242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci                _log.info('  %s: %s', prefixed_property, total_prefixed_properties[prefixed_property])
40793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
40893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    def setup_destination_directory(self):
409e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)        """ Creates a destination directory that mirrors that of the source directory """
41093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
41109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        new_subpath = self.dir_to_import[len(self.top_of_repo):]
41293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
41393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        destination_directory = os.path.join(self.destination_directory, new_subpath)
41493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
41593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        if not os.path.exists(destination_directory):
41693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)            os.makedirs(destination_directory)
41793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
41893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)        _log.info('Tests will be imported into: %s', destination_directory)
419