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

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

Issue 2544173002: Skip commits that don't generate a patch + fixes to get export working (Closed)
Patch Set: Created 4 years 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
1 # Copyright 2016 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """A utility class for interacting with a local checkout of the Web Platform Tes ts.""" 5 """A utility class for interacting with a local checkout of the Web Platform Tes ts."""
6 6
7 import logging 7 import logging
8 8
9 from webkitpy.w3c.chromium_commit import ChromiumCommit 9 from webkitpy.w3c.chromium_commit import ChromiumCommit
10 from webkitpy.common.system.executive import ScriptError
10 11
11 WPT_REPO_URL = 'https://chromium.googlesource.com/external/w3c/web-platform-test s.git' 12 WPT_REPO_URL = 'https://chromium.googlesource.com/external/w3c/web-platform-test s.git'
12 WPT_TMP_DIR = '/tmp/wpt' 13 WPT_TMP_DIR = '/tmp/wpt'
13 CHROMIUM_WPT_DIR = 'third_party/WebKit/LayoutTests/imported/wpt/' 14 CHROMIUM_WPT_DIR = 'third_party/WebKit/LayoutTests/imported/wpt/'
14 15
15 _log = logging.getLogger(__name__) 16 _log = logging.getLogger(__name__)
16 17
17 18
18 class LocalWPT(object): 19 class LocalWPT(object):
19 20
20 def __init__(self, host, path=WPT_TMP_DIR, no_fetch=False, use_github=False) : 21 def __init__(self, host, path=WPT_TMP_DIR, no_fetch=False, use_github=False) :
21 """ 22 """
22 Args: 23 Args:
23 host: A Host object. 24 host: A Host object.
24 path: Optional, the directory where LocalWPT will check out web-plat form-tests. 25 path: Optional, the directory where LocalWPT will check out web-plat form-tests.
25 no_fetch: Optional, passing true will skip updating the local WPT. 26 no_fetch: Optional, passing true will skip updating the local WPT.
26 Intended for use only in development after fetching once. 27 Intended for use only in development after fetching once.
27 use_github: Optional, passing true will check if the GitHub remote i s enabled 28 use_github: Optional, passing true will check if the GitHub remote i s enabled
28 (necessary for later pull request steps). 29 (necessary for later pull request steps).
29 """ 30 """
30 self.host = host 31 self.host = host
31 self.path = path 32 self.path = path
33 self.branch_name = 'chromium-export-try'
32 34
33 if no_fetch: 35 if no_fetch:
34 _log.info('Skipping remote WPT fetch') 36 _log.info('Skipping remote WPT fetch')
35 return 37 return
36 38
37 if self.host.filesystem.exists(self.path): 39 if self.host.filesystem.exists(self.path):
38 _log.info('WPT checkout exists at %s, fetching latest', self.path) 40 _log.info('WPT checkout exists at %s, fetching latest', self.path)
39 self.run(['git', 'fetch', '--all']) 41 self.run(['git', 'fetch', 'origin'])
40 self.run(['git', 'checkout', 'origin/master']) 42 self.run(['git', 'checkout', 'origin/master'])
41 else: 43 else:
42 _log.info('Cloning %s into %s', WPT_REPO_URL, self.path) 44 _log.info('Cloning %s into %s', WPT_REPO_URL, self.path)
43 self.host.executive.run_command(['git', 'clone', WPT_REPO_URL, self. path]) 45 self.host.executive.run_command(['git', 'clone', WPT_REPO_URL, self. path])
44 46
45 if use_github and 'github' not in self.run(['git', 'remote']): 47 if use_github and 'github' not in self.run(['git', 'remote']):
46 raise Exception('Need to set up remote "github"') 48 raise Exception(('Need to set up remote "github": cd %s && git remot e add github '
49 'git@github.com:w3c/web-platform-tests.git') % self .path)
47 50
48 def run(self, command, **kwargs): 51 def run(self, command, **kwargs):
49 """Runs a command in the local WPT directory.""" 52 """Runs a command in the local WPT directory."""
50 return self.host.executive.run_command(command, cwd=self.path, **kwargs) 53 return self.host.executive.run_command(command, cwd=self.path, **kwargs)
51 54
52 def most_recent_chromium_commit(self): 55 def most_recent_chromium_commit(self):
53 """Finds the most recent commit in WPT with a Chromium commit position." "" 56 """Finds the most recent commit in WPT with a Chromium commit position." ""
54 sha = self.run(['git', 'rev-list', 'HEAD', '-n', '1', '--grep=Cr-Commit- Position']) 57 sha = self.run(['git', 'rev-list', 'HEAD', '-n', '1', '--grep=Cr-Commit- Position'])
55 if not sha: 58 if not sha:
56 return None, None 59 return None, None
57 60
58 sha = sha.strip() 61 sha = sha.strip()
59 position = self.run(['git', 'footers', '--position', sha]) 62 position = self.run(['git', 'footers', '--position', sha])
60 position = position.strip() 63 position = position.strip()
61 assert position 64 assert position
62 65
63 chromium_commit = ChromiumCommit(self.host, position=position) 66 chromium_commit = ChromiumCommit(self.host, position=position)
64 return sha, chromium_commit 67 return sha, chromium_commit
65 68
66 def clean(self): 69 def clean(self):
67 self.run(['git', 'reset', '--hard', 'HEAD']) 70 self.run(['git', 'reset', '--hard', 'HEAD'])
68 self.run(['git', 'clean', '-fdx']) 71 self.run(['git', 'clean', '-fdx'])
69 self.run(['git', 'checkout', 'origin/master']) 72 self.run(['git', 'checkout', 'origin/master'])
73 try:
74 self.run(['git', 'branch', '-D', self.branch_name])
75 except ScriptError:
76 _log.info('Local branch %s does not exist yet, not deleting', self.b ranch_name)
70 77
71 def all_branches(self): 78 def all_branches(self):
72 """Returns a list of local and remote branches.""" 79 """Returns a list of local and remote branches."""
73 return self.run(['git', 'branch', '-a']).splitlines() 80 return self.run(['git', 'branch', '-a']).splitlines()
74 81
75 def create_branch_with_patch(self, message, patch): 82 def create_branch_with_patch(self, message, patch):
76 """Commits the given patch and pushes to the upstream repo. 83 """Commits the given patch and pushes to the upstream repo.
77 84
78 Args: 85 Args:
79 message: Commit message string. 86 message: Commit message string.
80 patch: A patch that can be applied by git apply. 87 patch: A patch that can be applied by git apply.
81 """ 88 """
82 self.clean() 89 self.clean()
83 all_branches = self.all_branches() 90 all_branches = self.all_branches()
84 branch_name = 'chromium-export-try' 91 remote_branch_name = 'remotes/github/%s' % self.branch_name
85 remote_branch_name = 'remotes/github/%s' % branch_name
86
87 if branch_name in all_branches:
88 _log.info('Local branch %s already exists, deleting', branch_name)
89 self.run(['git', 'branch', '-D', branch_name])
90 92
91 if remote_branch_name in all_branches: 93 if remote_branch_name in all_branches:
92 _log.info('Remote branch %s already exists, deleting', branch_name) 94 _log.info('Remote branch %s already exists, deleting', remote_branch _name)
93 # TODO(jeffcarp): Investigate what happens when remote branch exists . 95 # TODO(jeffcarp): Investigate what happens when remote branch exists .
94 self.run(['git', 'push', 'github', ':{}'.format(branch_name)]) 96 self.run(['git', 'push', 'github', ':{}'.format(remote_branch_name)] )
95 97
96 _log.info('Creating local branch %s', branch_name) 98 _log.info('Creating local branch %s', self.branch_name)
97 self.run(['git', 'checkout', '-b', branch_name]) 99 self.run(['git', 'checkout', '-b', self.branch_name])
98 100
99 # Remove Chromium WPT directory prefix. 101 # Remove Chromium WPT directory prefix.
100 patch = patch.replace(CHROMIUM_WPT_DIR, '') 102 patch = patch.replace(CHROMIUM_WPT_DIR, '')
101 103
102 # TODO(jeffcarp): Use git am -p<n> where n is len(CHROMIUM_WPT_DIR.split (/')) 104 # TODO(jeffcarp): Use git am -p<n> where n is len(CHROMIUM_WPT_DIR.split (/'))
103 # or something not off-by-one. 105 # or something not off-by-one.
104 self.run(['git', 'apply', '-'], input=patch) 106 self.run(['git', 'apply', '-'], input=patch)
105 self.run(['git', 'commit', '-am', message]) 107 self.run(['git', 'add', '.'])
106 self.run(['git', 'push', 'github', branch_name]) 108 self.run(['git', 'commit', '-m', message])
109 self.run(['git', 'push', 'github', self.branch_name])
107 110
108 return branch_name 111 return self.branch_name
112
113 def test_patch(self, patch):
qyearsley 2016/12/02 00:38:46 A docstring may be helpful here.
114 self.clean()
115
116 # Remove Chromium WPT directory prefix.
117 # TODO(jeffcarp): dedupe
118 patch = patch.replace(CHROMIUM_WPT_DIR, '')
119 print 'the PATCH'
120 print patch
qyearsley 2016/12/02 00:38:46 Are these meant to be left in? If so, they should
121
122 try:
123 self.run(['git', 'apply', '-'], input=patch)
124 self.run(['git', 'add', '.'])
125 output = self.run(['git', 'diff', 'origin/master'])
126 except ScriptError as error:
127 print 'Patch caused exception:'
128 print error
129 output = ''
130
131 self.clean()
132 return output
109 133
110 def commits_behind_master(self, commit): 134 def commits_behind_master(self, commit):
111 """Returns the number of commits after the given commit on origin/master . 135 """Returns the number of commits after the given commit on origin/master .
112 136
113 This doesn't include the given commit, and this assumes that the given 137 This doesn't include the given commit, and this assumes that the given
114 commit is on the the master branch. 138 commit is on the the master branch.
115 """ 139 """
116 return len(self.run([ 140 return len(self.run([
117 'git', 'rev-list', '{}..origin/master'.format(commit) 141 'git', 'rev-list', '{}..origin/master'.format(commit)
118 ]).splitlines()) 142 ]).splitlines())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698