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 re | |
| 6 | |
| 7 WPT_REPO_URL = 'https://chromium.googlesource.com/external/w3c/web-platform-test s.git' | |
| 8 WPT_TMP_DIR = '/tmp/wpt' | |
| 9 CR_WPT_DIR = 'third_party/WebKit/LayoutTests/imported/wpt/' | |
| 10 | |
| 11 | |
| 12 class LocalWPT(object): | |
| 13 | |
| 14 def __init__(self, host, path=WPT_TMP_DIR, no_fetch=False): | |
| 15 self.host = host | |
| 16 self.fs = self.host.filesystem | |
| 17 self.path = path | |
| 18 self.run_command = self.host.executive.run_command | |
|
qyearsley
2016/11/01 22:57:45
Here, self.fs and self.run_command are shortcuts,
| |
| 19 | |
| 20 if no_fetch: | |
| 21 self.host.print_('## Stop trying to make fetch happen, it\'s not goi ng to happen') | |
|
foolip
2016/11/01 22:07:44
When will this message be seen? :)
jeffcarp
2016/11/01 23:21:18
I was using this flag to avoid fetching the repo e
foolip
2016/11/02 13:15:32
:)
| |
| 22 else: | |
| 23 if self.fs.exists(self.path): | |
| 24 self.host.print_('## WPT checkout exists at %s, fetching latest' % (self.path)) | |
|
qyearsley
2016/11/01 22:57:45
Note, I think that rather than printing messages l
jeffcarp
2016/11/03 23:54:07
Changing everything to logging. It feels weird tho
| |
| 25 self.run(['git', 'checkout', 'master']) | |
| 26 self.run(['git', 'fetch', '--all']) | |
| 27 self.run(['git', 'merge', '--ff-only', 'origin/master']) | |
|
qyearsley
2016/11/01 22:57:45
Possible optional change: We could also make the c
jeffcarp
2016/11/03 23:54:07
That works. Since all the class is used for is int
| |
| 28 else: | |
| 29 self.host.print_('## Cloning %s into %s' % (WPT_REPO_URL, self.p ath)) | |
| 30 self.run_command(['git', 'clone', WPT_REPO_URL, self.path]) | |
| 31 self.host.print_('## Need to set up remote "github"!') | |
|
foolip
2016/11/01 22:07:45
Does this need to be done manually? If so, should
jeffcarp
2016/11/01 23:21:18
Yes but I'm not entirely sure how that's going to
foolip
2016/11/02 13:15:32
TODO and early exit then? The script doesn't need
| |
| 32 | |
| 33 def run(self, command, **kwargs): | |
| 34 """Runs a command in the local WPT directory.""" | |
| 35 return self.run_command(command, cwd=self.path, **kwargs) | |
| 36 | |
| 37 def run_to_list(self, command, **kwargs): | |
| 38 result = self.run(command, **kwargs) | |
| 39 return filter(bool, [s.strip() for s in result.split('\n')]) | |
|
foolip
2016/11/01 22:07:44
Maybe splitlines() here too, won't comment elsewhe
| |
| 40 | |
| 41 def most_recent_cr_commit(self): | |
| 42 """Goes back in WPT commit history and gets the most recent commit | |
| 43 that contains 'Cr-Commit-Position:' | |
| 44 """ | |
| 45 sha = self.run(['git', 'rev-list', 'HEAD', '-n', '1', '--grep=Cr-Commit- Position']) | |
| 46 if not sha: | |
| 47 return None, None | |
| 48 | |
| 49 message = self.run(['git', 'show', '-s', '--format=%B', sha]) | |
| 50 print 'yerah man' | |
|
foolip
2016/11/01 22:07:44
:)
| |
| 51 print message | |
| 52 match = re.search(r'Cr-Commit-Position: (?P<cr_commit>.+)$', message, re .MULTILINE) | |
|
foolip
2016/11/01 22:07:44
Throw in a ^ so that it only matches at the beginn
jeffcarp
2016/11/01 23:21:18
Even better, I found `git footers --position [sha]
foolip
2016/11/02 13:15:32
Note that this only works if there's a local maste
| |
| 53 return sha, match.groupdict()['cr_commit'] | |
| 54 | |
| 55 def clean(self): | |
| 56 self.run(['git', 'reset', '--hard', 'HEAD']) | |
|
foolip
2016/11/01 22:07:45
Perhaps also git clean -fdx? If this is supposed t
| |
| 57 self.run(['git', 'checkout', 'master']) | |
| 58 | |
| 59 def all_branches(self): | |
| 60 return self.run_to_list(['git', 'branch', '-a']) | |
| 61 | |
| 62 def create_branch_with_patch(self, branch_name, message, patch): | |
| 63 self.clean() | |
| 64 all_branches = self.all_branches() | |
| 65 remote_branch_name = 'remotes/github/%s' % branch_name | |
| 66 | |
| 67 if branch_name in all_branches: | |
| 68 self.host.print_('## Local branch %s already exists, deleting' % bra nch_name) | |
| 69 self.run(['git', 'branch', '-D', branch_name]) | |
| 70 | |
| 71 if remote_branch_name in all_branches: | |
| 72 self.host.print_('## Remote branch %s already exists, deleting' % br anch_name) | |
| 73 self.run(['git', 'push', 'github', ':%s' % branch_name]) | |
|
foolip
2016/11/01 22:07:44
This might mess things up if there's an open pull
foolip
2016/11/02 13:15:32
TODO for this and the following comments in this f
jeffcarp
2016/11/03 23:54:07
I think it should fail if the remote branch alread
| |
| 74 | |
| 75 self.host.print_('## Creating local branch %s' % branch_name) | |
| 76 self.run(['git', 'checkout', '-b', branch_name]) | |
| 77 | |
| 78 # Remove Chromium WPT directory prefix | |
| 79 patch = patch.replace(CR_WPT_DIR, '') | |
|
foolip
2016/11/01 22:07:45
Maybe this would also be the place to add "Chromiu
| |
| 80 | |
| 81 # foolip: Could also use git am -p<n> where n is len(CR_WPT_DIR.split(/' )) | |
|
foolip
2016/11/01 22:07:44
Yep. Can you make this a TODO?
| |
| 82 # or something not off-by-one. | |
| 83 self.run(['git', 'apply', '-'], input=patch) | |
| 84 self.run(['git', 'commit', '-am', message]) | |
| 85 self.run(['git', 'push', 'github', branch_name]) | |
| OLD | NEW |