#!/usr/bin/env python # Copyright (C) 2017 Igalia S.L. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above # copyright notice, this list of conditions and the following # disclaimer. # 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials # provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. import logging import json import os from webkitpy.common.host import Host from webkitpy.common.system.filesystem import FileSystem from webkitpy.common.system.logutils import configure_logging from webkitpy.common.webkit_finder import WebKitFinder from webkitpy.common.checkout.scm.git import Git from webkitpy.w3c.test_downloader import TestDownloader _log = logging.getLogger(__name__) def download_tests(host, url, revision, dest_directory): downloader = TestDownloader(None, host, TestDownloader.default_options()) downloader.checkout_test_repository(revision, url, dest_directory) downloader.git(dest_directory).checkout(revision, False) def should_skip_file(source_path, full_paths_to_skip): for path in full_paths_to_skip: if source_path.startswith(path): return True return False def import_tests(host, paths_to_import, paths_to_skip, src_directory, dest_directory): _log.info('Importing tests') full_paths_to_skip = [host.filesystem.join(src_directory, path) for path in paths_to_skip] for path in paths_to_import: source_directory = host.filesystem.join(src_directory, path) for source_path in host.filesystem.files_under(source_directory): if should_skip_file(source_path, full_paths_to_skip): continue destination_path = host.filesystem.join(dest_directory, host.filesystem.relpath(source_path, src_directory)) host.filesystem.maybe_make_directory(host.filesystem.dirname(destination_path)) host.filesystem.copyfile(source_path, destination_path) configure_logging() host = Host() host.initialize_scm() webkit_finder = WebKitFinder(host.filesystem) importer_config_path = webkit_finder.path_from_webkit_base('WebDriverTests', 'imported', 'w3c', 'importer.json') config = json.loads(host.filesystem.read_text_file(importer_config_path)) download_path = webkit_finder.path_from_webkit_base('WebKitBuild', 'w3c-tests', 'web-platform-tests') host.filesystem.maybe_make_directory(host.filesystem.dirname(download_path)) download_tests(host, config['repository'], config['revision'], download_path) import_path = webkit_finder.path_from_webkit_base('WebDriverTests', 'imported', 'w3c') import_tests(host, config['paths_to_import'], config['paths_to_skip'], download_path, import_path)