OLD | NEW |
| (Empty) |
1 #!/usr/bin/python | |
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
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 sys | |
11 import tempfile | |
12 | |
13 import git_cl | |
14 from scm import GIT | |
15 import trychange | |
16 | |
17 | |
18 class ScopedTemporaryFile(object): | |
19 def __init__(self, **kwargs): | |
20 file_handle, self._path = tempfile.mkstemp(**kwargs) | |
21 os.close(file_handle) | |
22 | |
23 def __enter__(self): | |
24 return self._path | |
25 | |
26 def __exit__(self, _exc_type, _exc_value, _exc_traceback): | |
27 try: | |
28 os.remove(self._path) | |
29 except OSError, e: | |
30 if e.errno != errno.ENOENT: | |
31 raise e | |
32 | |
33 | |
34 def generateDiff(path_to_write, chromium_src_root): | |
35 """Create the diff file to send to the try server. We prepend the WebKit | |
36 revision to the beginning of the diff so we can patch against ToT or other | |
37 versions of WebKit.""" | |
38 diff_lines = ['third_party/WebKit@HEAD\n'] | |
39 | |
40 raw_diff = GIT.GenerateDiff(os.path.join(chromium_src_root, | |
41 'third_party/WebKit'), full_move=True).splitlines(True) | |
42 diff_lines.extend(trychange.GetMungedDiff('third_party/WebKit', | |
43 raw_diff)[0]) | |
44 | |
45 open(path_to_write, 'wb').write(''.join(diff_lines)) | |
46 | |
47 | |
48 def addLayoutBotsIfNeeded(argv): | |
49 for flag in argv: | |
50 if flag == '--bot' or flag.startswith('--bot=') or flag.startswith('-b'): | |
51 return argv | |
52 argv.extend(('--bot', 'linux_layout_rel,mac_layout_rel,win_layout_rel')) | |
53 | |
54 | |
55 def chromiumSrcRoot(): | |
56 root = GIT.GetCheckoutRoot('.') | |
57 parent_path, leaf_path = os.path.split(root) | |
58 if leaf_path == 'WebKit': | |
59 root = GIT.GetCheckoutRoot(parent_path) | |
60 return root | |
61 | |
62 | |
63 def main(argv): | |
64 chromium_src_root = chromiumSrcRoot() | |
65 os.chdir(chromium_src_root) | |
66 argv = argv[1:] | |
67 addLayoutBotsIfNeeded(argv) | |
68 | |
69 with ScopedTemporaryFile() as diff_file: | |
70 generateDiff(diff_file, chromium_src_root) | |
71 args = [ | |
72 '--sub_rep', 'third_party/WebKit', | |
73 '--root', 'src', | |
74 '--rietveld_url', 'https://codereview.chromium.org', | |
75 '--diff', diff_file, | |
76 ] | |
77 args.extend(argv) | |
78 cl = git_cl.Changelist() | |
79 change = cl.GetChange(cl.GetUpstreamBranch(), None) | |
80 logging.getLogger().handlers = [] | |
81 return trychange.TryChange(args, change, | |
82 swallow_exception=False, prog='git wktry') | |
83 | |
84 | |
85 if __name__ == '__main__': | |
86 sys.exit(main(sys.argv)) | |
OLD | NEW |