| 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 from webkitpy.w3c.common import WPT_REPO_URL, CHROMIUM_WPT_DIR | 11 from webkitpy.w3c.common import WPT_GH_REPO_URL, CHROMIUM_WPT_DIR |
| 12 | 12 |
| 13 | 13 |
| 14 WPT_SSH_URL = 'git@github.com:w3c/web-platform-tests.git' | |
| 15 REMOTE_NAME = 'github' | |
| 16 | |
| 17 _log = logging.getLogger(__name__) | 14 _log = logging.getLogger(__name__) |
| 18 | 15 |
| 19 | 16 |
| 20 class LocalWPT(object): | 17 class LocalWPT(object): |
| 21 | 18 |
| 22 def __init__(self, host, path='/tmp/wpt'): | 19 def __init__(self, host, path='/tmp/wpt'): |
| 23 """ | 20 """ |
| 24 Args: | 21 Args: |
| 25 host: A Host object. | 22 host: A Host object. |
| 26 path: Optional, the path to the web-platform-tests repo. | 23 path: Optional, the path to the web-platform-tests repo. |
| 27 If this directory already exists, it is assumed that the | 24 If this directory already exists, it is assumed that the |
| 28 web-platform-tests repo is already checked out at this path. | 25 web-platform-tests repo is already checked out at this path. |
| 29 """ | 26 """ |
| 30 self.host = host | 27 self.host = host |
| 31 self.path = path | 28 self.path = path |
| 32 self.branch_name = 'chromium-export-try' | 29 self.branch_name = 'chromium-export-try' |
| 33 | 30 |
| 34 def fetch(self): | 31 def fetch(self): |
| 35 if self.host.filesystem.exists(self.path): | 32 if self.host.filesystem.exists(self.path): |
| 36 _log.info('WPT checkout exists at %s, fetching latest', self.path) | 33 _log.info('WPT checkout exists at %s, fetching latest', self.path) |
| 37 self.run(['git', 'fetch', '--all']) | 34 self.run(['git', 'fetch', 'origin']) |
| 38 self.run(['git', 'checkout', 'origin/master']) | 35 self.run(['git', 'checkout', 'origin/master']) |
| 39 else: | 36 else: |
| 40 _log.info('Cloning %s into %s', WPT_REPO_URL, self.path) | 37 _log.info('Cloning %s into %s', WPT_GH_REPO_URL, self.path) |
| 41 self.host.executive.run_command(['git', 'clone', WPT_REPO_URL, self.
path]) | 38 self.host.executive.run_command(['git', 'clone', WPT_GH_REPO_URL, se
lf.path]) |
| 42 | |
| 43 if REMOTE_NAME not in self.run(['git', 'remote']): | |
| 44 self.run(['git', 'remote', 'add', REMOTE_NAME, WPT_SSH_URL]) | |
| 45 | 39 |
| 46 def run(self, command, **kwargs): | 40 def run(self, command, **kwargs): |
| 47 """Runs a command in the local WPT directory.""" | 41 """Runs a command in the local WPT directory.""" |
| 48 return self.host.executive.run_command(command, cwd=self.path, **kwargs) | 42 return self.host.executive.run_command(command, cwd=self.path, **kwargs) |
| 49 | 43 |
| 50 def most_recent_chromium_commit(self): | 44 def most_recent_chromium_commit(self): |
| 51 """Finds the most recent commit in WPT with a Chromium commit position."
"" | 45 """Finds the most recent commit in WPT with a Chromium commit position."
"" |
| 52 wpt_commit_hash = self.run(['git', 'rev-list', 'HEAD', '-n', '1', '--gre
p=Cr-Commit-Position']) | 46 wpt_commit_hash = self.run(['git', 'rev-list', 'HEAD', '-n', '1', '--gre
p=Cr-Commit-Position']) |
| 53 if not wpt_commit_hash: | 47 if not wpt_commit_hash: |
| 54 return None, None | 48 return None, None |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 self.run(['git', 'checkout', '-b', self.branch_name]) | 84 self.run(['git', 'checkout', '-b', self.branch_name]) |
| 91 | 85 |
| 92 # Remove Chromium WPT directory prefix. | 86 # Remove Chromium WPT directory prefix. |
| 93 patch = patch.replace(CHROMIUM_WPT_DIR, '') | 87 patch = patch.replace(CHROMIUM_WPT_DIR, '') |
| 94 | 88 |
| 95 # TODO(jeffcarp): Use git am -p<n> where n is len(CHROMIUM_WPT_DIR.split
(/')) | 89 # TODO(jeffcarp): Use git am -p<n> where n is len(CHROMIUM_WPT_DIR.split
(/')) |
| 96 # or something not off-by-one. | 90 # or something not off-by-one. |
| 97 self.run(['git', 'apply', '-'], input=patch) | 91 self.run(['git', 'apply', '-'], input=patch) |
| 98 self.run(['git', 'add', '.']) | 92 self.run(['git', 'add', '.']) |
| 99 self.run(['git', 'commit', '--author', author, '-am', message]) | 93 self.run(['git', 'commit', '--author', author, '-am', message]) |
| 100 self.run(['git', 'push', '-f', REMOTE_NAME, self.branch_name]) | 94 self.run(['git', 'push', '-f', 'origin', self.branch_name]) |
| 101 | 95 |
| 102 return self.branch_name | 96 return self.branch_name |
| 103 | 97 |
| 104 def test_patch(self, patch, chromium_commit=None): | 98 def test_patch(self, patch, chromium_commit=None): |
| 105 """Returns the expected output of a patch against origin/master. | 99 """Returns the expected output of a patch against origin/master. |
| 106 | 100 |
| 107 Args: | 101 Args: |
| 108 patch: The patch to test against. | 102 patch: The patch to test against. |
| 109 | 103 |
| 110 Returns: | 104 Returns: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 131 | 125 |
| 132 def commits_behind_master(self, commit): | 126 def commits_behind_master(self, commit): |
| 133 """Returns the number of commits after the given commit on origin/master
. | 127 """Returns the number of commits after the given commit on origin/master
. |
| 134 | 128 |
| 135 This doesn't include the given commit, and this assumes that the given | 129 This doesn't include the given commit, and this assumes that the given |
| 136 commit is on the the master branch. | 130 commit is on the the master branch. |
| 137 """ | 131 """ |
| 138 return len(self.run([ | 132 return len(self.run([ |
| 139 'git', 'rev-list', '{}..origin/master'.format(commit) | 133 'git', 'rev-list', '{}..origin/master'.format(commit) |
| 140 ]).splitlines()) | 134 ]).splitlines()) |
| OLD | NEW |