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

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

Issue 2439153002: Script for exporting WPT (Closed)
Patch Set: Clean up finding Cr-Commit-Pos in WPT with one neat trick 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 side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..b5334461727f8b3c6682b8bd285b6bf4ae1e4c67
--- /dev/null
+++ b/third_party/WebKit/Tools/Scripts/webkitpy/w3c/local_wpt.py
@@ -0,0 +1,85 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import re
+
+WPT_REPO_URL = 'https://chromium.googlesource.com/external/w3c/web-platform-tests.git'
+WPT_TMP_DIR = '/tmp/wpt'
+CR_WPT_DIR = 'third_party/WebKit/LayoutTests/imported/wpt/'
+
+
+class LocalWPT(object):
+
+ def __init__(self, host, path=WPT_TMP_DIR, no_fetch=False):
+ self.host = host
+ self.fs = self.host.filesystem
+ self.path = path
+ self.run_command = self.host.executive.run_command
qyearsley 2016/11/01 22:57:45 Here, self.fs and self.run_command are shortcuts,
+
+ if no_fetch:
+ self.host.print_('## Stop trying to make fetch happen, it\'s not going to happen')
foolip 2016/11/01 22:07:44 When will this message be seen? :)
jeffcarp 2016/11/01 23:21:18 I was using this flag to avoid fetching the repo e
foolip 2016/11/02 13:15:32 :)
+ else:
+ if self.fs.exists(self.path):
+ self.host.print_('## WPT checkout exists at %s, fetching latest' % (self.path))
qyearsley 2016/11/01 22:57:45 Note, I think that rather than printing messages l
jeffcarp 2016/11/03 23:54:07 Changing everything to logging. It feels weird tho
+ self.run(['git', 'checkout', 'master'])
+ self.run(['git', 'fetch', '--all'])
+ self.run(['git', 'merge', '--ff-only', 'origin/master'])
qyearsley 2016/11/01 22:57:45 Possible optional change: We could also make the c
jeffcarp 2016/11/03 23:54:07 That works. Since all the class is used for is int
+ else:
+ self.host.print_('## Cloning %s into %s' % (WPT_REPO_URL, self.path))
+ self.run_command(['git', 'clone', WPT_REPO_URL, self.path])
+ self.host.print_('## Need to set up remote "github"!')
foolip 2016/11/01 22:07:45 Does this need to be done manually? If so, should
jeffcarp 2016/11/01 23:21:18 Yes but I'm not entirely sure how that's going to
foolip 2016/11/02 13:15:32 TODO and early exit then? The script doesn't need
+
+ def run(self, command, **kwargs):
+ """Runs a command in the local WPT directory."""
+ return self.run_command(command, cwd=self.path, **kwargs)
+
+ def run_to_list(self, command, **kwargs):
+ result = self.run(command, **kwargs)
+ return filter(bool, [s.strip() for s in result.split('\n')])
foolip 2016/11/01 22:07:44 Maybe splitlines() here too, won't comment elsewhe
+
+ def most_recent_cr_commit(self):
+ """Goes back in WPT commit history and gets the most recent commit
+ that contains 'Cr-Commit-Position:'
+ """
+ sha = self.run(['git', 'rev-list', 'HEAD', '-n', '1', '--grep=Cr-Commit-Position'])
+ if not sha:
+ return None, None
+
+ message = self.run(['git', 'show', '-s', '--format=%B', sha])
+ print 'yerah man'
foolip 2016/11/01 22:07:44 :)
+ print message
+ match = re.search(r'Cr-Commit-Position: (?P<cr_commit>.+)$', message, re.MULTILINE)
foolip 2016/11/01 22:07:44 Throw in a ^ so that it only matches at the beginn
jeffcarp 2016/11/01 23:21:18 Even better, I found `git footers --position [sha]
foolip 2016/11/02 13:15:32 Note that this only works if there's a local maste
+ return sha, match.groupdict()['cr_commit']
+
+ def clean(self):
+ self.run(['git', 'reset', '--hard', 'HEAD'])
foolip 2016/11/01 22:07:45 Perhaps also git clean -fdx? If this is supposed t
+ self.run(['git', 'checkout', 'master'])
+
+ def all_branches(self):
+ return self.run_to_list(['git', 'branch', '-a'])
+
+ def create_branch_with_patch(self, branch_name, message, patch):
+ self.clean()
+ all_branches = self.all_branches()
+ remote_branch_name = 'remotes/github/%s' % branch_name
+
+ if branch_name in all_branches:
+ self.host.print_('## Local branch %s already exists, deleting' % branch_name)
+ self.run(['git', 'branch', '-D', branch_name])
+
+ if remote_branch_name in all_branches:
+ self.host.print_('## Remote branch %s already exists, deleting' % branch_name)
+ self.run(['git', 'push', 'github', ':%s' % branch_name])
foolip 2016/11/01 22:07:44 This might mess things up if there's an open pull
foolip 2016/11/02 13:15:32 TODO for this and the following comments in this f
jeffcarp 2016/11/03 23:54:07 I think it should fail if the remote branch alread
+
+ self.host.print_('## Creating local branch %s' % branch_name)
+ self.run(['git', 'checkout', '-b', branch_name])
+
+ # Remove Chromium WPT directory prefix
+ patch = patch.replace(CR_WPT_DIR, '')
foolip 2016/11/01 22:07:45 Maybe this would also be the place to add "Chromiu
+
+ # foolip: Could also use git am -p<n> where n is len(CR_WPT_DIR.split(/'))
foolip 2016/11/01 22:07:44 Yep. Can you make this a TODO?
+ # 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])

Powered by Google App Engine
This is Rietveld 408576698