REGRESSION (r236481): Move soft-linking of LocalAuthentication.framework out of Local...
[WebKit-https.git] / Tools / Scripts / import-webdriver-tests
1 #!/usr/bin/env python
2
3 # Copyright (C) 2017 Igalia S.L.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
8 #
9 # 1. Redistributions of source code must retain the above
10 #    copyright notice, this list of conditions and the following
11 #    disclaimer.
12 # 2. Redistributions in binary form must reproduce the above
13 #    copyright notice, this list of conditions and the following
14 #    disclaimer in the documentation and/or other materials
15 #    provided with the distribution.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
18 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22 # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
26 # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 # SUCH DAMAGE.
29
30 import json
31 import logging
32 import optparse
33 import os
34 import sys
35
36 from webkitpy.common.host import Host
37 from webkitpy.common.system.filesystem import FileSystem
38 from webkitpy.common.system.logutils import configure_logging
39 from webkitpy.common.webkit_finder import WebKitFinder
40 from webkitpy.common.checkout.scm.git import Git
41
42 _log = logging.getLogger(__name__)
43
44 host = Host()
45 host.initialize_scm()
46 webkit_finder = WebKitFinder(host.filesystem)
47
48 class Importer(object):
49
50     def __init__(self, config_path, download_path, destination_path):
51         self.config = json.loads(host.filesystem.read_text_file(config_path))
52         self.download_path = download_path
53         self.destination_path = destination_path
54
55     def download_tests(self):
56         host.filesystem.maybe_make_directory(host.filesystem.dirname(self.download_path))
57         needs_clone = not host.filesystem.exists(self.download_path)
58         if needs_clone:
59             _log.info('Cloning %s into %s...' % (self.config['repository'], self.download_path))
60             Git.clone(self.config['repository'], self.download_path, host.executive)
61         git = Git(self.download_path, None, executive=host.executive, filesystem=host.filesystem)
62         if not needs_clone:
63             _log.info('Fetching %s...' % self.config['repository'])
64             git.fetch()
65
66         _log.info('Checking out revision %s' % self.config['revision'])
67         git.checkout(self.config['revision'], False)
68
69     def import_tests(self):
70         def should_skip_file(source_path, full_paths_to_skip):
71             for path in full_paths_to_skip:
72                 if source_path.startswith(path):
73                     return True
74             return False
75
76         _log.info('Importing tests')
77         full_paths_to_skip = [host.filesystem.join(self.download_path, path) for path in self.config['paths_to_skip']]
78         for path in self.config['paths_to_import']:
79             source_directory = host.filesystem.join(self.download_path, path)
80             for source_path in host.filesystem.files_under(source_directory):
81                 if should_skip_file(source_path, full_paths_to_skip):
82                     continue
83                 destination_path = host.filesystem.join(self.destination_path, host.filesystem.relpath(source_path, self.download_path))
84                 host.filesystem.maybe_make_directory(host.filesystem.dirname(destination_path))
85                 host.filesystem.copyfile(source_path, destination_path)
86
87
88 option_parser = optparse.OptionParser(usage='usage: %prog [options]')
89 option_parser.add_option('--w3c', action='store_true', dest='w3c',
90                          help='Import W3C tests')
91 option_parser.add_option('--selenium', action='store_true', dest='selenium',
92                          help='Import Selenium tests')
93 options, _ = option_parser.parse_args()
94
95 # Not giving any option means import all.
96 if not options.w3c and not options.selenium:
97     options.w3c = options.selenium = True
98
99 configure_logging()
100
101 importers = []
102
103 if options.w3c:
104     importer_config_path = webkit_finder.path_from_webkit_base('WebDriverTests', 'imported', 'w3c', 'importer.json')
105     download_path = webkit_finder.path_from_webkit_base('WebKitBuild', 'w3c-tests', 'web-platform-tests')
106     import_path = webkit_finder.path_from_webkit_base('WebDriverTests', 'imported', 'w3c')
107     importers.append(Importer(importer_config_path, download_path, import_path))
108
109 if options.selenium:
110     importer_config_path = webkit_finder.path_from_webkit_base('WebDriverTests', 'imported', 'selenium', 'importer.json')
111     download_path = webkit_finder.path_from_webkit_base('WebKitBuild', 'selenium-tests', 'selenium')
112     import_path = webkit_finder.path_from_webkit_base('WebDriverTests', 'imported', 'selenium')
113     importers.append(Importer(importer_config_path, download_path, import_path))
114
115 for importer in importers:
116     importer.download_tests()
117     importer.import_tests()