OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 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 import argparse | 6 import argparse |
7 import collections | 7 import collections |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import re | 10 import re |
(...skipping 14 matching lines...) Expand all Loading... |
25 upload.verbosity = 0 # Errors only. | 25 upload.verbosity = 0 # Errors only. |
26 | 26 |
27 CHROMIUM_GIT_URL = 'https://chromium.googlesource.com/chromium/src.git' | 27 CHROMIUM_GIT_URL = 'https://chromium.googlesource.com/chromium/src.git' |
28 CL_ISSUE_RE = re.compile('^Issue number: ([0-9]+) \((.*)\)$') | 28 CL_ISSUE_RE = re.compile('^Issue number: ([0-9]+) \((.*)\)$') |
29 RIETVELD_URL_RE = re.compile('^https?://(.*)/(.*)') | 29 RIETVELD_URL_RE = re.compile('^https?://(.*)/(.*)') |
30 ROLL_BRANCH_NAME = 'special_angle_roll_branch' | 30 ROLL_BRANCH_NAME = 'special_angle_roll_branch' |
31 TRYJOB_STATUS_SLEEP_SECONDS = 30 | 31 TRYJOB_STATUS_SLEEP_SECONDS = 30 |
32 | 32 |
33 # Use a shell for subcommands on Windows to get a PATH search. | 33 # Use a shell for subcommands on Windows to get a PATH search. |
34 USE_SHELL = sys.platform.startswith('win') | 34 USE_SHELL = sys.platform.startswith('win') |
35 ANGLE_PATH = 'third_party/angle' | 35 ANGLE_PATH = os.path.join('third_party', 'angle') |
36 | 36 |
37 CommitInfo = collections.namedtuple('CommitInfo', ['git_commit', | 37 CommitInfo = collections.namedtuple('CommitInfo', ['git_commit', |
38 'git_repo_url']) | 38 'git_repo_url']) |
39 CLInfo = collections.namedtuple('CLInfo', ['issue', 'url', 'rietveld_server']) | 39 CLInfo = collections.namedtuple('CLInfo', ['issue', 'url', 'rietveld_server']) |
40 | 40 |
| 41 def _PosixPath(path): |
| 42 """Convert a possibly-Windows path to a posix-style path.""" |
| 43 (_, path) = os.path.splitdrive(path) |
| 44 return path.replace(os.sep, '/') |
41 | 45 |
42 def _ParseGitCommitHash(description): | 46 def _ParseGitCommitHash(description): |
43 for line in description.splitlines(): | 47 for line in description.splitlines(): |
44 if line.startswith('commit '): | 48 if line.startswith('commit '): |
45 return line.split()[1] | 49 return line.split()[1] |
46 logging.error('Failed to parse git commit id from:\n%s\n', description) | 50 logging.error('Failed to parse git commit id from:\n%s\n', description) |
47 sys.exit(-1) | 51 sys.exit(-1) |
48 return None | 52 return None |
49 | 53 |
50 | 54 |
51 def _ParseDepsFile(filename): | 55 def _ParseDepsFile(filename): |
52 with open(filename, 'rb') as f: | 56 with open(filename, 'rb') as f: |
53 deps_content = f.read() | 57 deps_content = f.read() |
54 return _ParseDepsDict(deps_content) | 58 return _ParseDepsDict(deps_content) |
55 | 59 |
56 | 60 |
57 def _ParseDepsDict(deps_content): | 61 def _ParseDepsDict(deps_content): |
58 local_scope = {} | 62 local_scope = {} |
59 var = GClientKeywords.VarImpl({}, local_scope) | 63 var = GClientKeywords.VarImpl({}, local_scope) |
60 global_scope = { | 64 global_scope = { |
61 'File': GClientKeywords.FileImpl, | 65 'File': GClientKeywords.FileImpl, |
62 'From': GClientKeywords.FromImpl, | 66 'From': GClientKeywords.FromImpl, |
63 'Var': var.Lookup, | 67 'Var': var.Lookup, |
64 'deps_os': {}, | 68 'deps_os': {}, |
65 } | 69 } |
66 exec(deps_content, global_scope, local_scope) | 70 exec(deps_content, global_scope, local_scope) |
67 return local_scope | 71 return local_scope |
68 | 72 |
69 | 73 |
70 def _GenerateCLDescription(angle_current, angle_new): | 74 def _GenerateCLDescriptionCommand(angle_current, angle_new, bugs): |
71 delim = '' | |
72 angle_str = '' | |
73 def GetChangeString(current_hash, new_hash): | 75 def GetChangeString(current_hash, new_hash): |
74 return '%s..%s' % (current_hash[0:7], new_hash[0:7]); | 76 return '%s..%s' % (current_hash[0:7], new_hash[0:7]); |
75 | 77 |
76 def GetChangeLogURL(git_repo_url, change_string): | 78 def GetChangeLogURL(git_repo_url, change_string): |
77 return '%s/+log/%s' % (git_repo_url, change_string) | 79 return '%s/+log/%s' % (git_repo_url, change_string) |
78 | 80 |
| 81 def GetBugString(bugs): |
| 82 bug_str = 'BUG=' |
| 83 for bug in bugs: |
| 84 bug_str += str(bug) + ',' |
| 85 return bug_str.rstrip(',') |
| 86 |
79 if angle_current.git_commit != angle_new.git_commit: | 87 if angle_current.git_commit != angle_new.git_commit: |
80 change_str = GetChangeString(angle_current.git_commit, | 88 change_str = GetChangeString(angle_current.git_commit, |
81 angle_new.git_commit) | 89 angle_new.git_commit) |
82 changelog_url = GetChangeLogURL(angle_current.git_repo_url, | 90 changelog_url = GetChangeLogURL(angle_current.git_repo_url, |
83 change_str) | 91 change_str) |
84 | 92 |
85 description = 'Roll ANGLE ' + change_str + '\n\n' | 93 return [ |
86 description += '%s\n\n' % changelog_url | 94 '-m', 'Roll ANGLE ' + change_str, |
87 description += 'BUG=\nTEST=bots\n' | 95 '-m', '%s' % changelog_url, |
88 return description | 96 '-m', GetBugString(bugs), |
| 97 '-m', 'TEST=bots', |
| 98 ] |
89 | 99 |
90 | 100 |
91 class AutoRoller(object): | 101 class AutoRoller(object): |
92 def __init__(self, chromium_src): | 102 def __init__(self, chromium_src): |
93 self._chromium_src = chromium_src | 103 self._chromium_src = chromium_src |
94 | 104 |
95 def _RunCommand(self, command, working_dir=None, ignore_exit_code=False, | 105 def _RunCommand(self, command, working_dir=None, ignore_exit_code=False, |
96 extra_env=None): | 106 extra_env=None): |
97 """Runs a command and returns the stdout from that command. | 107 """Runs a command and returns the stdout from that command. |
98 | 108 |
(...skipping 21 matching lines...) Expand all Loading... |
120 def _GetCommitInfo(self, path_below_src, git_hash=None, git_repo_url=None): | 130 def _GetCommitInfo(self, path_below_src, git_hash=None, git_repo_url=None): |
121 working_dir = os.path.join(self._chromium_src, path_below_src) | 131 working_dir = os.path.join(self._chromium_src, path_below_src) |
122 self._RunCommand(['git', 'fetch', 'origin'], working_dir=working_dir) | 132 self._RunCommand(['git', 'fetch', 'origin'], working_dir=working_dir) |
123 revision_range = git_hash or 'origin' | 133 revision_range = git_hash or 'origin' |
124 ret = self._RunCommand( | 134 ret = self._RunCommand( |
125 ['git', '--no-pager', 'log', revision_range, '--pretty=full', '-1'], | 135 ['git', '--no-pager', 'log', revision_range, '--pretty=full', '-1'], |
126 working_dir=working_dir) | 136 working_dir=working_dir) |
127 return CommitInfo(_ParseGitCommitHash(ret), git_repo_url) | 137 return CommitInfo(_ParseGitCommitHash(ret), git_repo_url) |
128 | 138 |
129 def _GetDepsCommitInfo(self, deps_dict, path_below_src): | 139 def _GetDepsCommitInfo(self, deps_dict, path_below_src): |
130 entry = deps_dict['deps']['src/%s' % path_below_src] | 140 entry = deps_dict['deps'][_PosixPath('src/%s' % path_below_src)] |
131 at_index = entry.find('@') | 141 at_index = entry.find('@') |
132 git_repo_url = entry[:at_index] | 142 git_repo_url = entry[:at_index] |
133 git_hash = entry[at_index + 1:] | 143 git_hash = entry[at_index + 1:] |
134 return self._GetCommitInfo(path_below_src, git_hash, git_repo_url) | 144 return self._GetCommitInfo(path_below_src, git_hash, git_repo_url) |
135 | 145 |
136 def _GetCLInfo(self): | 146 def _GetCLInfo(self): |
137 cl_output = self._RunCommand(['git', 'cl', 'issue']) | 147 cl_output = self._RunCommand(['git', 'cl', 'issue']) |
138 m = CL_ISSUE_RE.match(cl_output.strip()) | 148 m = CL_ISSUE_RE.match(cl_output.strip()) |
139 if not m: | 149 if not m: |
140 logging.error('Cannot find any CL info. Output was:\n%s', cl_output) | 150 logging.error('Cannot find any CL info. Output was:\n%s', cl_output) |
(...skipping 15 matching lines...) Expand all Loading... |
156 | 166 |
157 def _IsTreeClean(self): | 167 def _IsTreeClean(self): |
158 lines = self._RunCommand( | 168 lines = self._RunCommand( |
159 ['git', 'status', '--porcelain', '-uno']).splitlines() | 169 ['git', 'status', '--porcelain', '-uno']).splitlines() |
160 if len(lines) == 0: | 170 if len(lines) == 0: |
161 return True | 171 return True |
162 | 172 |
163 logging.debug('Dirty/unversioned files:\n%s', '\n'.join(lines)) | 173 logging.debug('Dirty/unversioned files:\n%s', '\n'.join(lines)) |
164 return False | 174 return False |
165 | 175 |
| 176 def _GetBugList(self, path_below_src, angle_current, angle_new): |
| 177 working_dir = os.path.join(self._chromium_src, path_below_src) |
| 178 lines = self._RunCommand( |
| 179 ['git','log', |
| 180 '%s..%s' % (angle_current.git_commit, angle_new.git_commit)], |
| 181 working_dir=working_dir).split('\n') |
| 182 bugs = set() |
| 183 for line in lines: |
| 184 line = line.strip() |
| 185 bug_prefix = 'BUG=' |
| 186 if line.startswith(bug_prefix): |
| 187 bugs_strings = line[len(bug_prefix):].split(',') |
| 188 for bug_string in bugs_strings: |
| 189 try: |
| 190 bugs.add(int(bug_string)) |
| 191 except: |
| 192 # skip this, it may be a project specific bug such as |
| 193 # "angleproject:X" or an ill-formed BUG= message |
| 194 pass |
| 195 return bugs |
| 196 |
166 def _UpdateReadmeFile(self, readme_path, new_revision): | 197 def _UpdateReadmeFile(self, readme_path, new_revision): |
167 readme = open(os.path.join(self._chromium_src, readme_path), 'r+') | 198 readme = open(os.path.join(self._chromium_src, readme_path), 'r+') |
168 txt = readme.read() | 199 txt = readme.read() |
169 m = re.sub(re.compile('.*^Revision\: ([0-9]*).*', re.MULTILINE), | 200 m = re.sub(re.compile('.*^Revision\: ([0-9]*).*', re.MULTILINE), |
170 ('Revision: %s' % new_revision), txt) | 201 ('Revision: %s' % new_revision), txt) |
171 readme.seek(0) | 202 readme.seek(0) |
172 readme.write(m) | 203 readme.write(m) |
173 readme.truncate() | 204 readme.truncate() |
174 | 205 |
175 def PrepareRoll(self, ignore_checks): | 206 def PrepareRoll(self, ignore_checks): |
(...skipping 20 matching lines...) Expand all Loading... |
196 # Modify Chromium's DEPS file. | 227 # Modify Chromium's DEPS file. |
197 | 228 |
198 # Parse current hashes. | 229 # Parse current hashes. |
199 deps_filename = os.path.join(self._chromium_src, 'DEPS') | 230 deps_filename = os.path.join(self._chromium_src, 'DEPS') |
200 deps = _ParseDepsFile(deps_filename) | 231 deps = _ParseDepsFile(deps_filename) |
201 angle_current = self._GetDepsCommitInfo(deps, ANGLE_PATH) | 232 angle_current = self._GetDepsCommitInfo(deps, ANGLE_PATH) |
202 | 233 |
203 # Find ToT revisions. | 234 # Find ToT revisions. |
204 angle_latest = self._GetCommitInfo(ANGLE_PATH) | 235 angle_latest = self._GetCommitInfo(ANGLE_PATH) |
205 | 236 |
| 237 # Make sure the roll script doesn't use windows line endings |
| 238 self._RunCommand(['git', 'config', 'core.autocrlf', 'true']) |
| 239 |
206 self._UpdateDep(deps_filename, ANGLE_PATH, angle_latest) | 240 self._UpdateDep(deps_filename, ANGLE_PATH, angle_latest) |
207 | 241 |
208 if self._IsTreeClean(): | 242 if self._IsTreeClean(): |
209 logging.debug('Tree is clean - no changes detected.') | 243 logging.debug('Tree is clean - no changes detected.') |
210 self._DeleteRollBranch() | 244 self._DeleteRollBranch() |
211 else: | 245 else: |
212 description = _GenerateCLDescription(angle_current, angle_latest) | 246 bugs = self._GetBugList(ANGLE_PATH, angle_current, angle_latest) |
| 247 description = _GenerateCLDescriptionCommand( |
| 248 angle_current, angle_latest, bugs) |
213 logging.debug('Committing changes locally.') | 249 logging.debug('Committing changes locally.') |
214 self._RunCommand(['git', 'add', '--update', '.']) | 250 self._RunCommand(['git', 'add', '--update', '.']) |
215 self._RunCommand(['git', 'commit', '-m', description]) | 251 self._RunCommand(['git', 'commit'] + description) |
216 logging.debug('Uploading changes...') | 252 logging.debug('Uploading changes...') |
217 self._RunCommand(['git', 'cl', 'upload', '-m', description], | 253 self._RunCommand(['git', 'cl', 'upload'], |
218 extra_env={'EDITOR': 'true'}) | 254 extra_env={'EDITOR': 'true'}) |
| 255 self._RunCommand(['git', 'cl', 'try']) |
219 cl_info = self._GetCLInfo() | 256 cl_info = self._GetCLInfo() |
220 print 'Issue: %d URL: %s' % (cl_info.issue, cl_info.url) | 257 print 'Issue: %d URL: %s' % (cl_info.issue, cl_info.url) |
221 | 258 |
222 # Checkout master again. | 259 # Checkout master again. |
223 self._RunCommand(['git', 'checkout', 'master']) | 260 self._RunCommand(['git', 'checkout', 'master']) |
224 print 'Roll branch left as ' + ROLL_BRANCH_NAME | 261 print 'Roll branch left as ' + ROLL_BRANCH_NAME |
225 return 0 | 262 return 0 |
226 | 263 |
227 def _UpdateDep(self, deps_filename, dep_relative_to_src, commit_info): | 264 def _UpdateDep(self, deps_filename, dep_relative_to_src, commit_info): |
228 dep_name = os.path.join('src', dep_relative_to_src) | 265 dep_name = _PosixPath(os.path.join('src', dep_relative_to_src)) |
229 | 266 |
230 # roll_dep_svn.py relies on cwd being the Chromium checkout, so let's | 267 # roll_dep_svn.py relies on cwd being the Chromium checkout, so let's |
231 # temporarily change the working directory and then change back. | 268 # temporarily change the working directory and then change back. |
232 cwd = os.getcwd() | 269 cwd = os.getcwd() |
233 os.chdir(os.path.dirname(deps_filename)) | 270 os.chdir(os.path.dirname(deps_filename)) |
234 roll_dep_svn.update_deps(deps_filename, dep_relative_to_src, dep_name, | 271 roll_dep_svn.update_deps(deps_filename, dep_relative_to_src, dep_name, |
235 commit_info.git_commit, '') | 272 commit_info.git_commit, '') |
236 os.chdir(cwd) | 273 os.chdir(cwd) |
237 | 274 |
238 def _DeleteRollBranch(self): | 275 def _DeleteRollBranch(self): |
(...skipping 30 matching lines...) Expand all Loading... |
269 print 'Aborting pending roll.' | 306 print 'Aborting pending roll.' |
270 self._RunCommand(['git', 'checkout', ROLL_BRANCH_NAME]) | 307 self._RunCommand(['git', 'checkout', ROLL_BRANCH_NAME]) |
271 # Ignore an error here in case an issue wasn't created for some reason. | 308 # Ignore an error here in case an issue wasn't created for some reason. |
272 self._RunCommand(['git', 'cl', 'set_close'], ignore_exit_code=True) | 309 self._RunCommand(['git', 'cl', 'set_close'], ignore_exit_code=True) |
273 self._RunCommand(['git', 'checkout', active_branch]) | 310 self._RunCommand(['git', 'checkout', active_branch]) |
274 self._RunCommand(['git', 'branch', '-D', ROLL_BRANCH_NAME]) | 311 self._RunCommand(['git', 'branch', '-D', ROLL_BRANCH_NAME]) |
275 return 0 | 312 return 0 |
276 | 313 |
277 | 314 |
278 def main(): | 315 def main(): |
279 if sys.platform in ('win32', 'cygwin'): | |
280 logging.error('Only Linux and Mac platforms are supported right now.') | |
281 return -1 | |
282 | |
283 parser = argparse.ArgumentParser( | 316 parser = argparse.ArgumentParser( |
284 description='Auto-generates a CL containing an ANGLE roll.') | 317 description='Auto-generates a CL containing an ANGLE roll.') |
285 parser.add_argument('--abort', | 318 parser.add_argument('--abort', |
286 help=('Aborts a previously prepared roll. ' | 319 help=('Aborts a previously prepared roll. ' |
287 'Closes any associated issues and deletes the roll branches'), | 320 'Closes any associated issues and deletes the roll branches'), |
288 action='store_true') | 321 action='store_true') |
289 parser.add_argument('--ignore-checks', action='store_true', default=False, | 322 parser.add_argument('--ignore-checks', action='store_true', default=False, |
290 help=('Skips checks for being on the master branch, dirty workspaces and ' | 323 help=('Skips checks for being on the master branch, dirty workspaces and ' |
291 'the updating of the checkout. Will still delete and create local ' | 324 'the updating of the checkout. Will still delete and create local ' |
292 'Git branches.')) | 325 'Git branches.')) |
293 parser.add_argument('-v', '--verbose', action='store_true', default=False, | 326 parser.add_argument('-v', '--verbose', action='store_true', default=False, |
294 help='Be extra verbose in printing of log messages.') | 327 help='Be extra verbose in printing of log messages.') |
295 args = parser.parse_args() | 328 args = parser.parse_args() |
296 | 329 |
297 if args.verbose: | 330 if args.verbose: |
298 logging.basicConfig(level=logging.DEBUG) | 331 logging.basicConfig(level=logging.DEBUG) |
299 else: | 332 else: |
300 logging.basicConfig(level=logging.ERROR) | 333 logging.basicConfig(level=logging.ERROR) |
301 | 334 |
302 autoroller = AutoRoller(SRC_DIR) | 335 autoroller = AutoRoller(SRC_DIR) |
303 if args.abort: | 336 if args.abort: |
304 return autoroller.Abort() | 337 return autoroller.Abort() |
305 else: | 338 else: |
306 return autoroller.PrepareRoll(args.ignore_checks) | 339 return autoroller.PrepareRoll(args.ignore_checks) |
307 | 340 |
308 if __name__ == '__main__': | 341 if __name__ == '__main__': |
309 sys.exit(main()) | 342 sys.exit(main()) |
OLD | NEW |