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

Side by Side Diff: tools/push-to-trunk/push_to_trunk.py

Issue 607463002: Refactoring: Extract interface for VC in release scripts. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review. Created 6 years, 2 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
« no previous file with comments | « tools/push-to-trunk/merge_to_branch.py ('k') | tools/push-to-trunk/releases.py » ('j') | 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 2013 the V8 project authors. All rights reserved. 2 # Copyright 2013 the V8 project authors. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following 10 # copyright notice, this list of conditions and the following
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 print "Warning: Script started on branch %s" % self["current_branch"] 49 print "Warning: Script started on branch %s" % self["current_branch"]
50 50
51 self.PrepareBranch() 51 self.PrepareBranch()
52 self.DeleteBranch(self.Config("TRUNKBRANCH")) 52 self.DeleteBranch(self.Config("TRUNKBRANCH"))
53 53
54 54
55 class FreshBranch(Step): 55 class FreshBranch(Step):
56 MESSAGE = "Create a fresh branch." 56 MESSAGE = "Create a fresh branch."
57 57
58 def RunStep(self): 58 def RunStep(self):
59 self.GitCreateBranch(self.Config("BRANCHNAME"), "svn/bleeding_edge") 59 self.GitCreateBranch(self.Config("BRANCHNAME"),
60 self.vc.RemoteMasterBranch())
60 61
61 62
62 class PreparePushRevision(Step): 63 class PreparePushRevision(Step):
63 MESSAGE = "Check which revision to push." 64 MESSAGE = "Check which revision to push."
64 65
65 def RunStep(self): 66 def RunStep(self):
66 if self._options.revision: 67 if self._options.revision:
67 self["push_hash"] = self.GitSVNFindGitHash(self._options.revision) 68 self["push_hash"] = self.vc.SvnGit(self._options.revision)
68 else: 69 else:
69 self["push_hash"] = self.GitLog(n=1, format="%H", git_hash="HEAD") 70 self["push_hash"] = self.GitLog(n=1, format="%H", git_hash="HEAD")
70 if not self["push_hash"]: # pragma: no cover 71 if not self["push_hash"]: # pragma: no cover
71 self.Die("Could not determine the git hash for the push.") 72 self.Die("Could not determine the git hash for the push.")
72 73
73 74
74 class DetectLastPush(Step): 75 class DetectLastPush(Step):
75 MESSAGE = "Detect commit ID of last push to trunk." 76 MESSAGE = "Detect commit ID of last push to trunk."
76 77
77 def RunStep(self): 78 def RunStep(self):
(...skipping 10 matching lines...) Expand all
88 # option. 89 # option.
89 last_push_bleeding_edge = self._options.last_bleeding_edge 90 last_push_bleeding_edge = self._options.last_bleeding_edge
90 else: 91 else:
91 # Retrieve the bleeding edge revision of the last push from the text in 92 # Retrieve the bleeding edge revision of the last push from the text in
92 # the push commit message. 93 # the push commit message.
93 last_push_title = self.GitLog(n=1, format="%s", git_hash=last_push) 94 last_push_title = self.GitLog(n=1, format="%s", git_hash=last_push)
94 last_push_be_svn = PUSH_MESSAGE_RE.match(last_push_title).group(1) 95 last_push_be_svn = PUSH_MESSAGE_RE.match(last_push_title).group(1)
95 if not last_push_be_svn: # pragma: no cover 96 if not last_push_be_svn: # pragma: no cover
96 self.Die("Could not retrieve bleeding edge revision for trunk push %s" 97 self.Die("Could not retrieve bleeding edge revision for trunk push %s"
97 % last_push) 98 % last_push)
98 last_push_bleeding_edge = self.GitSVNFindGitHash(last_push_be_svn) 99 last_push_bleeding_edge = self.vc.SvnGit(last_push_be_svn)
99 if not last_push_bleeding_edge: # pragma: no cover 100 if not last_push_bleeding_edge: # pragma: no cover
100 self.Die("Could not retrieve bleeding edge git hash for trunk push %s" 101 self.Die("Could not retrieve bleeding edge git hash for trunk push %s"
101 % last_push) 102 % last_push)
102 103
103 # This points to the svn revision of the last push on trunk. 104 # This points to the svn revision of the last push on trunk.
104 self["last_push_trunk"] = last_push 105 self["last_push_trunk"] = last_push
105 # This points to the last bleeding_edge revision that went into the last 106 # This points to the last bleeding_edge revision that went into the last
106 # push. 107 # push.
107 # TODO(machenbach): Do we need a check to make sure we're not pushing a 108 # TODO(machenbach): Do we need a check to make sure we're not pushing a
108 # revision older than the last push? If we do this, the output of the 109 # revision older than the last push? If we do this, the output of the
109 # current change log preparation won't make much sense. 110 # current change log preparation won't make much sense.
110 self["last_push_bleeding_edge"] = last_push_bleeding_edge 111 self["last_push_bleeding_edge"] = last_push_bleeding_edge
111 112
112 113
113 # TODO(machenbach): Code similarities with bump_up_version.py. Merge after 114 # TODO(machenbach): Code similarities with bump_up_version.py. Merge after
114 # turning this script into a pure git script. 115 # turning this script into a pure git script.
115 class GetCurrentBleedingEdgeVersion(Step): 116 class GetCurrentBleedingEdgeVersion(Step):
116 MESSAGE = "Get latest bleeding edge version." 117 MESSAGE = "Get latest bleeding edge version."
117 118
118 def RunStep(self): 119 def RunStep(self):
119 self.GitCheckoutFile(VERSION_FILE, "svn/bleeding_edge") 120 self.GitCheckoutFile(VERSION_FILE, self.vc.RemoteMasterBranch())
120 121
121 # Store latest version. 122 # Store latest version.
122 self.ReadAndPersistVersion("latest_") 123 self.ReadAndPersistVersion("latest_")
123 self["latest_version"] = self.ArrayToVersion("latest_") 124 self["latest_version"] = self.ArrayToVersion("latest_")
124 print "Bleeding edge version: %s" % self["latest_version"] 125 print "Bleeding edge version: %s" % self["latest_version"]
125 126
126 127
127 class IncrementVersion(Step): 128 class IncrementVersion(Step):
128 MESSAGE = "Increment version number." 129 MESSAGE = "Increment version number."
129 130
130 def RunStep(self): 131 def RunStep(self):
131 # Retrieve current version from last trunk push. 132 # Retrieve current version from last trunk push.
132 self.GitCheckoutFile(VERSION_FILE, self["last_push_trunk"]) 133 self.GitCheckoutFile(VERSION_FILE, self["last_push_trunk"])
133 self.ReadAndPersistVersion() 134 self.ReadAndPersistVersion()
134 self["trunk_version"] = self.ArrayToVersion("") 135 self["trunk_version"] = self.ArrayToVersion("")
135 136
136 if self["latest_build"] == "9999": # pragma: no cover 137 if self["latest_build"] == "9999": # pragma: no cover
137 # If version control on bleeding edge was switched off, just use the last 138 # If version control on bleeding edge was switched off, just use the last
138 # trunk version. 139 # trunk version.
139 self["latest_version"] = self["trunk_version"] 140 self["latest_version"] = self["trunk_version"]
140 141
141 if SortingKey(self["trunk_version"]) < SortingKey(self["latest_version"]): 142 if SortingKey(self["trunk_version"]) < SortingKey(self["latest_version"]):
142 # If the version on bleeding_edge is newer than on trunk, use it. 143 # If the version on bleeding_edge is newer than on trunk, use it.
143 self.GitCheckoutFile(VERSION_FILE, "svn/bleeding_edge") 144 self.GitCheckoutFile(VERSION_FILE, self.vc.RemoteMasterBranch())
144 self.ReadAndPersistVersion() 145 self.ReadAndPersistVersion()
145 146
146 if self.Confirm(("Automatically increment BUILD_NUMBER? (Saying 'n' will " 147 if self.Confirm(("Automatically increment BUILD_NUMBER? (Saying 'n' will "
147 "fire up your EDITOR on %s so you can make arbitrary " 148 "fire up your EDITOR on %s so you can make arbitrary "
148 "changes. When you're done, save the file and exit your " 149 "changes. When you're done, save the file and exit your "
149 "EDITOR.)" % VERSION_FILE)): 150 "EDITOR.)" % VERSION_FILE)):
150 151
151 text = FileToText(os.path.join(self.default_cwd, VERSION_FILE)) 152 text = FileToText(os.path.join(self.default_cwd, VERSION_FILE))
152 text = MSub(r"(?<=#define BUILD_NUMBER)(?P<space>\s+)\d*$", 153 text = MSub(r"(?<=#define BUILD_NUMBER)(?P<space>\s+)\d*$",
153 r"\g<space>%s" % str(int(self["build"]) + 1), 154 r"\g<space>%s" % str(int(self["build"]) + 1),
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 243
243 # Safe new change log for adding it later to the trunk patch. 244 # Safe new change log for adding it later to the trunk patch.
244 TextToFile(changelog_entry, self.Config("CHANGELOG_ENTRY_FILE")) 245 TextToFile(changelog_entry, self.Config("CHANGELOG_ENTRY_FILE"))
245 246
246 247
247 class StragglerCommits(Step): 248 class StragglerCommits(Step):
248 MESSAGE = ("Fetch straggler commits that sneaked in since this script was " 249 MESSAGE = ("Fetch straggler commits that sneaked in since this script was "
249 "started.") 250 "started.")
250 251
251 def RunStep(self): 252 def RunStep(self):
252 self.GitSVNFetch() 253 self.vc.Fetch()
253 self.GitCheckout("svn/bleeding_edge") 254 self.GitCheckout(self.vc.RemoteMasterBranch())
254 255
255 256
256 class SquashCommits(Step): 257 class SquashCommits(Step):
257 MESSAGE = "Squash commits into one." 258 MESSAGE = "Squash commits into one."
258 259
259 def RunStep(self): 260 def RunStep(self):
260 # Instead of relying on "git rebase -i", we'll just create a diff, because 261 # Instead of relying on "git rebase -i", we'll just create a diff, because
261 # that's easier to automate. 262 # that's easier to automate.
262 TextToFile(self.GitDiff("svn/trunk", self["push_hash"]), 263 TextToFile(self.GitDiff(self.vc.RemoteCandidateBranch(),
264 self["push_hash"]),
263 self.Config("PATCH_FILE")) 265 self.Config("PATCH_FILE"))
264 266
265 # Convert the ChangeLog entry to commit message format. 267 # Convert the ChangeLog entry to commit message format.
266 text = FileToText(self.Config("CHANGELOG_ENTRY_FILE")) 268 text = FileToText(self.Config("CHANGELOG_ENTRY_FILE"))
267 269
268 # Remove date and trailing white space. 270 # Remove date and trailing white space.
269 text = re.sub(r"^%s: " % self["date"], "", text.rstrip()) 271 text = re.sub(r"^%s: " % self["date"], "", text.rstrip())
270 272
271 # Retrieve svn revision for showing the used bleeding edge revision in the 273 # Retrieve svn revision for showing the used bleeding edge revision in the
272 # commit message. 274 # commit message.
273 self["svn_revision"] = self.GitSVNFindSVNRev(self["push_hash"]) 275 self["svn_revision"] = self.vc.GitSvn(self["push_hash"])
274 suffix = PUSH_MESSAGE_SUFFIX % int(self["svn_revision"]) 276 suffix = PUSH_MESSAGE_SUFFIX % int(self["svn_revision"])
275 text = MSub(r"^(Version \d+\.\d+\.\d+)$", "\\1%s" % suffix, text) 277 text = MSub(r"^(Version \d+\.\d+\.\d+)$", "\\1%s" % suffix, text)
276 278
277 # Remove indentation and merge paragraphs into single long lines, keeping 279 # Remove indentation and merge paragraphs into single long lines, keeping
278 # empty lines between them. 280 # empty lines between them.
279 def SplitMapJoin(split_text, fun, join_text): 281 def SplitMapJoin(split_text, fun, join_text):
280 return lambda text: join_text.join(map(fun, text.split(split_text))) 282 return lambda text: join_text.join(map(fun, text.split(split_text)))
281 strip = lambda line: line.strip() 283 strip = lambda line: line.strip()
282 text = SplitMapJoin("\n\n", SplitMapJoin("\n", strip, " "), "\n\n")(text) 284 text = SplitMapJoin("\n\n", SplitMapJoin("\n", strip, " "), "\n\n")(text)
283 285
284 if not text: # pragma: no cover 286 if not text: # pragma: no cover
285 self.Die("Commit message editing failed.") 287 self.Die("Commit message editing failed.")
286 TextToFile(text, self.Config("COMMITMSG_FILE")) 288 TextToFile(text, self.Config("COMMITMSG_FILE"))
287 289
288 290
289 class NewBranch(Step): 291 class NewBranch(Step):
290 MESSAGE = "Create a new branch from trunk." 292 MESSAGE = "Create a new branch from trunk."
291 293
292 def RunStep(self): 294 def RunStep(self):
293 self.GitCreateBranch(self.Config("TRUNKBRANCH"), "svn/trunk") 295 self.GitCreateBranch(self.Config("TRUNKBRANCH"),
296 self.vc.RemoteCandidateBranch())
294 297
295 298
296 class ApplyChanges(Step): 299 class ApplyChanges(Step):
297 MESSAGE = "Apply squashed changes." 300 MESSAGE = "Apply squashed changes."
298 301
299 def RunStep(self): 302 def RunStep(self):
300 self.ApplyPatch(self.Config("PATCH_FILE")) 303 self.ApplyPatch(self.Config("PATCH_FILE"))
301 os.remove(self.Config("PATCH_FILE")) 304 os.remove(self.Config("PATCH_FILE"))
302 305
303 306
304 class AddChangeLog(Step): 307 class AddChangeLog(Step):
305 MESSAGE = "Add ChangeLog changes to trunk branch." 308 MESSAGE = "Add ChangeLog changes to trunk branch."
306 309
307 def RunStep(self): 310 def RunStep(self):
308 # The change log has been modified by the patch. Reset it to the version 311 # The change log has been modified by the patch. Reset it to the version
309 # on trunk and apply the exact changes determined by this PrepareChangeLog 312 # on trunk and apply the exact changes determined by this PrepareChangeLog
310 # step above. 313 # step above.
311 self.GitCheckoutFile(self.Config("CHANGELOG_FILE"), "svn/trunk") 314 self.GitCheckoutFile(self.Config("CHANGELOG_FILE"),
315 self.vc.RemoteCandidateBranch())
312 changelog_entry = FileToText(self.Config("CHANGELOG_ENTRY_FILE")) 316 changelog_entry = FileToText(self.Config("CHANGELOG_ENTRY_FILE"))
313 old_change_log = FileToText(self.Config("CHANGELOG_FILE")) 317 old_change_log = FileToText(self.Config("CHANGELOG_FILE"))
314 new_change_log = "%s\n\n\n%s" % (changelog_entry, old_change_log) 318 new_change_log = "%s\n\n\n%s" % (changelog_entry, old_change_log)
315 TextToFile(new_change_log, self.Config("CHANGELOG_FILE")) 319 TextToFile(new_change_log, self.Config("CHANGELOG_FILE"))
316 os.remove(self.Config("CHANGELOG_ENTRY_FILE")) 320 os.remove(self.Config("CHANGELOG_ENTRY_FILE"))
317 321
318 322
319 class SetVersion(Step): 323 class SetVersion(Step):
320 MESSAGE = "Set correct version for trunk." 324 MESSAGE = "Set correct version for trunk."
321 325
322 def RunStep(self): 326 def RunStep(self):
323 # The version file has been modified by the patch. Reset it to the version 327 # The version file has been modified by the patch. Reset it to the version
324 # on trunk and apply the correct version. 328 # on trunk and apply the correct version.
325 self.GitCheckoutFile(VERSION_FILE, "svn/trunk") 329 self.GitCheckoutFile(VERSION_FILE, self.vc.RemoteCandidateBranch())
326 self.SetVersion(os.path.join(self.default_cwd, VERSION_FILE), "new_") 330 self.SetVersion(os.path.join(self.default_cwd, VERSION_FILE), "new_")
327 331
328 332
329 class CommitTrunk(Step): 333 class CommitTrunk(Step):
330 MESSAGE = "Commit to local trunk branch." 334 MESSAGE = "Commit to local trunk branch."
331 335
332 def RunStep(self): 336 def RunStep(self):
333 self.GitCommit(file_name = self.Config("COMMITMSG_FILE")) 337 self.GitCommit(file_name = self.Config("COMMITMSG_FILE"))
334 os.remove(self.Config("COMMITMSG_FILE")) 338 os.remove(self.Config("COMMITMSG_FILE"))
335 339
336 340
337 class SanityCheck(Step): 341 class SanityCheck(Step):
338 MESSAGE = "Sanity check." 342 MESSAGE = "Sanity check."
339 343
340 def RunStep(self): 344 def RunStep(self):
341 # TODO(machenbach): Run presubmit script here as it is now missing in the 345 # TODO(machenbach): Run presubmit script here as it is now missing in the
342 # prepare push process. 346 # prepare push process.
343 if not self.Confirm("Please check if your local checkout is sane: Inspect " 347 if not self.Confirm("Please check if your local checkout is sane: Inspect "
344 "%s, compile, run tests. Do you want to commit this new trunk " 348 "%s, compile, run tests. Do you want to commit this new trunk "
345 "revision to the repository?" % VERSION_FILE): 349 "revision to the repository?" % VERSION_FILE):
346 self.Die("Execution canceled.") # pragma: no cover 350 self.Die("Execution canceled.") # pragma: no cover
347 351
348 352
349 class CommitSVN(Step): 353 class CommitSVN(Step):
350 MESSAGE = "Commit to SVN." 354 MESSAGE = "Commit to SVN."
351 355
352 def RunStep(self): 356 def RunStep(self):
353 result = self.GitSVNDCommit() 357 result = self.vc.Land()
358 # TODO(machenbach): Remove/improve this logic before the git switch.
354 if not result: # pragma: no cover 359 if not result: # pragma: no cover
355 self.Die("'git svn dcommit' failed.") 360 self.Die("'git svn dcommit' failed.")
356 result = filter(lambda x: re.search(r"^Committed r[0-9]+", x), 361 result = filter(lambda x: re.search(r"^Committed r[0-9]+", x),
357 result.splitlines()) 362 result.splitlines())
358 if len(result) > 0: 363 if len(result) > 0:
359 self["trunk_revision"] = re.sub(r"^Committed r([0-9]+)", r"\1",result[0]) 364 self["trunk_revision"] = re.sub(r"^Committed r([0-9]+)", r"\1",result[0])
360 365
361 # Sometimes grepping for the revision fails. No idea why. If you figure 366 # Sometimes grepping for the revision fails. No idea why. If you figure
362 # out why it is flaky, please do fix it properly. 367 # out why it is flaky, please do fix it properly.
363 if not self["trunk_revision"]: 368 if not self["trunk_revision"]:
364 print("Sorry, grepping for the SVN revision failed. Please look for it " 369 print("Sorry, grepping for the SVN revision failed. Please look for it "
365 "in the last command's output above and provide it manually (just " 370 "in the last command's output above and provide it manually (just "
366 "the number, without the leading \"r\").") 371 "the number, without the leading \"r\").")
367 self.DieNoManualMode("Can't prompt in forced mode.") 372 self.DieNoManualMode("Can't prompt in forced mode.")
368 while not self["trunk_revision"]: 373 while not self["trunk_revision"]:
369 print "> ", 374 print "> ",
370 self["trunk_revision"] = self.ReadLine() 375 self["trunk_revision"] = self.ReadLine()
371 376
372 377
373 class TagRevision(Step): 378 class TagRevision(Step):
374 MESSAGE = "Tag the new revision." 379 MESSAGE = "Tag the new revision."
375 380
376 def RunStep(self): 381 def RunStep(self):
377 self.GitSVNTag(self["version"]) 382 self.vc.Tag(self["version"])
378 383
379 384
380 class CleanUp(Step): 385 class CleanUp(Step):
381 MESSAGE = "Done!" 386 MESSAGE = "Done!"
382 387
383 def RunStep(self): 388 def RunStep(self):
384 print("Congratulations, you have successfully created the trunk " 389 print("Congratulations, you have successfully created the trunk "
385 "revision %s. Please don't forget to roll this new version into " 390 "revision %s. Please don't forget to roll this new version into "
386 "Chromium, and to update the v8rel spreadsheet:" 391 "Chromium, and to update the v8rel spreadsheet:"
387 % self["version"]) 392 % self["version"])
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 CommitTrunk, 460 CommitTrunk,
456 SanityCheck, 461 SanityCheck,
457 CommitSVN, 462 CommitSVN,
458 TagRevision, 463 TagRevision,
459 CleanUp, 464 CleanUp,
460 ] 465 ]
461 466
462 467
463 if __name__ == "__main__": # pragma: no cover 468 if __name__ == "__main__": # pragma: no cover
464 sys.exit(PushToTrunk().Run()) 469 sys.exit(PushToTrunk().Run())
OLDNEW
« no previous file with comments | « tools/push-to-trunk/merge_to_branch.py ('k') | tools/push-to-trunk/releases.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698