OLD | NEW |
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.common.system.executive import ScriptError | 9 from webkitpy.common.system.executive import ScriptError |
10 from webkitpy.w3c.chromium_commit import ChromiumCommit | 10 from webkitpy.w3c.chromium_commit import ChromiumCommit |
11 | 11 |
12 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' |
13 WPT_TMP_DIR = '/tmp/wpt' | 13 WPT_TEMP_DIR = '/tmp/wpt' |
14 WPT_SSH_URL = 'git@github.com:w3c/web-platform-tests.git' | 14 WPT_SSH_URL = 'git@github.com:w3c/web-platform-tests.git' |
15 REMOTE_NAME = 'github' | 15 REMOTE_NAME = 'github' |
16 CHROMIUM_WPT_DIR = 'third_party/WebKit/LayoutTests/external/wpt/' | 16 CHROMIUM_WPT_DIR = 'third_party/WebKit/LayoutTests/external/wpt/' |
17 | 17 |
18 _log = logging.getLogger(__name__) | 18 _log = logging.getLogger(__name__) |
19 | 19 |
20 | 20 |
21 class LocalWPT(object): | 21 class LocalWPT(object): |
22 | 22 |
23 def __init__(self, host, path=WPT_TMP_DIR, no_fetch=False): | 23 def __init__(self, host, path=WPT_TEMP_DIR): |
24 """ | 24 """ |
25 Args: | 25 Args: |
26 host: A Host object. | 26 host: A Host object. |
27 path: Optional, the directory where LocalWPT will check out web-plat
form-tests. | 27 path: Optional, the path to the web-platform-tests repo. |
28 no_fetch: Optional, passing true will skip updating the local WPT. | 28 If this directory already exists, it is assumed that the |
29 Intended for use only in development after fetching once. | 29 web-platform-tests repo is already checked out at this path. |
30 """ | 30 """ |
31 self.host = host | 31 self.host = host |
32 self.path = path | 32 self.path = path |
33 self.branch_name = 'chromium-export-try' | 33 self.branch_name = 'chromium-export-try' |
34 | 34 |
35 if no_fetch: | 35 def fetch(self): |
36 _log.info('Skipping remote WPT fetch') | |
37 return | |
38 | |
39 if self.host.filesystem.exists(self.path): | 36 if self.host.filesystem.exists(self.path): |
40 _log.info('WPT checkout exists at %s, fetching latest', self.path) | 37 _log.info('WPT checkout exists at %s, fetching latest', self.path) |
41 self.run(['git', 'fetch', '--all']) | 38 self.run(['git', 'fetch', '--all']) |
42 self.run(['git', 'checkout', 'origin/master']) | 39 self.run(['git', 'checkout', 'origin/master']) |
43 else: | 40 else: |
44 _log.info('Cloning %s into %s', WPT_REPO_URL, self.path) | 41 _log.info('Cloning %s into %s', WPT_REPO_URL, self.path) |
45 self.host.executive.run_command(['git', 'clone', WPT_REPO_URL, self.
path]) | 42 self.host.executive.run_command(['git', 'clone', WPT_REPO_URL, self.
path]) |
46 | 43 |
47 if REMOTE_NAME not in self.run(['git', 'remote']): | 44 if REMOTE_NAME not in self.run(['git', 'remote']): |
48 self.run(['git', 'remote', 'add', REMOTE_NAME, WPT_SSH_URL]) | 45 self.run(['git', 'remote', 'add', REMOTE_NAME, WPT_SSH_URL]) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 """ | 112 """ |
116 self.clean() | 113 self.clean() |
117 | 114 |
118 # Remove Chromium WPT directory prefix. | 115 # Remove Chromium WPT directory prefix. |
119 patch = patch.replace(CHROMIUM_WPT_DIR, '') | 116 patch = patch.replace(CHROMIUM_WPT_DIR, '') |
120 | 117 |
121 try: | 118 try: |
122 self.run(['git', 'apply', '-'], input=patch) | 119 self.run(['git', 'apply', '-'], input=patch) |
123 self.run(['git', 'add', '.']) | 120 self.run(['git', 'add', '.']) |
124 output = self.run(['git', 'diff', 'origin/master']) | 121 output = self.run(['git', 'diff', 'origin/master']) |
125 except ScriptError as error: | 122 except ScriptError: |
126 _log.warning('Patch did not apply cleanly, skipping...') | 123 _log.warning('Patch did not apply cleanly, skipping...') |
127 output = '' | 124 output = '' |
128 | 125 |
129 self.clean() | 126 self.clean() |
130 return output | 127 return output |
131 | 128 |
132 def commits_behind_master(self, commit): | 129 def commits_behind_master(self, commit): |
133 """Returns the number of commits after the given commit on origin/master
. | 130 """Returns the number of commits after the given commit on origin/master
. |
134 | 131 |
135 This doesn't include the given commit, and this assumes that the given | 132 This doesn't include the given commit, and this assumes that the given |
136 commit is on the the master branch. | 133 commit is on the the master branch. |
137 """ | 134 """ |
138 return len(self.run([ | 135 return len(self.run([ |
139 'git', 'rev-list', '{}..origin/master'.format(commit) | 136 'git', 'rev-list', '{}..origin/master'.format(commit) |
140 ]).splitlines()) | 137 ]).splitlines()) |
OLD | NEW |