Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 WPT_REPO_URL = 'https://chromium.googlesource.com/external/w3c/web-platform-test s.git' | |
| 6 WPT_TMP_DIR = '/tmp/wpt' | |
| 7 CR_WPT_DIR = 'third_party/WebKit/LayoutTests/imported/wpt/' | |
| 8 | |
| 9 | |
| 10 class LocalWPT(object): | |
| 11 | |
| 12 def __init__(self, host, path=WPT_TMP_DIR, no_fetch=False): | |
| 13 self.host = host | |
| 14 self.path = path | |
| 15 | |
| 16 if no_fetch: | |
| 17 self.host.print_('## Skipping remote WPT fetch') | |
| 18 else: | |
| 19 if self.host.filesystem.exists(self.path): | |
| 20 self.host.print_('## WPT checkout exists at %s, fetching latest' % (self.path)) | |
| 21 self.run(['git', 'checkout', 'master']) | |
| 22 self.run(['git', 'fetch', '--all']) | |
| 23 self.run(['git', 'merge', '--ff-only', 'origin/master']) | |
| 24 else: | |
| 25 self.host.print_('## Cloning %s into %s' % (WPT_REPO_URL, self.p ath)) | |
| 26 self.host.executive.run_command(['git', 'clone', WPT_REPO_URL, s elf.path]) | |
| 27 self.host.print_('## Need to set up remote "github"!') | |
| 28 | |
| 29 def run(self, command, **kwargs): | |
| 30 """Runs a command in the local WPT directory.""" | |
| 31 return self.host.executive.run_command(command, cwd=self.path, **kwargs) | |
| 32 | |
| 33 def run_to_list(self, command, **kwargs): | |
| 34 return self.run(command, **kwargs).splitlines() | |
| 35 | |
| 36 def most_recent_cr_commit(self): | |
| 37 """Goes back in WPT commit history and gets the most recent commit | |
| 38 that contains 'Cr-Commit-Position:' | |
| 39 """ | |
| 40 sha = self.run(['git', 'rev-list', 'HEAD', '-n', '1', '--grep=Cr-Commit- Position']) | |
| 41 if not sha: | |
| 42 return None, None | |
| 43 | |
| 44 sha = sha.strip() | |
| 45 position = self.run(['git', 'footers', '--position', sha]) | |
|
foolip
2016/11/02 13:15:33
Sweet!
| |
| 46 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
| |
| 47 position = position.strip() | |
| 48 return sha, position | |
| 49 | |
| 50 def clean(self): | |
| 51 self.run(['git', 'reset', '--hard', 'HEAD']) | |
| 52 self.run(['git', 'clean', '-fdx']) | |
| 53 self.run(['git', 'checkout', 'master']) | |
| 54 | |
| 55 def all_branches(self): | |
| 56 return self.run_to_list(['git', 'branch', '-a']) | |
| 57 | |
| 58 def create_branch_with_patch(self, branch_name, message, patch): | |
| 59 self.clean() | |
| 60 all_branches = self.all_branches() | |
| 61 remote_branch_name = 'remotes/github/%s' % branch_name | |
| 62 | |
| 63 if branch_name in all_branches: | |
| 64 self.host.print_('## Local branch %s already exists, deleting' % bra nch_name) | |
| 65 self.run(['git', 'branch', '-D', branch_name]) | |
| 66 | |
| 67 if remote_branch_name in all_branches: | |
| 68 self.host.print_('## Remote branch %s already exists, deleting' % br anch_name) | |
| 69 self.run(['git', 'push', 'github', ':%s' % branch_name]) | |
| 70 | |
| 71 self.host.print_('## Creating local branch %s' % branch_name) | |
| 72 self.run(['git', 'checkout', '-b', branch_name]) | |
| 73 | |
| 74 # Remove Chromium WPT directory prefix | |
| 75 patch = patch.replace(CR_WPT_DIR, '') | |
| 76 | |
| 77 # foolip: Could also use git am -p<n> where n is len(CR_WPT_DIR.split(/' )) | |
| 78 # or something not off-by-one. | |
| 79 self.run(['git', 'apply', '-'], input=patch) | |
| 80 self.run(['git', 'commit', '-am', message]) | |
| 81 self.run(['git', 'push', 'github', branch_name]) | |
| OLD | NEW |