Index: third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt.py |
diff --git a/third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt.py b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt.py |
index d7217c0999415007a3f5e9ea49322a3559e2f160..2e574d47c93ea37ee476c9e09b4bfc4d3f1100b3 100644 |
--- a/third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt.py |
+++ b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt.py |
@@ -7,6 +7,7 @@ |
import logging |
from webkitpy.w3c.chromium_commit import ChromiumCommit |
+from webkitpy.common.system.executive import ScriptError |
WPT_REPO_URL = 'https://chromium.googlesource.com/external/w3c/web-platform-tests.git' |
WPT_TMP_DIR = '/tmp/wpt' |
@@ -17,18 +18,17 @@ _log = logging.getLogger(__name__) |
class LocalWPT(object): |
- def __init__(self, host, path=WPT_TMP_DIR, no_fetch=False, use_github=False): |
+ def __init__(self, host, path=WPT_TMP_DIR, no_fetch=False): |
""" |
Args: |
host: A Host object. |
path: Optional, the directory where LocalWPT will check out web-platform-tests. |
no_fetch: Optional, passing true will skip updating the local WPT. |
Intended for use only in development after fetching once. |
- use_github: Optional, passing true will check if the GitHub remote is enabled |
- (necessary for later pull request steps). |
""" |
self.host = host |
self.path = path |
+ self.branch_name = 'chromium-export-try' |
if no_fetch: |
_log.info('Skipping remote WPT fetch') |
@@ -36,15 +36,12 @@ class LocalWPT(object): |
if self.host.filesystem.exists(self.path): |
_log.info('WPT checkout exists at %s, fetching latest', self.path) |
- self.run(['git', 'fetch', '--all']) |
+ self.run(['git', 'fetch', 'origin']) |
self.run(['git', 'checkout', 'origin/master']) |
else: |
_log.info('Cloning %s into %s', WPT_REPO_URL, self.path) |
self.host.executive.run_command(['git', 'clone', WPT_REPO_URL, self.path]) |
- if use_github and 'github' not in self.run(['git', 'remote']): |
- raise Exception('Need to set up remote "github"') |
- |
def run(self, command, **kwargs): |
"""Runs a command in the local WPT directory.""" |
return self.host.executive.run_command(command, cwd=self.path, **kwargs) |
@@ -67,6 +64,10 @@ class LocalWPT(object): |
self.run(['git', 'reset', '--hard', 'HEAD']) |
self.run(['git', 'clean', '-fdx']) |
self.run(['git', 'checkout', 'origin/master']) |
+ try: |
+ self.run(['git', 'branch', '-D', self.branch_name]) |
+ except ScriptError: |
+ _log.info('Local branch %s does not exist yet, not deleting', self.branch_name) |
def all_branches(self): |
"""Returns a list of local and remote branches.""" |
@@ -81,20 +82,19 @@ class LocalWPT(object): |
""" |
self.clean() |
all_branches = self.all_branches() |
- branch_name = 'chromium-export-try' |
- remote_branch_name = 'remotes/github/%s' % branch_name |
- if branch_name in all_branches: |
- _log.info('Local branch %s already exists, deleting', branch_name) |
- self.run(['git', 'branch', '-D', branch_name]) |
+ # Creating and deleting the branch causes a bunch of |
+ # noise in the #testing channel - trying out using |
+ # git push -f below to overwrite the branch |
- if remote_branch_name in all_branches: |
- _log.info('Remote branch %s already exists, deleting', branch_name) |
- # TODO(jeffcarp): Investigate what happens when remote branch exists. |
- self.run(['git', 'push', 'github', ':{}'.format(branch_name)]) |
+ # remote_branch_name = 'remotes/github/%s' % self.branch_name |
+ # if remote_branch_name in all_branches: |
+ # _log.info('Remote branch %s already exists, deleting', remote_branch_name) |
+ # # TODO(jeffcarp): Investigate what happens when remote branch exists. |
+ # self.run(['git', 'push', 'github', ':{}'.format(remote_branch_name)]) |
- _log.info('Creating local branch %s', branch_name) |
- self.run(['git', 'checkout', '-b', branch_name]) |
+ _log.info('Creating local branch %s', self.branch_name) |
+ self.run(['git', 'checkout', '-b', self.branch_name]) |
# Remove Chromium WPT directory prefix. |
patch = patch.replace(CHROMIUM_WPT_DIR, '') |
@@ -102,10 +102,37 @@ class LocalWPT(object): |
# TODO(jeffcarp): Use git am -p<n> where n is len(CHROMIUM_WPT_DIR.split(/')) |
# or something not off-by-one. |
self.run(['git', 'apply', '-'], input=patch) |
- self.run(['git', 'commit', '-am', message]) |
- self.run(['git', 'push', 'github', branch_name]) |
+ self.run(['git', 'add', '.']) |
+ self.run(['git', 'commit', '-m', message]) |
+ self.run(['git', 'push', '-f', 'github', self.branch_name]) |
+ |
+ return self.branch_name |
- return branch_name |
+ def test_patch(self, patch): |
+ """Returns the expected output of a patch agains origin/master. |
+ |
+ Args: |
+ patch: The patch to test against. |
+ |
+ Returns: |
+ A string containing the diff the patch produced. |
+ """ |
+ self.clean() |
+ |
+ # Remove Chromium WPT directory prefix. |
+ # TODO(jeffcarp): dedupe |
+ patch = patch.replace(CHROMIUM_WPT_DIR, '') |
+ |
+ try: |
+ self.run(['git', 'apply', '-'], input=patch) |
+ self.run(['git', 'add', '.']) |
+ output = self.run(['git', 'diff', 'origin/master']) |
+ except ScriptError as error: |
+ _log.error('Error while applying patch: %s', error) |
+ output = '' |
+ |
+ self.clean() |
+ return output |
def commits_behind_master(self, commit): |
"""Returns the number of commits after the given commit on origin/master. |