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

Unified Diff: git_wktry.py

Issue 12226013: Add a git command for running ToT WebKit patches against the trybots. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: Created 7 years, 10 months 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
« git-wktry ('K') | « git-wktry ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_wktry.py
===================================================================
--- git_wktry.py (revision 0)
+++ git_wktry.py (revision 0)
@@ -0,0 +1,112 @@
+#!/usr/bin/python
+# Copyright (c) 2011 The Chromium Authors. All rights reserved.
M-A Ruel 2013/02/07 14:06:17 Same
tony 2013/02/11 20:52:46 Done.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+"""Wrapper for trychange.py for WebKit changes."""
+
+import errno
+import logging
+import os
+import re
+import shutil
+import sys
+import tempfile
+
+import git_cl
+from scm import GIT
+import subprocess2
+import trychange
+
+
+class ScopedTemporaryFile(object):
+ def __init__(self, **kwargs):
+ _, self._path = tempfile.mkstemp(**kwargs)
M-A Ruel 2013/02/07 14:06:17 you need to os.close() the initial argument otherw
tony 2013/02/11 20:52:46 Done.
+
+ def __enter__(self):
+ return self._path
+
+ def __exit__(self, type, value, traceback):
+ try:
+ os.remove(self._path)
+ except OSError, e:
+ if e.errno != errno.ENOENT:
+ raise e
+
+
+class ScopedTemporaryDirectory(object):
+ def __init__(self, **kwargs):
+ self._path = tempfile.mkdtemp(**kwargs)
+
+ def __enter__(self):
+ return self._path
+
+ def __exit__(self, type, value, traceback):
+ shutil.rmtree(self._path, ignore_errors=True)
+
+
+def generateDiff(path_to_write, chromium_src_root):
M-A Ruel 2013/02/07 14:06:17 Can you add a docstring just to explain that it's
tony 2013/02/11 20:52:46 Done.
+ diff_lines = []
+ with ScopedTemporaryDirectory() as temporary_directory:
+ deps_contents = open(os.path.join(chromium_src_root, 'DEPS')).read()
+ deps_contents = re.sub(r'"webkit_revision":\s*"\d+"',
+ '"webkit_revision": "HEAD"', deps_contents)
+
+ temporary_deps_path = os.path.join(temporary_directory, 'DEPS')
+ temporary_deps = open(temporary_deps_path, 'wb')
+ temporary_deps.write(deps_contents)
+ temporary_deps.close()
+ try:
+ raw_diff = GIT.Capture(['diff', '-p', '--no-color',
+ '--no-ext-diff', 'DEPS', temporary_deps_path],
+ chromium_src_root)
+ except subprocess2.CalledProcessError, e:
+ raw_diff = e.stdout
+ raw_diff = raw_diff.replace('\n--- a/DEPS', '\n--- DEPS')
+ diff_lines = trychange.GetMungedDiff('', raw_diff.splitlines(True))[0]
+
+ raw_diff = GIT.GenerateDiff(os.path.join(chromium_src_root,
+ 'third_party/WebKit'), full_move=True).splitlines(True)
+ diff_lines.extend(trychange.GetMungedDiff('third_party/WebKit',
+ raw_diff)[0])
+
+ open(path_to_write, 'wb').write(''.join(diff_lines))
+
+
+def addLayoutBotsIfNeeded(argv):
+ for flag in argv:
+ if flag == '--bot' or flag.startswith('--bot='):
+ return argv
+ argv.extend(('--bot', 'linux_layout_rel,mac_layout_rel,win_layout_rel'))
+
+
+def chromiumSrcRoot():
+ root = GIT.GetCheckoutRoot('.')
+ parent_path, leaf_path = os.path.split(root)
+ if leaf_path == 'WebKit':
+ root = GIT.GetCheckoutRoot(parent_path)
+ return root
+
M-A Ruel 2013/02/07 14:06:17 Two lines
tony 2013/02/11 20:52:46 Done.
+def main(argv):
+ chromium_src_root = chromiumSrcRoot()
+ os.chdir(chromium_src_root)
+ argv = argv[1:]
+ addLayoutBotsIfNeeded(argv)
+
+ with ScopedTemporaryFile() as diff_file:
+ generateDiff(diff_file, chromium_src_root)
+ args = [
+ '--sub_rep', 'third_party/WebKit',
+ '--root', 'src',
+ '--rietveld_url', 'https://codereview.chromium.org',
+ '-r%s' % GIT.GetGitSvnHeadRev(chromium_src_root),
+ '--diff', diff_file,
+ ]
+ args.extend(argv)
+ cl = git_cl.Changelist()
+ change = cl.GetChange(cl.GetUpstreamBranch(), None)
+ logging.getLogger().handlers = []
+ return trychange.TryChange(args, change,
+ swallow_exception=False, prog='git wktry')
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
Property changes on: git_wktry.py
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:eol-style
+ LF
« git-wktry ('K') | « git-wktry ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698