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

Side by Side Diff: tools/safely-roll-blink.py

Issue 510343002: Fix Blink roll script to handle git revisions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Generate a CL to roll Blink to the specified revision number and post 6 """Generate a CL to roll Blink to the specified revision number and post
7 it to Rietveld so that the CL will land automatically if it passes the 7 it to Rietveld so that the CL will land automatically if it passes the
8 commit-queue's checks. 8 commit-queue's checks.
9 """ 9 """
10 10
(...skipping 12 matching lines...) Expand all
23 print >> sys.stderr, msg 23 print >> sys.stderr, msg
24 sys.exit(1) 24 sys.exit(1)
25 25
26 26
27 def process_deps(path, new_rev, is_dry_run): 27 def process_deps(path, new_rev, is_dry_run):
28 """Update webkit_revision to |new_issue|. 28 """Update webkit_revision to |new_issue|.
29 29
30 A bit hacky, could it be made better? 30 A bit hacky, could it be made better?
31 """ 31 """
32 content = open(path).read() 32 content = open(path).read()
33 old_line = r'(\s+)"webkit_revision": "(\d+)",' 33 old_line = r"(\s+)'webkit_revision': '([a-f0-9]{40})',"
34 new_line = r'\1"webkit_revision": "%d",' % new_rev 34 new_line = r"\1'webkit_revision': '%s'," % new_rev
35 new_content = re.sub(old_line, new_line, content, 1) 35 new_content = re.sub(old_line, new_line, content, 1)
36 old_rev = re.search(old_line, content).group(2) 36 old_rev = re.search(old_line, content).group(2)
37 if not old_rev or new_content == content: 37 if not old_rev or new_content == content:
38 die_with_error('Failed to update the DEPS file') 38 die_with_error('Failed to update the DEPS file')
39 39
40 if not is_dry_run: 40 if not is_dry_run:
41 open(path, 'w').write(new_content) 41 open(path, 'w').write(new_content)
42 return old_rev 42 return old_rev
43 43
44 44
45 def get_svn_rev_from_git_rev(git_rev):
46 """Return the svn revision associated with the Blink git revision."""
47
48 os.chdir("third_party/WebKit/")
49 log = subprocess2.check_output(['git', 'log', git_rev, '-n', '1'])
50 rev_line = r"\s+git-svn-id: svn://svn.chromium.org/blink/trunk@(\d+)"
51 os.chdir("../..")
52
53 return int(re.search(rev_line, log).group(1))
54
45 def main(): 55 def main():
46 tool_dir = os.path.dirname(os.path.abspath(__file__)) 56 tool_dir = os.path.dirname(os.path.abspath(__file__))
47 parser = optparse.OptionParser(usage='%prog [options] <new blink rev>') 57 parser = optparse.OptionParser(usage='%prog [options] <new blink git rev>')
48 parser.add_option('-v', '--verbose', action='count', default=0) 58 parser.add_option('-v', '--verbose', action='count', default=0)
49 parser.add_option('--dry-run', action='store_true') 59 parser.add_option('--dry-run', action='store_true')
50 parser.add_option('--commit', action='store_true', default=True, 60 parser.add_option('--commit', action='store_true', default=True,
51 help='(default) Put change in commit queue on upload.') 61 help='(default) Put change in commit queue on upload.')
52 parser.add_option('--no-commit', action='store_false', dest='commit', 62 parser.add_option('--no-commit', action='store_false', dest='commit',
53 help='Don\'t put change in commit queue on upload.') 63 help='Don\'t put change in commit queue on upload.')
54 parser.add_option('-r', '--reviewers', default='', 64 parser.add_option('-r', '--reviewers', default='',
55 help='Add given users as either reviewers or TBR as' 65 help='Add given users as either reviewers or TBR as'
56 ' appropriate.') 66 ' appropriate.')
57 parser.add_option('--upstream', default='origin/master', 67 parser.add_option('--upstream', default='origin/master',
58 help='(default "%default") Use given start point for change' 68 help='(default "%default") Use given start point for change'
59 ' to upload. For instance, if you use the old git workflow,' 69 ' to upload. For instance, if you use the old git workflow,'
60 ' you might set it to "origin/trunk".') 70 ' you might set it to "origin/trunk".')
61 parser.add_option('--cc', help='CC email addresses for issue.') 71 parser.add_option('--cc', help='CC email addresses for issue.')
62 72
63 options, args = parser.parse_args() 73 options, args = parser.parse_args()
64 logging.basicConfig( 74 logging.basicConfig(
65 level= 75 level=
66 [logging.WARNING, logging.INFO, logging.DEBUG][ 76 [logging.WARNING, logging.INFO, logging.DEBUG][
67 min(2, options.verbose)]) 77 min(2, options.verbose)])
68 if len(args) != 1: 78 if len(args) != 1:
69 parser.print_help() 79 parser.print_help()
70 exit(0) 80 exit(0)
71 81
72 root_dir = os.path.dirname(tool_dir) 82 root_dir = os.path.dirname(tool_dir)
73 os.chdir(root_dir) 83 os.chdir(root_dir)
74 84
75 new_rev = int(args[0]) 85 new_git_rev = args[0]
76 86
77 # Silence the editor. 87 # Silence the editor.
78 os.environ['EDITOR'] = 'true' 88 os.environ['EDITOR'] = 'true'
79 89
80 old_branch = scm.GIT.GetBranch(root_dir) 90 old_branch = scm.GIT.GetBranch(root_dir)
81 if old_branch == 'blink_roll': 91 if old_branch == 'blink_roll':
82 parser.error( 92 parser.error(
83 'Please delete the branch blink_roll and move to a different branch') 93 'Please delete the branch blink_roll and move to a different branch')
84 94
85 if not options.dry_run: 95 if not options.dry_run:
86 subprocess2.check_output( 96 subprocess2.check_output(
87 ['git', 'checkout', '-b', 'blink_roll', options.upstream]) 97 ['git', 'checkout', '-b', 'blink_roll', options.upstream])
88 98
89 try: 99 try:
90 old_rev = int(process_deps(os.path.join(root_dir, 'DEPS'), new_rev, 100 old_git_rev = process_deps(os.path.join(root_dir, 'DEPS'), new_git_rev,
91 options.dry_run)) 101 options.dry_run)
92 print 'Blink roll %s:%s' % (old_rev, new_rev) 102
103 new_svn_rev = get_svn_rev_from_git_rev(new_git_rev)
104 old_svn_rev = get_svn_rev_from_git_rev(old_git_rev)
105
106 print 'Blink roll %s:%s' % (old_svn_rev, new_svn_rev)
93 107
94 review_field = 'TBR' if options.commit else 'R' 108 review_field = 'TBR' if options.commit else 'R'
95 commit_msg = ('Blink roll %s:%s\n' 109 commit_msg = ('Blink roll %s:%s\n'
96 '\n' 110 '\n'
97 'http://build.chromium.org/f/chromium/perf/dashboard/ui/' 111 'http://build.chromium.org/f/chromium/perf/dashboard/ui/'
98 'changelog_blink.html?url=/trunk&range=%s:%s&mode=html' 112 'changelog_blink.html?url=/trunk&range=%s:%s&mode=html'
99 '\n' 113 '\n'
100 '%s=%s\n' % (old_rev, new_rev, 114 '%s=%s\n' % (old_svn_rev, new_svn_rev,
101 old_rev+1, new_rev, 115 old_svn_rev+1, new_svn_rev,
102 review_field, 116 review_field,
103 options.reviewers)) 117 options.reviewers))
104 118
105 if options.dry_run: 119 if options.dry_run:
106 print 'Commit message: ' + commit_msg 120 print 'Commit message: ' + commit_msg
107 return 0 121 return 0
108 122
109 subprocess2.check_output(['git', 'commit', '-m', commit_msg, 'DEPS']) 123 subprocess2.check_output(['git', 'commit', '-m', commit_msg, 'DEPS'])
110 subprocess2.check_call(['git', 'diff', options.upstream]) 124 subprocess2.check_call(['git', 'diff', options.upstream])
111 upload_cmd = ['git', 'cl', 'upload'] 125 upload_cmd = ['git', 'cl', 'upload']
112 if options.commit: 126 if options.commit:
113 upload_cmd.append('--use-commit-queue') 127 upload_cmd.append('--use-commit-queue')
114 if options.reviewers: 128 if options.reviewers:
115 upload_cmd.append('--send-mail') 129 upload_cmd.append('--send-mail')
116 if options.cc: 130 if options.cc:
117 upload_cmd.extend(['--cc', options.cc]) 131 upload_cmd.extend(['--cc', options.cc])
118 subprocess2.check_call(upload_cmd) 132 subprocess2.check_call(upload_cmd)
119 finally: 133 finally:
120 if not options.dry_run: 134 if not options.dry_run:
121 subprocess2.check_output(['git', 'checkout', old_branch]) 135 subprocess2.check_output(['git', 'checkout', old_branch])
122 subprocess2.check_output(['git', 'branch', '-D', 'blink_roll']) 136 subprocess2.check_output(['git', 'branch', '-D', 'blink_roll'])
123 return 0 137 return 0
124 138
125 139
126 if __name__ == '__main__': 140 if __name__ == '__main__':
127 sys.exit(main()) 141 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698