Chromium Code Reviews| Index: third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt.py |
| diff --git a/third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt.py b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..829d269d50d5e821a974e559c842f9ef39c36d4d |
| --- /dev/null |
| +++ b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt.py |
| @@ -0,0 +1,88 @@ |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import logging |
| + |
| + |
| +WPT_REPO_URL = 'https://chromium.googlesource.com/external/w3c/web-platform-tests.git' |
| +WPT_TMP_DIR = '/tmp/wpt' |
| +CR_WPT_DIR = 'third_party/WebKit/LayoutTests/imported/wpt/' |
| +_log = logging.getLogger(__name__) |
| + |
| + |
| +class LocalWPT(object): |
| + |
| + def __init__(self, host, path=WPT_TMP_DIR, no_fetch=False, gh=False): |
|
qyearsley
2016/11/04 17:40:32
A docstring or different argument names might make
|
| + self.host = host |
| + self.path = path |
| + |
| + if no_fetch: |
| + _log.info('Skipping remote WPT fetch') |
| + else: |
| + if self.host.filesystem.exists(self.path): |
| + _log.info('WPT checkout exists at %s, fetching latest', self.path) |
| + self.run(['git', 'checkout', 'master']) |
| + self.run(['git', 'fetch', '--all']) |
| + self.run(['git', 'merge', '--ff-only', 'origin/master']) |
| + else: |
| + _log.info('Cloning %s into %s', WPT_REPO_URL, self.path) |
| + self.host.executive.run_command(['git', 'clone', WPT_REPO_URL, self.path]) |
| + |
| + if gh and 'github' not in self.run(['git', 'remote']): |
| + raise Exception('Need to set up remote "github"') |
|
qyearsley
2016/11/04 17:40:32
Possible minor restructuring: if you add a return
|
| + |
| + def run(self, command, **kwargs): |
| + """Runs a command in the local WPT directory.""" |
| + return self.host.executive.run_command(command, cwd=self.path, **kwargs) |
| + |
| + def run_to_list(self, command, **kwargs): |
| + return self.run(command, **kwargs).splitlines() |
|
qyearsley
2016/11/04 17:40:32
Would it be simpler just to add a .splitlines() in
|
| + |
| + def most_recent_cr_commit(self): |
| + """Goes back in WPT commit history and gets the most recent commit |
| + that contains 'Cr-Commit-Position:' |
| + """ |
| + sha = self.run(['git', 'rev-list', 'HEAD', '-n', '1', '--grep=Cr-Commit-Position']) |
| + if not sha: |
| + return None, None |
| + |
| + sha = sha.strip() |
| + position = self.run(['git', 'footers', '--position', sha]) |
| + position = position.strip() |
| + assert position |
| + return sha, position |
| + |
| + def clean(self): |
| + self.run(['git', 'reset', '--hard', 'HEAD']) |
| + self.run(['git', 'clean', '-fdx']) |
| + self.run(['git', 'checkout', 'master']) |
| + |
| + def all_branches(self): |
| + return self.run_to_list(['git', 'branch', '-a']) |
| + |
| + def create_branch_with_patch(self, branch_name, message, patch): |
| + self.clean() |
| + all_branches = self.all_branches() |
| + remote_branch_name = 'remotes/github/%s' % branch_name |
| + |
| + if branch_name in all_branches: |
| + _log.info('Local branch %s already exists, deleting', branch_name) |
| + self.run(['git', 'branch', '-D', branch_name]) |
| + |
| + if remote_branch_name in all_branches: |
| + _log.info('Remote branch %s already exists, deleting', branch_name) |
| + # TODO(jeffcarp): Investigate what happens when remote branch exists |
| + self.run(['git', 'push', 'github', ':{}'.format(branch_name)]) |
| + |
| + _log.info('Creating local branch %s', branch_name) |
| + self.run(['git', 'checkout', '-b', branch_name]) |
| + |
| + # Remove Chromium WPT directory prefix |
| + patch = patch.replace(CR_WPT_DIR, '') |
| + |
| + # TODO(jeffcarp): Use git am -p<n> where n is len(CR_WPT_DIR.split(/')) |
| + # or something not off-by-one. |
| + self.run(['git', 'apply', '-'], input=patch) |
| + self.run(['git', 'commit', '-am', message]) |
| + self.run(['git', 'push', 'github', branch_name]) |