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 import logging | |
| 6 | |
| 7 | |
| 8 WPT_REPO_URL = 'https://chromium.googlesource.com/external/w3c/web-platform-test s.git' | |
| 9 WPT_TMP_DIR = '/tmp/wpt' | |
| 10 CR_WPT_DIR = 'third_party/WebKit/LayoutTests/imported/wpt/' | |
| 11 _log = logging.getLogger(__name__) | |
| 12 | |
| 13 | |
| 14 class LocalWPT(object): | |
| 15 | |
| 16 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
| |
| 17 self.host = host | |
| 18 self.path = path | |
| 19 | |
| 20 if no_fetch: | |
| 21 _log.info('Skipping remote WPT fetch') | |
| 22 else: | |
| 23 if self.host.filesystem.exists(self.path): | |
| 24 _log.info('WPT checkout exists at %s, fetching latest', self.pat h) | |
| 25 self.run(['git', 'checkout', 'master']) | |
| 26 self.run(['git', 'fetch', '--all']) | |
| 27 self.run(['git', 'merge', '--ff-only', 'origin/master']) | |
| 28 else: | |
| 29 _log.info('Cloning %s into %s', WPT_REPO_URL, self.path) | |
| 30 self.host.executive.run_command(['git', 'clone', WPT_REPO_URL, s elf.path]) | |
| 31 | |
| 32 if gh and 'github' not in self.run(['git', 'remote']): | |
| 33 raise Exception('Need to set up remote "github"') | |
|
qyearsley
2016/11/04 17:40:32
Possible minor restructuring: if you add a return
| |
| 34 | |
| 35 def run(self, command, **kwargs): | |
| 36 """Runs a command in the local WPT directory.""" | |
| 37 return self.host.executive.run_command(command, cwd=self.path, **kwargs) | |
| 38 | |
| 39 def run_to_list(self, command, **kwargs): | |
| 40 return self.run(command, **kwargs).splitlines() | |
|
qyearsley
2016/11/04 17:40:32
Would it be simpler just to add a .splitlines() in
| |
| 41 | |
| 42 def most_recent_cr_commit(self): | |
| 43 """Goes back in WPT commit history and gets the most recent commit | |
| 44 that contains 'Cr-Commit-Position:' | |
| 45 """ | |
| 46 sha = self.run(['git', 'rev-list', 'HEAD', '-n', '1', '--grep=Cr-Commit- Position']) | |
| 47 if not sha: | |
| 48 return None, None | |
| 49 | |
| 50 sha = sha.strip() | |
| 51 position = self.run(['git', 'footers', '--position', sha]) | |
| 52 position = position.strip() | |
| 53 assert position | |
| 54 return sha, position | |
| 55 | |
| 56 def clean(self): | |
| 57 self.run(['git', 'reset', '--hard', 'HEAD']) | |
| 58 self.run(['git', 'clean', '-fdx']) | |
| 59 self.run(['git', 'checkout', 'master']) | |
| 60 | |
| 61 def all_branches(self): | |
| 62 return self.run_to_list(['git', 'branch', '-a']) | |
| 63 | |
| 64 def create_branch_with_patch(self, branch_name, message, patch): | |
| 65 self.clean() | |
| 66 all_branches = self.all_branches() | |
| 67 remote_branch_name = 'remotes/github/%s' % branch_name | |
| 68 | |
| 69 if branch_name in all_branches: | |
| 70 _log.info('Local branch %s already exists, deleting', branch_name) | |
| 71 self.run(['git', 'branch', '-D', branch_name]) | |
| 72 | |
| 73 if remote_branch_name in all_branches: | |
| 74 _log.info('Remote branch %s already exists, deleting', branch_name) | |
| 75 # TODO(jeffcarp): Investigate what happens when remote branch exists | |
| 76 self.run(['git', 'push', 'github', ':{}'.format(branch_name)]) | |
| 77 | |
| 78 _log.info('Creating local branch %s', branch_name) | |
| 79 self.run(['git', 'checkout', '-b', branch_name]) | |
| 80 | |
| 81 # Remove Chromium WPT directory prefix | |
| 82 patch = patch.replace(CR_WPT_DIR, '') | |
| 83 | |
| 84 # TODO(jeffcarp): Use git am -p<n> where n is len(CR_WPT_DIR.split(/')) | |
| 85 # or something not off-by-one. | |
| 86 self.run(['git', 'apply', '-'], input=patch) | |
| 87 self.run(['git', 'commit', '-am', message]) | |
| 88 self.run(['git', 'push', 'github', branch_name]) | |
| OLD | NEW |