| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 """A utility class for interacting with a local checkout of the Web Platform Tes
ts.""" | 5 """A utility class for interacting with a local checkout of the Web Platform Tes
ts.""" |
| 6 | 6 |
| 7 import logging | 7 import logging |
| 8 | 8 |
| 9 from webkitpy.common.system.executive import ScriptError | 9 from webkitpy.common.system.executive import ScriptError |
| 10 from webkitpy.w3c.chromium_commit import ChromiumCommit | 10 from webkitpy.w3c.chromium_commit import ChromiumCommit |
| 11 | 11 |
| 12 WPT_REPO_URL = 'https://chromium.googlesource.com/external/w3c/web-platform-test
s.git' | 12 WPT_REPO_URL = 'https://chromium.googlesource.com/external/w3c/web-platform-test
s.git' |
| 13 WPT_TMP_DIR = '/tmp/wpt' | 13 WPT_TMP_DIR = '/tmp/wpt' |
| 14 WPT_SSH_URL = 'git@github.com:w3c/web-platform-tests.git' |
| 15 REMOTE_NAME = 'github' |
| 14 CHROMIUM_WPT_DIR = 'third_party/WebKit/LayoutTests/imported/wpt/' | 16 CHROMIUM_WPT_DIR = 'third_party/WebKit/LayoutTests/imported/wpt/' |
| 15 | 17 |
| 16 _log = logging.getLogger(__name__) | 18 _log = logging.getLogger(__name__) |
| 17 | 19 |
| 18 | 20 |
| 19 class LocalWPT(object): | 21 class LocalWPT(object): |
| 20 | 22 |
| 21 def __init__(self, host, path=WPT_TMP_DIR, no_fetch=False, use_github=False)
: | 23 def __init__(self, host, path=WPT_TMP_DIR, no_fetch=False): |
| 22 """ | 24 """ |
| 23 Args: | 25 Args: |
| 24 host: A Host object. | 26 host: A Host object. |
| 25 path: Optional, the directory where LocalWPT will check out web-plat
form-tests. | 27 path: Optional, the directory where LocalWPT will check out web-plat
form-tests. |
| 26 no_fetch: Optional, passing true will skip updating the local WPT. | 28 no_fetch: Optional, passing true will skip updating the local WPT. |
| 27 Intended for use only in development after fetching once. | 29 Intended for use only in development after fetching once. |
| 28 use_github: Optional, passing true will check if the GitHub remote i
s enabled | |
| 29 (necessary for later pull request steps). | |
| 30 """ | 30 """ |
| 31 self.host = host | 31 self.host = host |
| 32 self.path = path | 32 self.path = path |
| 33 self.branch_name = 'chromium-export-try' | 33 self.branch_name = 'chromium-export-try' |
| 34 | 34 |
| 35 if no_fetch: | 35 if no_fetch: |
| 36 _log.info('Skipping remote WPT fetch') | 36 _log.info('Skipping remote WPT fetch') |
| 37 return | 37 return |
| 38 | 38 |
| 39 if self.host.filesystem.exists(self.path): | 39 if self.host.filesystem.exists(self.path): |
| 40 _log.info('WPT checkout exists at %s, fetching latest', self.path) | 40 _log.info('WPT checkout exists at %s, fetching latest', self.path) |
| 41 self.run(['git', 'fetch', '--all']) | 41 self.run(['git', 'fetch', '--all']) |
| 42 self.run(['git', 'checkout', 'origin/master']) | 42 self.run(['git', 'checkout', 'origin/master']) |
| 43 else: | 43 else: |
| 44 _log.info('Cloning %s into %s', WPT_REPO_URL, self.path) | 44 _log.info('Cloning %s into %s', WPT_REPO_URL, self.path) |
| 45 self.host.executive.run_command(['git', 'clone', WPT_REPO_URL, self.
path]) | 45 self.host.executive.run_command(['git', 'clone', WPT_REPO_URL, self.
path]) |
| 46 | 46 |
| 47 if use_github and 'github' not in self.run(['git', 'remote']): | 47 if REMOTE_NAME not in self.run(['git', 'remote']): |
| 48 raise Exception('Need to set up remote "github"') | 48 self.run(['git', 'remote', 'add', REMOTE_NAME, WPT_SSH_URL]) |
| 49 | 49 |
| 50 def run(self, command, **kwargs): | 50 def run(self, command, **kwargs): |
| 51 """Runs a command in the local WPT directory.""" | 51 """Runs a command in the local WPT directory.""" |
| 52 return self.host.executive.run_command(command, cwd=self.path, **kwargs) | 52 return self.host.executive.run_command(command, cwd=self.path, **kwargs) |
| 53 | 53 |
| 54 def most_recent_chromium_commit(self): | 54 def most_recent_chromium_commit(self): |
| 55 """Finds the most recent commit in WPT with a Chromium commit position."
"" | 55 """Finds the most recent commit in WPT with a Chromium commit position."
"" |
| 56 sha = self.run(['git', 'rev-list', 'HEAD', '-n', '1', '--grep=Cr-Commit-
Position']) | 56 sha = self.run(['git', 'rev-list', 'HEAD', '-n', '1', '--grep=Cr-Commit-
Position']) |
| 57 if not sha: | 57 if not sha: |
| 58 return None, None | 58 return None, None |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 _log.info('Creating local branch %s', self.branch_name) | 93 _log.info('Creating local branch %s', self.branch_name) |
| 94 self.run(['git', 'checkout', '-b', self.branch_name]) | 94 self.run(['git', 'checkout', '-b', self.branch_name]) |
| 95 | 95 |
| 96 # Remove Chromium WPT directory prefix. | 96 # Remove Chromium WPT directory prefix. |
| 97 patch = patch.replace(CHROMIUM_WPT_DIR, '') | 97 patch = patch.replace(CHROMIUM_WPT_DIR, '') |
| 98 | 98 |
| 99 # TODO(jeffcarp): Use git am -p<n> where n is len(CHROMIUM_WPT_DIR.split
(/')) | 99 # TODO(jeffcarp): Use git am -p<n> where n is len(CHROMIUM_WPT_DIR.split
(/')) |
| 100 # or something not off-by-one. | 100 # or something not off-by-one. |
| 101 self.run(['git', 'apply', '-'], input=patch) | 101 self.run(['git', 'apply', '-'], input=patch) |
| 102 self.run(['git', 'commit', '--author', author, '-am', message]) | 102 self.run(['git', 'commit', '--author', author, '-am', message]) |
| 103 self.run(['git', 'push', 'github', self.branch_name]) | 103 self.run(['git', 'push', REMOTE_NAME, self.branch_name]) |
| 104 | 104 |
| 105 return self.branch_name | 105 return self.branch_name |
| 106 | 106 |
| 107 def test_patch(self, patch): | 107 def test_patch(self, patch): |
| 108 """Returns the expected output of a patch against origin/master. | 108 """Returns the expected output of a patch against origin/master. |
| 109 | 109 |
| 110 Args: | 110 Args: |
| 111 patch: The patch to test against. | 111 patch: The patch to test against. |
| 112 | 112 |
| 113 Returns: | 113 Returns: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 131 | 131 |
| 132 def commits_behind_master(self, commit): | 132 def commits_behind_master(self, commit): |
| 133 """Returns the number of commits after the given commit on origin/master
. | 133 """Returns the number of commits after the given commit on origin/master
. |
| 134 | 134 |
| 135 This doesn't include the given commit, and this assumes that the given | 135 This doesn't include the given commit, and this assumes that the given |
| 136 commit is on the the master branch. | 136 commit is on the the master branch. |
| 137 """ | 137 """ |
| 138 return len(self.run([ | 138 return len(self.run([ |
| 139 'git', 'rev-list', '{}..origin/master'.format(commit) | 139 'git', 'rev-list', '{}..origin/master'.format(commit) |
| 140 ]).splitlines()) | 140 ]).splitlines()) |
| OLD | NEW |