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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« git-wktry ('K') | « git-wktry ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:executable
+ *
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 #!/usr/bin/python
2 # 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.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5 """Wrapper for trychange.py for WebKit changes."""
6
7 import errno
8 import logging
9 import os
10 import re
11 import shutil
12 import sys
13 import tempfile
14
15 import git_cl
16 from scm import GIT
17 import subprocess2
18 import trychange
19
20
21 class ScopedTemporaryFile(object):
22 def __init__(self, **kwargs):
23 _, 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.
24
25 def __enter__(self):
26 return self._path
27
28 def __exit__(self, type, value, traceback):
29 try:
30 os.remove(self._path)
31 except OSError, e:
32 if e.errno != errno.ENOENT:
33 raise e
34
35
36 class ScopedTemporaryDirectory(object):
37 def __init__(self, **kwargs):
38 self._path = tempfile.mkdtemp(**kwargs)
39
40 def __enter__(self):
41 return self._path
42
43 def __exit__(self, type, value, traceback):
44 shutil.rmtree(self._path, ignore_errors=True)
45
46
47 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.
48 diff_lines = []
49 with ScopedTemporaryDirectory() as temporary_directory:
50 deps_contents = open(os.path.join(chromium_src_root, 'DEPS')).read()
51 deps_contents = re.sub(r'"webkit_revision":\s*"\d+"',
52 '"webkit_revision": "HEAD"', deps_contents)
53
54 temporary_deps_path = os.path.join(temporary_directory, 'DEPS')
55 temporary_deps = open(temporary_deps_path, 'wb')
56 temporary_deps.write(deps_contents)
57 temporary_deps.close()
58 try:
59 raw_diff = GIT.Capture(['diff', '-p', '--no-color',
60 '--no-ext-diff', 'DEPS', temporary_deps_path],
61 chromium_src_root)
62 except subprocess2.CalledProcessError, e:
63 raw_diff = e.stdout
64 raw_diff = raw_diff.replace('\n--- a/DEPS', '\n--- DEPS')
65 diff_lines = trychange.GetMungedDiff('', raw_diff.splitlines(True))[0]
66
67 raw_diff = GIT.GenerateDiff(os.path.join(chromium_src_root,
68 'third_party/WebKit'), full_move=True).splitlines(True)
69 diff_lines.extend(trychange.GetMungedDiff('third_party/WebKit',
70 raw_diff)[0])
71
72 open(path_to_write, 'wb').write(''.join(diff_lines))
73
74
75 def addLayoutBotsIfNeeded(argv):
76 for flag in argv:
77 if flag == '--bot' or flag.startswith('--bot='):
78 return argv
79 argv.extend(('--bot', 'linux_layout_rel,mac_layout_rel,win_layout_rel'))
80
81
82 def chromiumSrcRoot():
83 root = GIT.GetCheckoutRoot('.')
84 parent_path, leaf_path = os.path.split(root)
85 if leaf_path == 'WebKit':
86 root = GIT.GetCheckoutRoot(parent_path)
87 return root
88
M-A Ruel 2013/02/07 14:06:17 Two lines
tony 2013/02/11 20:52:46 Done.
89 def main(argv):
90 chromium_src_root = chromiumSrcRoot()
91 os.chdir(chromium_src_root)
92 argv = argv[1:]
93 addLayoutBotsIfNeeded(argv)
94
95 with ScopedTemporaryFile() as diff_file:
96 generateDiff(diff_file, chromium_src_root)
97 args = [
98 '--sub_rep', 'third_party/WebKit',
99 '--root', 'src',
100 '--rietveld_url', 'https://codereview.chromium.org',
101 '-r%s' % GIT.GetGitSvnHeadRev(chromium_src_root),
102 '--diff', diff_file,
103 ]
104 args.extend(argv)
105 cl = git_cl.Changelist()
106 change = cl.GetChange(cl.GetUpstreamBranch(), None)
107 logging.getLogger().handlers = []
108 return trychange.TryChange(args, change,
109 swallow_exception=False, prog='git wktry')
110
111 if __name__ == '__main__':
112 sys.exit(main(sys.argv))
OLDNEW
« git-wktry ('K') | « git-wktry ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698