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

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

Issue 2439153002: Script for exporting WPT (Closed)
Patch Set: Fix spacing issues 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 """A utility class for interacting with a local checkout of the web-platform-tes ts."""
6
7 import logging
8
9 WPT_REPO_URL = 'https://chromium.googlesource.com/external/w3c/web-platform-test s.git'
10 WPT_TMP_DIR = '/tmp/wpt'
11 CHROMIUM_WPT_DIR = 'third_party/WebKit/LayoutTests/imported/wpt/'
12 _log = logging.getLogger(__name__)
13
14
15 class LocalWPT(object):
16
17 def __init__(self, host, path=WPT_TMP_DIR, no_fetch=False, use_github=False) :
18 """
19 Args:
20 host: A Host object.
21 path: Optional, the directory where LocalWPT will check out web-plat form-tests.
22 no_fetch: Optional, passing true will skip updating the local WPT.
23 Intended for use only in development after fetching once.
24 use_github: Optional, passing true will check if the GitHub remote i s enabled
25 (necessary for later pull request steps).
26 """
27 self.host = host
28 self.path = path
29
30 if no_fetch:
31 _log.info('Skipping remote WPT fetch')
32 return
33
34 if self.host.filesystem.exists(self.path):
35 _log.info('WPT checkout exists at %s, fetching latest', self.path)
36 self.run(['git', 'checkout', 'master'])
37 self.run(['git', 'fetch', '--all'])
38 self.run(['git', 'merge', '--ff-only', 'origin/master'])
39 else:
40 _log.info('Cloning %s into %s', WPT_REPO_URL, self.path)
41 self.host.executive.run_command(['git', 'clone', WPT_REPO_URL, self. path])
42
43 if use_github and 'github' not in self.run(['git', 'remote']):
44 raise Exception('Need to set up remote "github"')
45
46 def run(self, command, **kwargs):
47 """Runs a command in the local WPT directory."""
48 return self.host.executive.run_command(command, cwd=self.path, **kwargs)
49
50 def most_recent_chromium_commit(self):
51 """Goes back in WPT commit history and gets the most recent commit
52 that contains 'Cr-Commit-Position:'
53 """
54 sha = self.run(['git', 'rev-list', 'HEAD', '-n', '1', '--grep=Cr-Commit- Position'])
55 if not sha:
56 return None, None
57
58 sha = sha.strip()
59 position = self.run(['git', 'footers', '--position', sha])
60 position = position.strip()
61 assert position
62 return sha, position
63
64 def clean(self):
65 self.run(['git', 'reset', '--hard', 'HEAD'])
66 self.run(['git', 'clean', '-fdx'])
67 self.run(['git', 'checkout', 'master'])
68
69 def all_branches(self):
70 return self.run(['git', 'branch', '-a']).splitlines()
71
72 def create_branch_with_patch(self, branch_name, message, patch):
73 self.clean()
74 all_branches = self.all_branches()
75 remote_branch_name = 'remotes/github/%s' % branch_name
76
77 if branch_name in all_branches:
78 _log.info('Local branch %s already exists, deleting', branch_name)
79 self.run(['git', 'branch', '-D', branch_name])
80
81 if remote_branch_name in all_branches:
82 _log.info('Remote branch %s already exists, deleting', branch_name)
83 # TODO(jeffcarp): Investigate what happens when remote branch exists
84 self.run(['git', 'push', 'github', ':{}'.format(branch_name)])
85
86 _log.info('Creating local branch %s', branch_name)
87 self.run(['git', 'checkout', '-b', branch_name])
88
89 # Remove Chromium WPT directory prefix
90 patch = patch.replace(CHROMIUM_WPT_DIR, '')
91
92 # TODO(jeffcarp): Use git am -p<n> where n is len(CHROMIUM_WPT_DIR.split (/'))
93 # or something not off-by-one.
94 self.run(['git', 'apply', '-'], input=patch)
95 self.run(['git', 'commit', '-am', message])
96 self.run(['git', 'push', 'github', branch_name])
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698