2014-02-18 13:09:14 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are
|
|
|
|
# met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above
|
|
|
|
# copyright notice, this list of conditions and the following
|
|
|
|
# disclaimer in the documentation and/or other materials provided
|
|
|
|
# with the distribution.
|
|
|
|
# * Neither the name of Google Inc. nor the names of its
|
|
|
|
# contributors may be used to endorse or promote products derived
|
|
|
|
# from this software without specific prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2014-02-26 15:13:31 +00:00
|
|
|
import argparse
|
2014-02-18 13:09:14 +00:00
|
|
|
from collections import OrderedDict
|
2014-02-18 13:51:46 +00:00
|
|
|
import sys
|
2014-02-18 13:09:14 +00:00
|
|
|
|
|
|
|
from common_includes import *
|
|
|
|
|
2014-11-05 13:30:50 +00:00
|
|
|
def IsSvnNumber(rev):
|
|
|
|
return rev.isdigit() and len(rev) < 8
|
|
|
|
|
2014-02-18 13:09:14 +00:00
|
|
|
class Preparation(Step):
|
|
|
|
MESSAGE = "Preparation."
|
|
|
|
|
|
|
|
def RunStep(self):
|
2014-09-23 14:41:36 +00:00
|
|
|
if os.path.exists(self.Config("ALREADY_MERGING_SENTINEL_FILE")):
|
2014-03-04 23:27:27 +00:00
|
|
|
if self._options.force:
|
2014-09-23 14:41:36 +00:00
|
|
|
os.remove(self.Config("ALREADY_MERGING_SENTINEL_FILE"))
|
2014-03-12 10:45:23 +00:00
|
|
|
elif self._options.step == 0: # pragma: no cover
|
2014-02-18 13:09:14 +00:00
|
|
|
self.Die("A merge is already in progress")
|
2014-09-23 14:41:36 +00:00
|
|
|
open(self.Config("ALREADY_MERGING_SENTINEL_FILE"), "a").close()
|
2014-02-18 13:09:14 +00:00
|
|
|
|
2014-09-19 13:37:34 +00:00
|
|
|
self.InitialEnvironmentChecks(self.default_cwd)
|
2014-02-18 13:09:14 +00:00
|
|
|
if self._options.revert_bleeding_edge:
|
2014-09-25 13:25:14 +00:00
|
|
|
# FIXME(machenbach): Make revert bleeding_edge obsolete?
|
2014-02-19 11:56:48 +00:00
|
|
|
self["merge_to_branch"] = "bleeding_edge"
|
2014-02-26 15:13:31 +00:00
|
|
|
elif self._options.branch:
|
|
|
|
self["merge_to_branch"] = self._options.branch
|
2014-03-12 10:45:23 +00:00
|
|
|
else: # pragma: no cover
|
2014-02-18 13:09:14 +00:00
|
|
|
self.Die("Please specify a branch to merge to")
|
|
|
|
|
|
|
|
self.CommonPrepare()
|
|
|
|
self.PrepareBranch()
|
|
|
|
|
|
|
|
|
|
|
|
class CreateBranch(Step):
|
|
|
|
MESSAGE = "Create a fresh branch for the patch."
|
|
|
|
|
|
|
|
def RunStep(self):
|
2014-09-23 14:41:36 +00:00
|
|
|
self.GitCreateBranch(self.Config("BRANCHNAME"),
|
2014-09-25 13:25:14 +00:00
|
|
|
self.vc.RemoteBranch(self["merge_to_branch"]))
|
2014-02-18 13:09:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SearchArchitecturePorts(Step):
|
|
|
|
MESSAGE = "Search for corresponding architecture ports."
|
|
|
|
|
|
|
|
def RunStep(self):
|
2014-02-26 15:13:31 +00:00
|
|
|
self["full_revision_list"] = list(OrderedDict.fromkeys(
|
|
|
|
self._options.revisions))
|
2014-02-18 13:09:14 +00:00
|
|
|
port_revision_list = []
|
2014-02-19 11:56:48 +00:00
|
|
|
for revision in self["full_revision_list"]:
|
2014-11-05 13:30:50 +00:00
|
|
|
# Search for commits which matches the "Port XXX" pattern.
|
2014-02-20 16:39:41 +00:00
|
|
|
git_hashes = self.GitLog(reverse=True, format="%H",
|
2014-11-05 13:30:50 +00:00
|
|
|
grep="Port %s" % revision,
|
2014-09-25 13:25:14 +00:00
|
|
|
branch=self.vc.RemoteMasterBranch())
|
2014-02-20 16:39:41 +00:00
|
|
|
for git_hash in git_hashes.splitlines():
|
|
|
|
revision_title = self.GitLog(n=1, format="%s", git_hash=git_hash)
|
2014-02-18 13:09:14 +00:00
|
|
|
|
|
|
|
# Is this revision included in the original revision list?
|
2014-11-05 13:30:50 +00:00
|
|
|
if git_hash in self["full_revision_list"]:
|
|
|
|
print("Found port of %s -> %s (already included): %s"
|
|
|
|
% (revision, git_hash, revision_title))
|
2014-02-18 13:09:14 +00:00
|
|
|
else:
|
2014-11-05 13:30:50 +00:00
|
|
|
print("Found port of %s -> %s: %s"
|
|
|
|
% (revision, git_hash, revision_title))
|
|
|
|
port_revision_list.append(git_hash)
|
2014-02-18 13:09:14 +00:00
|
|
|
|
|
|
|
# Do we find any port?
|
|
|
|
if len(port_revision_list) > 0:
|
|
|
|
if self.Confirm("Automatically add corresponding ports (%s)?"
|
|
|
|
% ", ".join(port_revision_list)):
|
|
|
|
#: 'y': Add ports to revision list.
|
2014-02-19 11:56:48 +00:00
|
|
|
self["full_revision_list"].extend(port_revision_list)
|
2014-02-18 13:09:14 +00:00
|
|
|
|
|
|
|
|
2014-11-05 13:30:50 +00:00
|
|
|
class CreateCommitMessage(Step):
|
|
|
|
MESSAGE = "Create commit message."
|
2014-02-18 13:09:14 +00:00
|
|
|
|
|
|
|
def RunStep(self):
|
|
|
|
|
|
|
|
# Stringify: [123, 234] -> "r123, r234"
|
2014-02-19 11:56:48 +00:00
|
|
|
self["revision_list"] = ", ".join(map(lambda s: "r%s" % s,
|
|
|
|
self["full_revision_list"]))
|
2014-02-18 13:09:14 +00:00
|
|
|
|
2014-03-12 10:45:23 +00:00
|
|
|
if not self["revision_list"]: # pragma: no cover
|
2014-02-18 13:09:14 +00:00
|
|
|
self.Die("Revision list is empty.")
|
|
|
|
|
2014-11-05 13:30:50 +00:00
|
|
|
if self._options.revert and not self._options.revert_bleeding_edge:
|
|
|
|
action_text = "Rollback of %s"
|
|
|
|
else:
|
|
|
|
action_text = "Merged %s"
|
|
|
|
|
2014-04-03 12:57:33 +00:00
|
|
|
# The commit message title is added below after the version is specified.
|
2014-11-05 13:30:50 +00:00
|
|
|
msg_pieces = [
|
|
|
|
"\n".join(action_text % s for s in self["full_revision_list"]),
|
|
|
|
]
|
|
|
|
msg_pieces.append("\n\n")
|
2014-02-18 13:09:14 +00:00
|
|
|
|
2014-11-05 13:30:50 +00:00
|
|
|
for commit_hash in self["full_revision_list"]:
|
2014-02-20 16:39:41 +00:00
|
|
|
patch_merge_desc = self.GitLog(n=1, format="%s", git_hash=commit_hash)
|
2014-11-05 13:30:50 +00:00
|
|
|
msg_pieces.append("%s\n\n" % patch_merge_desc)
|
2014-02-18 13:09:14 +00:00
|
|
|
|
|
|
|
bugs = []
|
2014-11-05 13:30:50 +00:00
|
|
|
for commit_hash in self["full_revision_list"]:
|
2014-02-20 16:39:41 +00:00
|
|
|
msg = self.GitLog(n=1, git_hash=commit_hash)
|
2014-11-05 13:30:50 +00:00
|
|
|
for bug in re.findall(r"^[ \t]*BUG[ \t]*=[ \t]*(.*?)[ \t]*$", msg, re.M):
|
|
|
|
bugs.extend(s.strip() for s in bug.split(","))
|
2014-04-03 13:01:22 +00:00
|
|
|
bug_aggregate = ",".join(sorted(filter(lambda s: s and s != "none", bugs)))
|
2014-02-18 13:09:14 +00:00
|
|
|
if bug_aggregate:
|
2014-11-05 13:30:50 +00:00
|
|
|
msg_pieces.append("BUG=%s\nLOG=N\n" % bug_aggregate)
|
|
|
|
|
|
|
|
self["new_commit_msg"] = "".join(msg_pieces)
|
2014-02-18 13:09:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ApplyPatches(Step):
|
|
|
|
MESSAGE = "Apply patches for selected revisions."
|
|
|
|
|
|
|
|
def RunStep(self):
|
2014-11-05 13:30:50 +00:00
|
|
|
for commit_hash in self["full_revision_list"]:
|
2014-02-18 13:09:14 +00:00
|
|
|
print("Applying patch for %s to %s..."
|
2014-02-19 11:56:48 +00:00
|
|
|
% (commit_hash, self["merge_to_branch"]))
|
2014-02-26 16:12:32 +00:00
|
|
|
patch = self.GitGetPatch(commit_hash)
|
2014-09-23 14:41:36 +00:00
|
|
|
TextToFile(patch, self.Config("TEMPORARY_PATCH_FILE"))
|
|
|
|
self.ApplyPatch(self.Config("TEMPORARY_PATCH_FILE"), self._options.revert)
|
2014-02-18 13:09:14 +00:00
|
|
|
if self._options.patch:
|
|
|
|
self.ApplyPatch(self._options.patch, self._options.revert)
|
|
|
|
|
|
|
|
|
|
|
|
class PrepareVersion(Step):
|
|
|
|
MESSAGE = "Prepare version file."
|
|
|
|
|
|
|
|
def RunStep(self):
|
|
|
|
if self._options.revert_bleeding_edge:
|
|
|
|
return
|
2014-04-03 09:42:18 +00:00
|
|
|
# This is used to calculate the patch level increment.
|
2014-02-18 13:09:14 +00:00
|
|
|
self.ReadAndPersistVersion()
|
|
|
|
|
|
|
|
|
|
|
|
class IncrementVersion(Step):
|
|
|
|
MESSAGE = "Increment version number."
|
|
|
|
|
|
|
|
def RunStep(self):
|
|
|
|
if self._options.revert_bleeding_edge:
|
|
|
|
return
|
2014-02-19 11:56:48 +00:00
|
|
|
new_patch = str(int(self["patch"]) + 1)
|
2014-02-18 13:09:14 +00:00
|
|
|
if self.Confirm("Automatically increment PATCH_LEVEL? (Saying 'n' will "
|
|
|
|
"fire up your EDITOR on %s so you can make arbitrary "
|
|
|
|
"changes. When you're done, save the file and exit your "
|
2014-09-23 09:35:49 +00:00
|
|
|
"EDITOR.)" % VERSION_FILE):
|
|
|
|
text = FileToText(os.path.join(self.default_cwd, VERSION_FILE))
|
2014-02-18 13:09:14 +00:00
|
|
|
text = MSub(r"(?<=#define PATCH_LEVEL)(?P<space>\s+)\d*$",
|
|
|
|
r"\g<space>%s" % new_patch,
|
|
|
|
text)
|
2014-09-23 09:35:49 +00:00
|
|
|
TextToFile(text, os.path.join(self.default_cwd, VERSION_FILE))
|
2014-02-18 13:09:14 +00:00
|
|
|
else:
|
2014-09-23 09:35:49 +00:00
|
|
|
self.Editor(os.path.join(self.default_cwd, VERSION_FILE))
|
2014-02-18 13:09:14 +00:00
|
|
|
self.ReadAndPersistVersion("new_")
|
2014-04-03 09:42:18 +00:00
|
|
|
self["version"] = "%s.%s.%s.%s" % (self["new_major"],
|
|
|
|
self["new_minor"],
|
|
|
|
self["new_build"],
|
|
|
|
self["new_patch"])
|
2014-02-18 13:09:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CommitLocal(Step):
|
|
|
|
MESSAGE = "Commit to local branch."
|
|
|
|
|
|
|
|
def RunStep(self):
|
2014-04-03 12:57:33 +00:00
|
|
|
# Add a commit message title.
|
2014-11-05 13:30:50 +00:00
|
|
|
if self._options.revert and self._options.revert_bleeding_edge:
|
|
|
|
# TODO(machenbach): Find a better convention if multiple patches are
|
|
|
|
# reverted in one CL.
|
|
|
|
self["commit_title"] = "Revert on master"
|
2014-04-03 12:57:33 +00:00
|
|
|
else:
|
2014-11-05 13:30:50 +00:00
|
|
|
self["commit_title"] = "Version %s (cherry-pick)" % self["version"]
|
|
|
|
self["new_commit_msg"] = "%s\n\n%s" % (self["commit_title"],
|
|
|
|
self["new_commit_msg"])
|
2014-09-23 14:41:36 +00:00
|
|
|
TextToFile(self["new_commit_msg"], self.Config("COMMITMSG_FILE"))
|
|
|
|
self.GitCommit(file_name=self.Config("COMMITMSG_FILE"))
|
2014-02-18 13:09:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CommitRepository(Step):
|
|
|
|
MESSAGE = "Commit to the repository."
|
|
|
|
|
|
|
|
def RunStep(self):
|
2014-09-23 14:41:36 +00:00
|
|
|
self.GitCheckout(self.Config("BRANCHNAME"))
|
2014-02-18 13:09:14 +00:00
|
|
|
self.WaitForLGTM()
|
2014-02-20 16:39:41 +00:00
|
|
|
self.GitPresubmit()
|
2014-09-25 13:25:14 +00:00
|
|
|
self.vc.CLLand()
|
2014-02-18 13:09:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TagRevision(Step):
|
|
|
|
MESSAGE = "Create the tag."
|
|
|
|
|
|
|
|
def RunStep(self):
|
|
|
|
if self._options.revert_bleeding_edge:
|
|
|
|
return
|
2014-10-07 10:46:04 +00:00
|
|
|
print "Creating tag %s" % self["version"]
|
|
|
|
self.vc.Tag(self["version"],
|
|
|
|
self.vc.RemoteBranch(self["merge_to_branch"]),
|
|
|
|
self["commit_title"])
|
2014-02-18 13:09:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CleanUp(Step):
|
|
|
|
MESSAGE = "Cleanup."
|
|
|
|
|
|
|
|
def RunStep(self):
|
|
|
|
self.CommonCleanup()
|
|
|
|
if not self._options.revert_bleeding_edge:
|
|
|
|
print "*** SUMMARY ***"
|
2014-02-19 11:56:48 +00:00
|
|
|
print "version: %s" % self["version"]
|
2014-09-25 13:25:14 +00:00
|
|
|
print "branch: %s" % self["merge_to_branch"]
|
2014-02-19 11:56:48 +00:00
|
|
|
if self["revision_list"]:
|
|
|
|
print "patches: %s" % self["revision_list"]
|
2014-02-18 13:09:14 +00:00
|
|
|
|
|
|
|
|
2014-03-04 23:27:27 +00:00
|
|
|
class MergeToBranch(ScriptsBase):
|
|
|
|
def _Description(self):
|
|
|
|
return ("Performs the necessary steps to merge revisions from "
|
|
|
|
"bleeding_edge to other branches, including trunk.")
|
|
|
|
|
|
|
|
def _PrepareOptions(self, parser):
|
|
|
|
group = parser.add_mutually_exclusive_group(required=True)
|
|
|
|
group.add_argument("--branch", help="The branch to merge to.")
|
|
|
|
group.add_argument("-R", "--revert-bleeding-edge",
|
|
|
|
help="Revert specified patches from bleeding edge.",
|
|
|
|
default=False, action="store_true")
|
|
|
|
parser.add_argument("revisions", nargs="*",
|
|
|
|
help="The revisions to merge.")
|
|
|
|
parser.add_argument("-f", "--force",
|
|
|
|
help="Delete sentinel file.",
|
|
|
|
default=False, action="store_true")
|
|
|
|
parser.add_argument("-m", "--message",
|
|
|
|
help="A commit message for the patch.")
|
|
|
|
parser.add_argument("--revert",
|
|
|
|
help="Revert specified patches.",
|
|
|
|
default=False, action="store_true")
|
|
|
|
parser.add_argument("-p", "--patch",
|
|
|
|
help="A patch file to apply as part of the merge.")
|
|
|
|
|
|
|
|
def _ProcessOptions(self, options):
|
|
|
|
# TODO(machenbach): Add a test that covers revert from bleeding_edge
|
|
|
|
if len(options.revisions) < 1:
|
|
|
|
if not options.patch:
|
|
|
|
print "Either a patch file or revision numbers must be specified"
|
|
|
|
return False
|
|
|
|
if not options.message:
|
|
|
|
print "You must specify a merge comment if no patches are specified"
|
|
|
|
return False
|
2014-09-10 07:51:13 +00:00
|
|
|
options.bypass_upload_hooks = True
|
2014-09-25 11:28:27 +00:00
|
|
|
# CC ulan to make sure that fixes are merged to Google3.
|
|
|
|
options.cc = "ulan@chromium.org"
|
2014-11-05 13:30:50 +00:00
|
|
|
|
|
|
|
# Thd old git-svn workflow is deprecated for this script.
|
|
|
|
assert options.vc_interface != "git_svn"
|
|
|
|
|
|
|
|
# Make sure to use git hashes in the new workflows.
|
|
|
|
for revision in options.revisions:
|
|
|
|
if (IsSvnNumber(revision) or
|
|
|
|
(revision[0:1] == "r" and IsSvnNumber(revision[1:]))):
|
|
|
|
print "Please provide full git hashes of the patches to merge."
|
|
|
|
print "Got: %s" % revision
|
|
|
|
return False
|
2014-03-04 23:27:27 +00:00
|
|
|
return True
|
|
|
|
|
2014-09-23 14:41:36 +00:00
|
|
|
def _Config(self):
|
|
|
|
return {
|
|
|
|
"BRANCHNAME": "prepare-merge",
|
|
|
|
"PERSISTFILE_BASENAME": "/tmp/v8-merge-to-branch-tempfile",
|
|
|
|
"ALREADY_MERGING_SENTINEL_FILE":
|
|
|
|
"/tmp/v8-merge-to-branch-tempfile-already-merging",
|
|
|
|
"TEMPORARY_PATCH_FILE": "/tmp/v8-prepare-merge-tempfile-temporary-patch",
|
|
|
|
"COMMITMSG_FILE": "/tmp/v8-prepare-merge-tempfile-commitmsg",
|
|
|
|
}
|
|
|
|
|
2014-03-04 23:27:27 +00:00
|
|
|
def _Steps(self):
|
|
|
|
return [
|
|
|
|
Preparation,
|
|
|
|
CreateBranch,
|
|
|
|
SearchArchitecturePorts,
|
2014-11-05 13:30:50 +00:00
|
|
|
CreateCommitMessage,
|
2014-03-04 23:27:27 +00:00
|
|
|
ApplyPatches,
|
|
|
|
PrepareVersion,
|
|
|
|
IncrementVersion,
|
|
|
|
CommitLocal,
|
|
|
|
UploadStep,
|
|
|
|
CommitRepository,
|
|
|
|
TagRevision,
|
|
|
|
CleanUp,
|
|
|
|
]
|
|
|
|
|
2014-02-18 13:09:14 +00:00
|
|
|
|
2014-03-12 10:45:23 +00:00
|
|
|
if __name__ == "__main__": # pragma: no cover
|
2014-09-23 14:41:36 +00:00
|
|
|
sys.exit(MergeToBranch().Run())
|