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

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: Merge ChromiumWPT functionality into TestExporter, expose exportable_commits 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):
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 (necessary for later pull request steps).
29 """ 28 """
30 self.host = host 29 self.host = host
31 self.path = path 30 self.path = path
31 self.branch_name = 'chromium-export-try'
32 32
33 if no_fetch: 33 if no_fetch:
34 _log.info('Skipping remote WPT fetch') 34 _log.info('Skipping remote WPT fetch')
35 return 35 return
36 36
37 if self.host.filesystem.exists(self.path): 37 if self.host.filesystem.exists(self.path):
38 _log.info('WPT checkout exists at %s, fetching latest', self.path) 38 _log.info('WPT checkout exists at %s, fetching latest', self.path)
39 self.run(['git', 'fetch', '--all']) 39 self.run(['git', 'fetch', 'origin'])
40 self.run(['git', 'checkout', 'origin/master']) 40 self.run(['git', 'checkout', 'origin/master'])
41 else: 41 else:
42 _log.info('Cloning %s into %s', WPT_REPO_URL, self.path) 42 _log.info('Cloning %s into %s', WPT_REPO_URL, self.path)
43 self.host.executive.run_command(['git', 'clone', WPT_REPO_URL, self. path]) 43 self.host.executive.run_command(['git', 'clone', WPT_REPO_URL, self. path])
44 44
45 if use_github and 'github' not in self.run(['git', 'remote']):
46 raise Exception('Need to set up remote "github"')
47
48 def run(self, command, **kwargs): 45 def run(self, command, **kwargs):
49 """Runs a command in the local WPT directory.""" 46 """Runs a command in the local WPT directory."""
50 return self.host.executive.run_command(command, cwd=self.path, **kwargs) 47 return self.host.executive.run_command(command, cwd=self.path, **kwargs)
51 48
52 def most_recent_chromium_commit(self): 49 def most_recent_chromium_commit(self):
53 """Finds the most recent commit in WPT with a Chromium commit position." "" 50 """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']) 51 sha = self.run(['git', 'rev-list', 'HEAD', '-n', '1', '--grep=Cr-Commit- Position'])
55 if not sha: 52 if not sha:
56 return None, None 53 return None, None
57 54
58 sha = sha.strip() 55 sha = sha.strip()
59 position = self.run(['git', 'footers', '--position', sha]) 56 position = self.run(['git', 'footers', '--position', sha])
60 position = position.strip() 57 position = position.strip()
61 assert position 58 assert position
62 59
63 chromium_commit = ChromiumCommit(self.host, position=position) 60 chromium_commit = ChromiumCommit(self.host, position=position)
64 return sha, chromium_commit 61 return sha, chromium_commit
65 62
66 def clean(self): 63 def clean(self):
67 self.run(['git', 'reset', '--hard', 'HEAD']) 64 self.run(['git', 'reset', '--hard', 'HEAD'])
68 self.run(['git', 'clean', '-fdx']) 65 self.run(['git', 'clean', '-fdx'])
69 self.run(['git', 'checkout', 'origin/master']) 66 self.run(['git', 'checkout', 'origin/master'])
67 try:
68 self.run(['git', 'branch', '-D', self.branch_name])
69 except ScriptError:
70 _log.info('Local branch %s does not exist yet, not deleting', self.b ranch_name)
70 71
71 def all_branches(self): 72 def all_branches(self):
72 """Returns a list of local and remote branches.""" 73 """Returns a list of local and remote branches."""
73 return self.run(['git', 'branch', '-a']).splitlines() 74 return self.run(['git', 'branch', '-a']).splitlines()
74 75
75 def create_branch_with_patch(self, message, patch): 76 def create_branch_with_patch(self, message, patch):
76 """Commits the given patch and pushes to the upstream repo. 77 """Commits the given patch and pushes to the upstream repo.
77 78
78 Args: 79 Args:
79 message: Commit message string. 80 message: Commit message string.
80 patch: A patch that can be applied by git apply. 81 patch: A patch that can be applied by git apply.
81 """ 82 """
82 self.clean() 83 self.clean()
83 all_branches = self.all_branches() 84 all_branches = self.all_branches()
84 branch_name = 'chromium-export-try'
85 remote_branch_name = 'remotes/github/%s' % branch_name
86 85
87 if branch_name in all_branches: 86 # Creating and deleting the branch causes a bunch of
88 _log.info('Local branch %s already exists, deleting', branch_name) 87 # noise in the #testing channel - trying out using
89 self.run(['git', 'branch', '-D', branch_name]) 88 # git push -f below to overwrite the branch
90 89
91 if remote_branch_name in all_branches: 90 # remote_branch_name = 'remotes/github/%s' % self.branch_name
92 _log.info('Remote branch %s already exists, deleting', branch_name) 91 # if remote_branch_name in all_branches:
93 # TODO(jeffcarp): Investigate what happens when remote branch exists . 92 # _log.info('Remote branch %s already exists, deleting', remote_bran ch_name)
94 self.run(['git', 'push', 'github', ':{}'.format(branch_name)]) 93 # # TODO(jeffcarp): Investigate what happens when remote branch exis ts.
94 # self.run(['git', 'push', 'github', ':{}'.format(remote_branch_name )])
95 95
96 _log.info('Creating local branch %s', branch_name) 96 _log.info('Creating local branch %s', self.branch_name)
97 self.run(['git', 'checkout', '-b', branch_name]) 97 self.run(['git', 'checkout', '-b', self.branch_name])
98 98
99 # Remove Chromium WPT directory prefix. 99 # Remove Chromium WPT directory prefix.
100 patch = patch.replace(CHROMIUM_WPT_DIR, '') 100 patch = patch.replace(CHROMIUM_WPT_DIR, '')
101 101
102 # TODO(jeffcarp): Use git am -p<n> where n is len(CHROMIUM_WPT_DIR.split (/')) 102 # TODO(jeffcarp): Use git am -p<n> where n is len(CHROMIUM_WPT_DIR.split (/'))
103 # or something not off-by-one. 103 # or something not off-by-one.
104 self.run(['git', 'apply', '-'], input=patch) 104 self.run(['git', 'apply', '-'], input=patch)
105 self.run(['git', 'commit', '-am', message]) 105 self.run(['git', 'add', '.'])
106 self.run(['git', 'push', 'github', branch_name]) 106 self.run(['git', 'commit', '-m', message])
107 self.run(['git', 'push', '-f', 'github', self.branch_name])
107 108
108 return branch_name 109 return self.branch_name
110
111 def test_patch(self, patch):
112 """Returns the expected output of a patch agains origin/master.
113
114 Args:
115 patch: The patch to test against.
116
117 Returns:
118 A string containing the diff the patch produced.
119 """
120 self.clean()
121
122 # Remove Chromium WPT directory prefix.
123 # TODO(jeffcarp): dedupe
124 patch = patch.replace(CHROMIUM_WPT_DIR, '')
125
126 try:
127 self.run(['git', 'apply', '-'], input=patch)
128 self.run(['git', 'add', '.'])
129 output = self.run(['git', 'diff', 'origin/master'])
130 except ScriptError as error:
131 _log.error('Error while applying patch: %s', error)
132 output = ''
133
134 self.clean()
135 return output
109 136
110 def commits_behind_master(self, commit): 137 def commits_behind_master(self, commit):
111 """Returns the number of commits after the given commit on origin/master . 138 """Returns the number of commits after the given commit on origin/master .
112 139
113 This doesn't include the given commit, and this assumes that the given 140 This doesn't include the given commit, and this assumes that the given
114 commit is on the the master branch. 141 commit is on the the master branch.
115 """ 142 """
116 return len(self.run([ 143 return len(self.run([
117 'git', 'rev-list', '{}..origin/master'.format(commit) 144 'git', 'rev-list', '{}..origin/master'.format(commit)
118 ]).splitlines()) 145 ]).splitlines())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698