From 082b65c5db7910b6894e7b7344dcbec005b847e6 Mon Sep 17 00:00:00 2001 From: "machenbach@chromium.org" Date: Fri, 22 Aug 2014 14:30:37 +0000 Subject: [PATCH] Make v8 releases script ready for chromium git switch. This uses chromium commit numbers that are supported after the chromium git switch. Most functionality is copied from the bot_update.py script from tools/build. This also enables mapping bleeding edge revisions to chromium revisions (previously the data was only retrieved for trunk). TEST=script_test.py TEST=tools/push-to-trunk/releases.py -c /path/to/chromium/src --branch recent TBR=jarin@chromium.org Review URL: https://codereview.chromium.org/497043002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23319 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- tools/push-to-trunk/releases.py | 93 +++++++++++++++++++++++++++++++++---- tools/push-to-trunk/test_scripts.py | 39 +++++++++++++--- 2 files changed, 115 insertions(+), 17 deletions(-) diff --git a/tools/push-to-trunk/releases.py b/tools/push-to-trunk/releases.py index ff57844..586cbc1 100755 --- a/tools/push-to-trunk/releases.py +++ b/tools/push-to-trunk/releases.py @@ -57,6 +57,77 @@ DEPS_RE = re.compile(r'^\s*(?:"v8_revision": "' BLEEDING_EDGE_TAGS_RE = re.compile( r"A \/tags\/([^\s]+) \(from \/branches\/bleeding_edge\:(\d+)\)") +# Regular expression that matches a single commit footer line. +COMMIT_FOOTER_ENTRY_RE = re.compile(r'([^:]+):\s+(.+)') + +# Footer metadata key for commit position. +COMMIT_POSITION_FOOTER_KEY = 'Cr-Commit-Position' + +# Regular expression to parse a commit position +COMMIT_POSITION_RE = re.compile(r'(.+)@\{#(\d+)\}') + +# Key for the 'git-svn' ID metadata commit footer entry. +GIT_SVN_ID_FOOTER_KEY = 'git-svn-id' + +# e.g., git-svn-id: https://v8.googlecode.com/svn/trunk@23117 +# ce2b1a6d-e550-0410-aec6-3dcde31c8c00 +GIT_SVN_ID_RE = re.compile(r'((?:\w+)://[^@]+)@(\d+)\s+(?:[a-zA-Z0-9\-]+)') + + +# Copied from bot_update.py. +def GetCommitMessageFooterMap(message): + """Returns: (dict) A dictionary of commit message footer entries. + """ + footers = {} + + # Extract the lines in the footer block. + lines = [] + for line in message.strip().splitlines(): + line = line.strip() + if len(line) == 0: + del(lines[:]) + continue + lines.append(line) + + # Parse the footer + for line in lines: + m = COMMIT_FOOTER_ENTRY_RE.match(line) + if not m: + # If any single line isn't valid, the entire footer is invalid. + footers.clear() + return footers + footers[m.group(1)] = m.group(2).strip() + return footers + + +# Copied from bot_update.py and modified for svn-like numbers only. +def GetCommitPositionNumber(step, git_hash): + """Dumps the 'git' log for a specific revision and parses out the commit + position number. + + If a commit position metadata key is found, its number will be returned. + + Otherwise, we will search for a 'git-svn' metadata entry. If one is found, + its SVN revision value is returned. + """ + git_log = step.GitLog(format='%B', n=1, git_hash=git_hash) + footer_map = GetCommitMessageFooterMap(git_log) + + # Search for commit position metadata + value = footer_map.get(COMMIT_POSITION_FOOTER_KEY) + if value: + match = COMMIT_POSITION_RE.match(value) + if match: + return match.group(2) + + # Extract the svn revision from 'git-svn' metadata + value = footer_map.get(GIT_SVN_ID_FOOTER_KEY) + if value: + match = GIT_SVN_ID_RE.match(value) + if match: + return match.group(2) + return None + def SortBranches(branches): """Sort branches with version number names.""" @@ -310,12 +381,13 @@ class RetrieveChromiumV8Releases(Step): def RunStep(self): os.chdir(self["chrome_path"]) - trunk_releases = filter(lambda r: r["branch"] == "trunk", self["releases"]) - if not trunk_releases: # pragma: no cover - print "No trunk releases detected. Skipping chromium history." + releases = filter( + lambda r: r["branch"] in ["trunk", "bleeding_edge"], self["releases"]) + if not releases: # pragma: no cover + print "No releases detected. Skipping chromium history." return True - oldest_v8_rev = int(trunk_releases[-1]["revision"]) + oldest_v8_rev = int(releases[-1]["revision"]) cr_releases = [] try: @@ -327,9 +399,10 @@ class RetrieveChromiumV8Releases(Step): deps = FileToText(self.Config(DEPS_FILE)) match = DEPS_RE.search(deps) if match: - svn_rev = self.GitSVNFindSVNRev(git_hash) - v8_rev = match.group(1) - cr_releases.append([svn_rev, v8_rev]) + cr_rev = GetCommitPositionNumber(self, git_hash) + if cr_rev: + v8_rev = match.group(1) + cr_releases.append([cr_rev, v8_rev]) # Stop after reaching beyond the last v8 revision we want to update. # We need a small buffer for possible revert/reland frenzies. @@ -344,11 +417,11 @@ class RetrieveChromiumV8Releases(Step): # Clean up. self.GitCheckoutFileSafe(self._config[DEPS_FILE], "HEAD") - # Add the chromium ranges to the v8 trunk releases. + # Add the chromium ranges to the v8 trunk and bleeding_edge releases. all_ranges = BuildRevisionRanges(cr_releases) - trunk_dict = dict((r["revision"], r) for r in trunk_releases) + releases_dict = dict((r["revision"], r) for r in releases) for revision, ranges in all_ranges.iteritems(): - trunk_dict.get(revision, {})["chromium_revision"] = ranges + releases_dict.get(revision, {})["chromium_revision"] = ranges # TODO(machenbach): Unify common code with method above. diff --git a/tools/push-to-trunk/test_scripts.py b/tools/push-to-trunk/test_scripts.py index 82a4d15..7a40985 100644 --- a/tools/push-to-trunk/test_scripts.py +++ b/tools/push-to-trunk/test_scripts.py @@ -1194,6 +1194,26 @@ Changed paths: Tagging version 3.28.40 ------------------------------------------------------------------------ """ + c_hash2_commit_log = """Revert something. + +BUG=12345 + +Reason: +> Some reason. +> Cr-Commit-Position: refs/heads/master@{#12345} +> git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12345 003-1c4 + +Review URL: https://codereview.chromium.org/12345 + +Cr-Commit-Position: refs/heads/master@{#4567} +git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4567 0039-1c4b + +""" + c_hash3_commit_log = """Simple. + +git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3456 0039-1c4b + +""" json_output = self.MakeEmptyTempFile() csv_output = self.MakeEmptyTempFile() TEST_CONFIG[VERSION_FILE] = self.MakeEmptyTempFile() @@ -1270,12 +1290,16 @@ Tagging version 3.28.40 Git("checkout -f master", ""), Git("pull", ""), Git("checkout -b %s" % TEST_CONFIG[BRANCHNAME], ""), - Git("log --format=%H --grep=\"V8\"", "c_hash1\nc_hash2\n"), + Git("log --format=%H --grep=\"V8\"", "c_hash1\nc_hash2\nc_hash3\n"), Git("diff --name-only c_hash1 c_hash1^", ""), Git("diff --name-only c_hash2 c_hash2^", TEST_CONFIG[DEPS_FILE]), Git("checkout -f c_hash2 -- %s" % TEST_CONFIG[DEPS_FILE], "", + cb=ResetDEPS(22624)), + Git("log -1 --format=%B c_hash2", c_hash2_commit_log), + Git("diff --name-only c_hash3 c_hash3^", TEST_CONFIG[DEPS_FILE]), + Git("checkout -f c_hash3 -- %s" % TEST_CONFIG[DEPS_FILE], "", cb=ResetDEPS(345)), - Git("svn find-rev c_hash2", "4567"), + Git("log -1 --format=%B c_hash3", c_hash3_commit_log), Git("checkout -f HEAD -- %s" % TEST_CONFIG[DEPS_FILE], "", cb=ResetDEPS(567)), Git("branch -r", " weird/123\n branch-heads/7\n"), @@ -1297,8 +1321,8 @@ Tagging version 3.28.40 # Check expected output. csv = ("3.28.41,bleeding_edge,22626,,\r\n" - "3.28.40,bleeding_edge,22624,,\r\n" - "3.22.3,trunk,345,4567,\r\n" + "3.28.40,bleeding_edge,22624,4567,\r\n" + "3.22.3,trunk,345,3456:4566,\r\n" "3.21.2,3.21,123,,\r\n" "3.3.1.1,3.3,234,,12\r\n") self.assertEquals(csv, FileToText(csv_output)) @@ -1309,11 +1333,12 @@ Tagging version 3.28.40 "review_link": "", "date": "01:23", "chromium_branch": "", "revision_link": "https://code.google.com/p/v8/source/detail?r=22626"}, {"bleeding_edge": "22624", "patches_merged": "", "version": "3.28.40", - "chromium_revision": "", "branch": "bleeding_edge", "revision": "22624", - "review_link": "", "date": "02:34", "chromium_branch": "", + "chromium_revision": "4567", "branch": "bleeding_edge", + "revision": "22624", "review_link": "", "date": "02:34", + "chromium_branch": "", "revision_link": "https://code.google.com/p/v8/source/detail?r=22624"}, {"bleeding_edge": "", "patches_merged": "", "version": "3.22.3", - "chromium_revision": "4567", "branch": "trunk", "revision": "345", + "chromium_revision": "3456:4566", "branch": "trunk", "revision": "345", "review_link": "", "date": "", "chromium_branch": "7", "revision_link": "https://code.google.com/p/v8/source/detail?r=345"}, {"patches_merged": "", "bleeding_edge": "", "version": "3.21.2", -- 2.7.4