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..87249ebb93e395b89edf685d4ecbb779c21ee274 |
| --- /dev/null |
| +++ b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt.py |
| @@ -0,0 +1,81 @@ |
| +# 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. |
| + |
| +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/' |
| + |
| + |
| +class LocalWPT(object): |
| + |
| + def __init__(self, host, path=WPT_TMP_DIR, no_fetch=False): |
| + self.host = host |
| + self.path = path |
| + |
| + if no_fetch: |
| + self.host.print_('## Skipping remote WPT fetch') |
| + else: |
| + if self.host.filesystem.exists(self.path): |
| + self.host.print_('## 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: |
| + self.host.print_('## Cloning %s into %s' % (WPT_REPO_URL, self.path)) |
| + self.host.executive.run_command(['git', 'clone', WPT_REPO_URL, self.path]) |
| + self.host.print_('## Need to set up remote "github"!') |
| + |
| + 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() |
| + |
| + 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]) |
|
foolip
2016/11/02 13:15:33
Sweet!
|
| + assert position |
|
foolip
2016/11/02 13:15:33
Put the assert after the strip, because I guess we
jeffcarp
2016/11/03 22:33:00
The reason it was before strip was to catch the ca
|
| + position = position.strip() |
| + 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: |
| + self.host.print_('## Local branch %s already exists, deleting' % branch_name) |
| + self.run(['git', 'branch', '-D', branch_name]) |
| + |
| + if remote_branch_name in all_branches: |
| + self.host.print_('## Remote branch %s already exists, deleting' % branch_name) |
| + self.run(['git', 'push', 'github', ':%s' % branch_name]) |
| + |
| + self.host.print_('## Creating local branch %s' % branch_name) |
| + self.run(['git', 'checkout', '-b', branch_name]) |
| + |
| + # Remove Chromium WPT directory prefix |
| + patch = patch.replace(CR_WPT_DIR, '') |
| + |
| + # foolip: Could also 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]) |