Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt.py

Issue 2439153002: Script for exporting WPT (Closed)
Patch Set: Linting Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 OLDEST_POSSIBLE_WPT_COMMIT = '2f10dbcf873d4f67c81a89f4ba84bfde514675b0'
11
12
13 class LocalWPT(object):
14
15 def __init__(self, host, path=WPT_TMP_DIR, no_fetch=False):
16 self.host = host
17 self.fs = self.host.filesystem
18 self.path = path
19 self.run_command = self.host.executive.run_command
20
21 if no_fetch:
22 self.host.print_('## Stop trying to make fetch happen, it\'s not goi ng to happen')
23 else:
24 if self.fs.exists(self.path):
25 self.host.print_('## WPT checkout exists at %s, fetching latest' % (self.path))
26 self.run(['git', 'checkout', 'master'])
27 self.run(['git', 'fetch', '--all'])
28 self.run(['git', 'merge', '--ff-only', 'origin/master'])
29 else:
30 self.host.print_('## Cloning %s into %s' % (WPT_REPO_URL, self.p ath))
31 self.run_command(['git', 'clone', WPT_REPO_URL, self.path])
32 # TODO: need to set up remote github
33 self.host.print_('## Need to set up remote "github"!')
34
35 def run(self, command, **kwargs):
36 """Runs a command in the local WPT directory."""
37 return self.run_command(command, cwd=self.path, **kwargs)
38
39 def most_recent_cr_commit(self):
40 """Goes back in WPT commit history and gets the most recent commit
41 that contains 'Cr-Commit-Position:'
42 """
43 rev = '%s..HEAD' % OLDEST_POSSIBLE_WPT_COMMIT
44 shas = filter(bool, self.run(['git', 'rev-list', rev]).split('\n'))
45
46 for sha in shas:
47 message = self.run(['git', 'show', '-s', '--format=%B', sha])
48 if 'Cr-Commit-Position' in message:
49 match = re.match(r'Cr-Commit-Position: (?P<cr_commit>.+)$', mess age)
50 if not match:
51 return None, None
52 cr_commit = match.group('cr_commit')
53 if cr_commit:
54 return sha, cr_commit
55
56 return None, None
57
58 def clean(self):
59 self.run(['git', 'reset', '--hard', 'HEAD'])
60 self.run(['git', 'checkout', 'master'])
61
62 def all_branches(self):
63 return [s.strip() for s in self.run(['git', 'branch', '-a']).split('\n') ]
64
65 def create_branch_with_patch(self, branch_name, message, patch):
66 self.clean()
67 all_branches = self.all_branches()
68 remote_branch_name = 'remotes/github/%s' % branch_name
69
70 if branch_name in all_branches:
71 self.host.print_('## Local branch %s already exists, deleting' % bra nch_name)
72 self.run(['git', 'branch', '-D', branch_name])
73 # raise Exception('Local branch %s already exists' % branch_name)
74
75 if remote_branch_name in all_branches:
76 self.host.print_('## Remote branch %s already exists, deleting' % br anch_name)
77 self.run(['git', 'push', 'github', ':%s' % branch_name])
78 # raise Exception('Remote branch %s already exists' % branch_name)
79
80 self.host.print_('## Creating local branch %s' % branch_name)
81 self.run(['git', 'checkout', '-b', branch_name])
82
83 # Remove Chromium WPT directory prefix
84 patch = patch.replace(CR_WPT_DIR, '')
85
86 # foolip: Could also use git am -p<n> where n is len(CR_WPT_DIR.split(/' ))
87 # or something not off-by-one.
88 self.run(['git', 'apply', '-'], input=patch)
89 self.run(['git', 'commit', '-am', message])
90 self.run(['git', 'push', 'github', branch_name])
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698