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

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

Issue 2655183002: In WPT importer, abort if there are exportable-but-not-yet-exported commits. (Closed)
Patch Set: Rebased Created 3 years, 11 months 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 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Fetches a copy of the latest state of a W3C test repository and commits. 5 """Fetches a copy of the latest state of a W3C test repository and commits.
6 6
7 If this script is given the argument --auto-update, it will also: 7 If this script is given the argument --auto-update, it will also:
8 1. Upload a CL. 8 1. Upload a CL.
9 2. Trigger try jobs and wait for them to complete. 9 2. Trigger try jobs and wait for them to complete.
10 3. Make any changes that are required for new failing tests. 10 3. Make any changes that are required for new failing tests.
11 4. Commit the CL. 11 4. Commit the CL.
12 12
13 If this script is given the argument --auto-update, it will also attempt to 13 If this script is given the argument --auto-update, it will also attempt to
14 upload a CL, trigger try jobs, and make any changes that are required for 14 upload a CL, trigger try jobs, and make any changes that are required for
15 new failing tests before committing. 15 new failing tests before committing.
16 """ 16 """
17 17
18 import argparse 18 import argparse
19 import json 19 import json
20 import logging 20 import logging
21 import re 21 import re
22 22
23 from webkitpy.common.net.git_cl import GitCL 23 from webkitpy.common.net.git_cl import GitCL
24 from webkitpy.common.webkit_finder import WebKitFinder 24 from webkitpy.common.webkit_finder import WebKitFinder
25 from webkitpy.layout_tests.models.test_expectations import TestExpectations, Tes tExpectationParser 25 from webkitpy.layout_tests.models.test_expectations import TestExpectations, Tes tExpectationParser
26 from webkitpy.w3c.common import WPT_REPO_URL, CSS_REPO_URL, WPT_DEST_NAME, CSS_D EST_NAME 26 from webkitpy.w3c.common import WPT_REPO_URL, CSS_REPO_URL, WPT_DEST_NAME, CSS_D EST_NAME, exportable_commits_since
27 from webkitpy.w3c.directory_owners_extractor import DirectoryOwnersExtractor 27 from webkitpy.w3c.directory_owners_extractor import DirectoryOwnersExtractor
28 from webkitpy.w3c.local_wpt import LocalWPT
28 from webkitpy.w3c.test_copier import TestCopier 29 from webkitpy.w3c.test_copier import TestCopier
29 from webkitpy.w3c.wpt_expectations_updater import WPTExpectationsUpdater 30 from webkitpy.w3c.wpt_expectations_updater import WPTExpectationsUpdater
30 31
31 # Settings for how often to check try job results and how long to wait. 32 # Settings for how often to check try job results and how long to wait.
32 POLL_DELAY_SECONDS = 2 * 60 33 POLL_DELAY_SECONDS = 2 * 60
33 TIMEOUT_SECONDS = 180 * 60 34 TIMEOUT_SECONDS = 180 * 60
34 35
35 _log = logging.getLogger(__file__) 36 _log = logging.getLogger(__file__)
36 37
37 38
(...skipping 15 matching lines...) Expand all
53 54
54 if not self.checkout_is_okay(options.allow_local_commits): 55 if not self.checkout_is_okay(options.allow_local_commits):
55 return 1 56 return 1
56 57
57 self.git_cl = GitCL(self.host, auth_refresh_token_json=options.auth_refr esh_token_json) 58 self.git_cl = GitCL(self.host, auth_refresh_token_json=options.auth_refr esh_token_json)
58 59
59 _log.info('Noting the current Chromium commit.') 60 _log.info('Noting the current Chromium commit.')
60 _, show_ref_output = self.run(['git', 'show-ref', 'HEAD']) 61 _, show_ref_output = self.run(['git', 'show-ref', 'HEAD'])
61 chromium_commit = show_ref_output.split()[0] 62 chromium_commit = show_ref_output.split()[0]
62 63
64 assert options.target in ('wpt', 'css')
65 dest_dir_name = WPT_DEST_NAME
66 repo_url = WPT_REPO_URL
67 if options.target != 'wpt':
68 dest_dir_name = CSS_DEST_NAME
69 repo_url = CSS_REPO_URL
70
71 # TODO(qyearsley): Simplify this to use LocalWPT.fetch when csswg-test
72 # is merged into web-platform-tests.
73 temp_repo_path = self.path_from_webkit_base(dest_dir_name)
74 _log.info('Cloning %s into %s.', repo_url, temp_repo_path)
75 self.run(['git', 'clone', repo_url, temp_repo_path])
76
63 if options.target == 'wpt': 77 if options.target == 'wpt':
64 import_commit = self.update(WPT_DEST_NAME, WPT_REPO_URL, options.kee p_w3c_repos_around, options.revision) 78 commits = self.exportable_but_not_exported_commits(temp_repo_path)
79 if commits:
80 _log.error('There were exportable but not-yet-exported commits: %r', commits)
81 _log.error('Aborting import to prevent clobbering these commits. ')
82 return 1
83
84 import_commit = self.update(dest_dir_name, temp_repo_path, options.keep_ w3c_repos_around, options.revision)
85
86 if options.target == 'wpt':
65 self._copy_resources() 87 self._copy_resources()
66 elif options.target == 'css':
67 import_commit = self.update(CSS_DEST_NAME, CSS_REPO_URL, options.kee p_w3c_repos_around, options.revision)
68 else:
69 raise AssertionError("Unsupported target %s" % options.target)
70 88
71 has_changes = self._has_changes() 89 has_changes = self._has_changes()
72 if not has_changes: 90 if not has_changes:
73 _log.info('Done: no changes to import.') 91 _log.info('Done: no changes to import.')
74 return 0 92 return 0
75 93
76 commit_message = self._commit_message(chromium_commit, import_commit) 94 commit_message = self._commit_message(chromium_commit, import_commit)
77 self._commit_changes(commit_message) 95 self._commit_changes(commit_message)
78 _log.info('Done: changes imported and committed.') 96 _log.info('Done: changes imported and committed.')
79 97
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 if self.fs.exists(self.path_from_webkit_base(WPT_DEST_NAME)): 134 if self.fs.exists(self.path_from_webkit_base(WPT_DEST_NAME)):
117 _log.warning('WebKit/%s exists; aborting.', WPT_DEST_NAME) 135 _log.warning('WebKit/%s exists; aborting.', WPT_DEST_NAME)
118 return False 136 return False
119 137
120 if self.fs.exists(self.path_from_webkit_base(CSS_DEST_NAME)): 138 if self.fs.exists(self.path_from_webkit_base(CSS_DEST_NAME)):
121 _log.warning('WebKit/%s repo exists; aborting.', CSS_DEST_NAME) 139 _log.warning('WebKit/%s repo exists; aborting.', CSS_DEST_NAME)
122 return False 140 return False
123 141
124 return True 142 return True
125 143
144 def exportable_but_not_exported_commits(self, wpt_path):
145 """Checks for commits that might be overwritten by importing.
146
147 Args:
148 wpt_path: The path to a local checkout of web-platform-tests.
149
150 Returns:
151 A list of commits in the Chromium repo that are exportable
152 but not yet exported to the web-platform-tests repo.
153 """
154 local_wpt = LocalWPT(self.host, path=wpt_path)
155 assert self.host.filesystem.exists(wpt_path)
156 _, chromium_commit = local_wpt.most_recent_chromium_commit()
157 return exportable_commits_since(chromium_commit.sha, self.host, local_wp t)
158
126 def _copy_resources(self): 159 def _copy_resources(self):
127 """Copies resources from wpt to LayoutTests/resources. 160 """Copies resources from wpt to LayoutTests/resources.
128 161
129 We copy idlharness.js and testharness.js in wpt to LayoutTests/resources 162 We copy idlharness.js and testharness.js in wpt to LayoutTests/resources
130 in order to use them in non-imported tests. 163 in order to use them in non-imported tests.
131 164
132 If this method is changed, the lists of files expected to be identical 165 If this method is changed, the lists of files expected to be identical
133 in LayoutTests/PRESUBMIT.py should also be changed. 166 in LayoutTests/PRESUBMIT.py should also be changed.
134 """ 167 """
135 resources_to_copy_from_wpt = [ 168 resources_to_copy_from_wpt = [
(...skipping 16 matching lines...) Expand all
152 stages the generated MANIFEST.json in the git index, ready to commit. 185 stages the generated MANIFEST.json in the git index, ready to commit.
153 """ 186 """
154 manifest_command = self.finder.path_from_webkit_base('Tools', 'Scripts', 'webkitpy', 'thirdparty', 'wpt', 'wpt', 'manifest') 187 manifest_command = self.finder.path_from_webkit_base('Tools', 'Scripts', 'webkitpy', 'thirdparty', 'wpt', 'wpt', 'manifest')
155 if 'css' in dest_path: 188 if 'css' in dest_path:
156 # Do nothing for csswg-test. 189 # Do nothing for csswg-test.
157 return 190 return
158 _log.info('Generating MANIFEST.json') 191 _log.info('Generating MANIFEST.json')
159 self.run([manifest_command, '--work', '--tests-root', dest_path]) 192 self.run([manifest_command, '--work', '--tests-root', dest_path])
160 self.run(['git', 'add', self.fs.join(dest_path, 'MANIFEST.json')]) 193 self.run(['git', 'add', self.fs.join(dest_path, 'MANIFEST.json')])
161 194
162 def update(self, dest_dir_name, url, keep_w3c_repos_around, revision): 195 def update(self, dest_dir_name, temp_repo_path, keep_w3c_repos_around, revis ion):
163 """Updates an imported repository. 196 """Updates an imported repository.
164 197
165 Args: 198 Args:
166 dest_dir_name: The destination directory name. 199 dest_dir_name: The destination directory name.
167 url: URL of the git repository. 200 temp_repo_path: Path to local checkout of W3C test repo.
168 revision: Commit hash or None. 201 keep_w3c_repos_around: If True, the temp directory won't be cleaned up.
202 revision: A W3C test repo commit hash, or None.
169 203
170 Returns: 204 Returns:
171 A string for the commit description "<destination>@<commitish>". 205 A string for the commit description "<destination>@<commitish>".
172 """ 206 """
173 temp_repo_path = self.path_from_webkit_base(dest_dir_name)
174 _log.info('Cloning %s into %s.', url, temp_repo_path)
175 self.run(['git', 'clone', url, temp_repo_path])
176
177 if revision is not None: 207 if revision is not None:
178 _log.info('Checking out %s', revision) 208 _log.info('Checking out %s', revision)
179 self.run(['git', 'checkout', revision], cwd=temp_repo_path) 209 self.run(['git', 'checkout', revision], cwd=temp_repo_path)
180 210
181 self.run(['git', 'submodule', 'update', '--init', '--recursive'], cwd=te mp_repo_path) 211 self.run(['git', 'submodule', 'update', '--init', '--recursive'], cwd=te mp_repo_path)
182 212
183 _log.info('Noting the revision we are importing.') 213 _log.info('Noting the revision we are importing.')
184 _, show_ref_output = self.run(['git', 'show-ref', 'origin/master'], cwd= temp_repo_path) 214 _, show_ref_output = self.run(['git', 'show-ref', 'origin/master'], cwd= temp_repo_path)
185 master_commitish = show_ref_output.split()[0] 215 master_commitish = show_ref_output.split()[0]
186 216
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 """Returns a dict mapping source to dest name for layout tests that have been renamed.""" 446 """Returns a dict mapping source to dest name for layout tests that have been renamed."""
417 out = self.check_run(['git', 'diff', 'origin/master', '-M100%', '--diff- filter=R', '--name-status']) 447 out = self.check_run(['git', 'diff', 'origin/master', '-M100%', '--diff- filter=R', '--name-status'])
418 renamed_tests = {} 448 renamed_tests = {}
419 for line in out.splitlines(): 449 for line in out.splitlines():
420 _, source_path, dest_path = line.split() 450 _, source_path, dest_path = line.split()
421 source_test = self.finder.layout_test_name(source_path) 451 source_test = self.finder.layout_test_name(source_path)
422 dest_test = self.finder.layout_test_name(dest_path) 452 dest_test = self.finder.layout_test_name(dest_path)
423 if source_test and dest_test: 453 if source_test and dest_test:
424 renamed_tests[source_test] = dest_test 454 renamed_tests[source_test] = dest_test
425 return renamed_tests 455 return renamed_tests
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698