| 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..a48e69faf71d1eb866b81ed24c3a943a119931a0
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt.py
|
| @@ -0,0 +1,90 @@
|
| +# 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 re
|
| +
|
| +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/'
|
| +OLDEST_POSSIBLE_WPT_COMMIT = '2f10dbcf873d4f67c81a89f4ba84bfde514675b0'
|
| +
|
| +
|
| +class LocalWPT(object):
|
| +
|
| + def __init__(self, host, path=WPT_TMP_DIR, no_fetch=False):
|
| + self.host = host
|
| + self.fs = self.host.filesystem
|
| + self.path = path
|
| + self.run_command = self.host.executive.run_command
|
| +
|
| + if no_fetch:
|
| + self.host.print_('## Stop trying to make fetch happen, it\'s not going to happen')
|
| + else:
|
| + if self.fs.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.run_command(['git', 'clone', WPT_REPO_URL, self.path])
|
| + # TODO: need to set up remote github
|
| + self.host.print_('## Need to set up remote "github"!')
|
| +
|
| + def run(self, command, **kwargs):
|
| + """Runs a command in the local WPT directory."""
|
| + return self.run_command(command, cwd=self.path, **kwargs)
|
| +
|
| + def most_recent_cr_commit(self):
|
| + """Goes back in WPT commit history and gets the most recent commit
|
| + that contains 'Cr-Commit-Position:'
|
| + """
|
| + rev = '%s..HEAD' % OLDEST_POSSIBLE_WPT_COMMIT
|
| + shas = filter(bool, self.run(['git', 'rev-list', rev]).split('\n'))
|
| +
|
| + for sha in shas:
|
| + message = self.run(['git', 'show', '-s', '--format=%B', sha])
|
| + if 'Cr-Commit-Position' in message:
|
| + match = re.match(r'Cr-Commit-Position: (?P<cr_commit>.+)$', message)
|
| + if not match:
|
| + return None, None
|
| + cr_commit = match.group('cr_commit')
|
| + if cr_commit:
|
| + return sha, cr_commit
|
| +
|
| + return None, None
|
| +
|
| + def clean(self):
|
| + self.run(['git', 'reset', '--hard', 'HEAD'])
|
| + self.run(['git', 'checkout', 'master'])
|
| +
|
| + def all_branches(self):
|
| + return [s.strip() for s in self.run(['git', 'branch', '-a']).split('\n')]
|
| +
|
| + 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])
|
| + # raise Exception('Local branch %s already exists' % 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])
|
| + # raise Exception('Remote branch %s already exists' % 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])
|
|
|