2013-11-08 14:27:16 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Copyright 2013 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-03-04 23:27:27 +00:00
|
|
|
import argparse
|
2013-12-03 12:38:25 +00:00
|
|
|
import datetime
|
2014-06-25 08:17:45 +00:00
|
|
|
import httplib
|
2014-09-05 09:19:48 +00:00
|
|
|
import glob
|
2014-04-08 12:07:49 +00:00
|
|
|
import imp
|
2014-02-19 11:56:48 +00:00
|
|
|
import json
|
2013-11-08 14:27:16 +00:00
|
|
|
import os
|
|
|
|
import re
|
2014-09-05 09:19:48 +00:00
|
|
|
import shutil
|
2013-11-08 14:27:16 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2013-11-20 08:25:17 +00:00
|
|
|
import textwrap
|
2013-12-02 09:53:28 +00:00
|
|
|
import time
|
2014-06-25 08:44:59 +00:00
|
|
|
import urllib
|
2013-11-22 07:56:00 +00:00
|
|
|
import urllib2
|
2013-11-08 14:27:16 +00:00
|
|
|
|
2014-02-20 16:39:41 +00:00
|
|
|
from git_recipes import GitRecipesMixin
|
2014-04-09 14:30:02 +00:00
|
|
|
from git_recipes import GitFailedException
|
2014-02-20 16:39:41 +00:00
|
|
|
|
2014-09-23 09:35:49 +00:00
|
|
|
VERSION_FILE = os.path.join("src", "version.cc")
|
|
|
|
|
2014-09-05 09:19:48 +00:00
|
|
|
# V8 base directory.
|
|
|
|
DEFAULT_CWD = os.path.dirname(
|
|
|
|
os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
2013-11-08 14:27:16 +00:00
|
|
|
|
|
|
|
def TextToFile(text, file_name):
|
|
|
|
with open(file_name, "w") as f:
|
|
|
|
f.write(text)
|
|
|
|
|
|
|
|
|
|
|
|
def AppendToFile(text, file_name):
|
|
|
|
with open(file_name, "a") as f:
|
|
|
|
f.write(text)
|
|
|
|
|
|
|
|
|
|
|
|
def LinesInFile(file_name):
|
|
|
|
with open(file_name) as f:
|
|
|
|
for line in f:
|
|
|
|
yield line
|
|
|
|
|
|
|
|
|
|
|
|
def FileToText(file_name):
|
|
|
|
with open(file_name) as f:
|
|
|
|
return f.read()
|
|
|
|
|
|
|
|
|
|
|
|
def MSub(rexp, replacement, text):
|
|
|
|
return re.sub(rexp, replacement, text, flags=re.MULTILINE)
|
|
|
|
|
|
|
|
|
2013-11-20 08:25:17 +00:00
|
|
|
def Fill80(line):
|
2013-11-22 09:48:43 +00:00
|
|
|
# Replace tabs and remove surrounding space.
|
|
|
|
line = re.sub(r"\t", r" ", line.strip())
|
|
|
|
|
|
|
|
# Format with 8 characters indentation and line width 80.
|
2013-11-20 08:25:17 +00:00
|
|
|
return textwrap.fill(line, width=80, initial_indent=" ",
|
|
|
|
subsequent_indent=" ")
|
|
|
|
|
|
|
|
|
2013-11-21 09:35:25 +00:00
|
|
|
def MakeComment(text):
|
|
|
|
return MSub(r"^( ?)", "#", text)
|
|
|
|
|
|
|
|
|
|
|
|
def StripComments(text):
|
|
|
|
# Use split not splitlines to keep terminal newlines.
|
|
|
|
return "\n".join(filter(lambda x: not x.startswith("#"), text.split("\n")))
|
|
|
|
|
|
|
|
|
|
|
|
def MakeChangeLogBody(commit_messages, auto_format=False):
|
2013-11-18 13:34:32 +00:00
|
|
|
result = ""
|
2013-11-21 09:35:25 +00:00
|
|
|
added_titles = set()
|
|
|
|
for (title, body, author) in commit_messages:
|
2013-11-25 14:20:39 +00:00
|
|
|
# TODO(machenbach): Better check for reverts. A revert should remove the
|
|
|
|
# original CL from the actual log entry.
|
2013-11-22 09:48:43 +00:00
|
|
|
title = title.strip()
|
2013-11-21 09:35:25 +00:00
|
|
|
if auto_format:
|
|
|
|
# Only add commits that set the LOG flag correctly.
|
2013-12-03 09:13:51 +00:00
|
|
|
log_exp = r"^[ \t]*LOG[ \t]*=[ \t]*(?:(?:Y(?:ES)?)|TRUE)"
|
2013-11-21 09:35:25 +00:00
|
|
|
if not re.search(log_exp, body, flags=re.I | re.M):
|
|
|
|
continue
|
|
|
|
# Never include reverts.
|
|
|
|
if title.startswith("Revert "):
|
|
|
|
continue
|
|
|
|
# Don't include duplicates.
|
|
|
|
if title in added_titles:
|
|
|
|
continue
|
|
|
|
|
2013-11-25 14:20:39 +00:00
|
|
|
# Add and format the commit's title and bug reference. Move dot to the end.
|
2013-11-21 09:35:25 +00:00
|
|
|
added_titles.add(title)
|
2013-11-25 14:20:39 +00:00
|
|
|
raw_title = re.sub(r"(\.|\?|!)$", "", title)
|
|
|
|
bug_reference = MakeChangeLogBugReference(body)
|
|
|
|
space = " " if bug_reference else ""
|
|
|
|
result += "%s\n" % Fill80("%s%s%s." % (raw_title, space, bug_reference))
|
2013-11-18 13:34:32 +00:00
|
|
|
|
2013-11-21 09:35:25 +00:00
|
|
|
# Append the commit's author for reference if not in auto-format mode.
|
|
|
|
if not auto_format:
|
2013-11-22 09:48:43 +00:00
|
|
|
result += "%s\n" % Fill80("(%s)" % author.strip())
|
2013-11-21 09:35:25 +00:00
|
|
|
|
|
|
|
result += "\n"
|
2013-11-18 13:34:32 +00:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
2013-11-20 08:25:17 +00:00
|
|
|
def MakeChangeLogBugReference(body):
|
|
|
|
"""Grep for "BUG=xxxx" lines in the commit message and convert them to
|
|
|
|
"(issue xxxx)".
|
|
|
|
"""
|
|
|
|
crbugs = []
|
|
|
|
v8bugs = []
|
|
|
|
|
|
|
|
def AddIssues(text):
|
|
|
|
ref = re.match(r"^BUG[ \t]*=[ \t]*(.+)$", text.strip())
|
|
|
|
if not ref:
|
|
|
|
return
|
|
|
|
for bug in ref.group(1).split(","):
|
|
|
|
bug = bug.strip()
|
|
|
|
match = re.match(r"^v8:(\d+)$", bug)
|
|
|
|
if match: v8bugs.append(int(match.group(1)))
|
|
|
|
else:
|
|
|
|
match = re.match(r"^(?:chromium:)?(\d+)$", bug)
|
|
|
|
if match: crbugs.append(int(match.group(1)))
|
|
|
|
|
|
|
|
# Add issues to crbugs and v8bugs.
|
|
|
|
map(AddIssues, body.splitlines())
|
|
|
|
|
|
|
|
# Filter duplicates, sort, stringify.
|
|
|
|
crbugs = map(str, sorted(set(crbugs)))
|
|
|
|
v8bugs = map(str, sorted(set(v8bugs)))
|
|
|
|
|
|
|
|
bug_groups = []
|
|
|
|
def FormatIssues(prefix, bugs):
|
|
|
|
if len(bugs) > 0:
|
|
|
|
plural = "s" if len(bugs) > 1 else ""
|
|
|
|
bug_groups.append("%sissue%s %s" % (prefix, plural, ", ".join(bugs)))
|
|
|
|
|
|
|
|
FormatIssues("", v8bugs)
|
|
|
|
FormatIssues("Chromium ", crbugs)
|
|
|
|
|
|
|
|
if len(bug_groups) > 0:
|
2013-11-25 14:20:39 +00:00
|
|
|
return "(%s)" % ", ".join(bug_groups)
|
2013-11-20 08:25:17 +00:00
|
|
|
else:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
2014-07-16 07:57:13 +00:00
|
|
|
def SortingKey(version):
|
|
|
|
"""Key for sorting version number strings: '3.11' > '3.2.1.1'"""
|
|
|
|
version_keys = map(int, version.split("."))
|
|
|
|
# Fill up to full version numbers to normalize comparison.
|
|
|
|
while len(version_keys) < 4: # pragma: no cover
|
|
|
|
version_keys.append(0)
|
|
|
|
# Fill digits.
|
|
|
|
return ".".join(map("{0:04d}".format, version_keys))
|
|
|
|
|
|
|
|
|
2013-11-08 14:27:16 +00:00
|
|
|
# Some commands don't like the pipe, e.g. calling vi from within the script or
|
|
|
|
# from subscripts like git cl upload.
|
2014-09-05 09:19:48 +00:00
|
|
|
def Command(cmd, args="", prefix="", pipe=True, cwd=None):
|
|
|
|
cwd = cwd or os.getcwd()
|
2013-12-02 09:53:28 +00:00
|
|
|
# TODO(machenbach): Use timeout.
|
2013-11-08 14:27:16 +00:00
|
|
|
cmd_line = "%s %s %s" % (prefix, cmd, args)
|
|
|
|
print "Command: %s" % cmd_line
|
2014-09-05 09:19:48 +00:00
|
|
|
print "in %s" % cwd
|
2014-05-05 15:16:26 +00:00
|
|
|
sys.stdout.flush()
|
2013-11-08 14:27:16 +00:00
|
|
|
try:
|
|
|
|
if pipe:
|
2014-09-05 09:19:48 +00:00
|
|
|
return subprocess.check_output(cmd_line, shell=True, cwd=cwd)
|
2013-11-08 14:27:16 +00:00
|
|
|
else:
|
2014-09-05 09:19:48 +00:00
|
|
|
return subprocess.check_call(cmd_line, shell=True, cwd=cwd)
|
2013-11-08 14:27:16 +00:00
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
return None
|
2014-05-05 15:16:26 +00:00
|
|
|
finally:
|
|
|
|
sys.stdout.flush()
|
|
|
|
sys.stderr.flush()
|
2013-11-08 14:27:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Wrapper for side effects.
|
2014-03-12 10:45:23 +00:00
|
|
|
class SideEffectHandler(object): # pragma: no cover
|
2014-01-17 11:29:43 +00:00
|
|
|
def Call(self, fun, *args, **kwargs):
|
|
|
|
return fun(*args, **kwargs)
|
|
|
|
|
2014-09-05 09:19:48 +00:00
|
|
|
def Command(self, cmd, args="", prefix="", pipe=True, cwd=None):
|
|
|
|
return Command(cmd, args, prefix, pipe, cwd=cwd)
|
2013-11-08 14:27:16 +00:00
|
|
|
|
|
|
|
def ReadLine(self):
|
|
|
|
return sys.stdin.readline().strip()
|
|
|
|
|
2014-01-15 15:55:23 +00:00
|
|
|
def ReadURL(self, url, params=None):
|
2013-11-22 07:56:00 +00:00
|
|
|
# pylint: disable=E1121
|
2014-01-15 15:55:23 +00:00
|
|
|
url_fh = urllib2.urlopen(url, params, 60)
|
2013-11-22 07:56:00 +00:00
|
|
|
try:
|
|
|
|
return url_fh.read()
|
|
|
|
finally:
|
|
|
|
url_fh.close()
|
|
|
|
|
2014-06-25 08:17:45 +00:00
|
|
|
def ReadClusterFuzzAPI(self, api_key, **params):
|
2014-06-25 08:44:59 +00:00
|
|
|
params["api_key"] = api_key.strip()
|
2014-06-25 08:17:45 +00:00
|
|
|
params = urllib.urlencode(params)
|
|
|
|
|
|
|
|
headers = {"Content-type": "application/x-www-form-urlencoded"}
|
|
|
|
|
|
|
|
conn = httplib.HTTPSConnection("backend-dot-cluster-fuzz.appspot.com")
|
|
|
|
conn.request("POST", "/_api/", params, headers)
|
|
|
|
|
|
|
|
response = conn.getresponse()
|
|
|
|
data = response.read()
|
|
|
|
|
|
|
|
try:
|
|
|
|
return json.loads(data)
|
|
|
|
except:
|
|
|
|
print data
|
|
|
|
print "ERROR: Could not read response. Is your key valid?"
|
|
|
|
raise
|
|
|
|
|
2013-12-03 12:38:25 +00:00
|
|
|
def Sleep(self, seconds):
|
2013-12-02 09:53:28 +00:00
|
|
|
time.sleep(seconds)
|
|
|
|
|
2013-12-03 12:38:25 +00:00
|
|
|
def GetDate(self):
|
|
|
|
return datetime.date.today().strftime("%Y-%m-%d")
|
|
|
|
|
2014-07-18 12:16:14 +00:00
|
|
|
def GetUTCStamp(self):
|
2014-07-24 07:36:25 +00:00
|
|
|
return time.mktime(datetime.datetime.utcnow().timetuple())
|
2014-07-18 12:16:14 +00:00
|
|
|
|
2013-11-08 14:27:16 +00:00
|
|
|
DEFAULT_SIDE_EFFECT_HANDLER = SideEffectHandler()
|
|
|
|
|
|
|
|
|
2013-12-16 10:56:52 +00:00
|
|
|
class NoRetryException(Exception):
|
|
|
|
pass
|
|
|
|
|
2014-01-07 15:23:48 +00:00
|
|
|
|
2014-09-25 13:25:14 +00:00
|
|
|
class VCInterface(object):
|
|
|
|
def InjectStep(self, step):
|
|
|
|
self.step=step
|
|
|
|
|
|
|
|
def Pull(self):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def Fetch(self):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def GetTags(self):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def GetBranches(self):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def GitSvn(self, hsh, branch=""):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def SvnGit(self, rev, branch=""):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
2014-10-13 12:34:53 +00:00
|
|
|
def MasterBranch(self):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def CandidateBranch(self):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
2014-09-25 13:25:14 +00:00
|
|
|
def RemoteMasterBranch(self):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def RemoteCandidateBranch(self):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def RemoteBranch(self, name):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def Land(self):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def CLLand(self):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
# TODO(machenbach): There is some svn knowledge in this interface. In svn,
|
|
|
|
# tag and commit are different remote commands, while in git we would commit
|
|
|
|
# and tag locally and then push/land in one unique step.
|
2014-10-07 10:46:04 +00:00
|
|
|
def Tag(self, tag, remote, message):
|
|
|
|
"""Sets a tag for the current commit.
|
|
|
|
|
|
|
|
Assumptions: The commit already landed and the commit message is unique.
|
|
|
|
"""
|
2014-09-25 13:25:14 +00:00
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
|
|
|
|
class GitSvnInterface(VCInterface):
|
|
|
|
def Pull(self):
|
|
|
|
self.step.GitSVNRebase()
|
|
|
|
|
|
|
|
def Fetch(self):
|
|
|
|
self.step.GitSVNFetch()
|
|
|
|
|
|
|
|
def GetTags(self):
|
|
|
|
# Get remote tags.
|
|
|
|
tags = filter(lambda s: re.match(r"^svn/tags/[\d+\.]+$", s),
|
|
|
|
self.step.GitRemotes())
|
|
|
|
|
|
|
|
# Remove 'svn/tags/' prefix.
|
|
|
|
return map(lambda s: s[9:], tags)
|
|
|
|
|
|
|
|
def GetBranches(self):
|
|
|
|
# Get relevant remote branches, e.g. "svn/3.25".
|
|
|
|
branches = filter(lambda s: re.match(r"^svn/\d+\.\d+$", s),
|
|
|
|
self.step.GitRemotes())
|
|
|
|
# Remove 'svn/' prefix.
|
|
|
|
return map(lambda s: s[4:], branches)
|
|
|
|
|
|
|
|
def GitSvn(self, hsh, branch=""):
|
|
|
|
return self.step.GitSVNFindSVNRev(hsh, branch)
|
|
|
|
|
|
|
|
def SvnGit(self, rev, branch=""):
|
|
|
|
return self.step.GitSVNFindGitHash(rev, branch)
|
|
|
|
|
2014-10-13 12:34:53 +00:00
|
|
|
def MasterBranch(self):
|
|
|
|
return "bleeding_edge"
|
|
|
|
|
|
|
|
def CandidateBranch(self):
|
|
|
|
return "trunk"
|
|
|
|
|
2014-09-25 13:25:14 +00:00
|
|
|
def RemoteMasterBranch(self):
|
|
|
|
return "svn/bleeding_edge"
|
|
|
|
|
|
|
|
def RemoteCandidateBranch(self):
|
|
|
|
return "svn/trunk"
|
|
|
|
|
|
|
|
def RemoteBranch(self, name):
|
|
|
|
return "svn/%s" % name
|
|
|
|
|
|
|
|
def Land(self):
|
2014-09-25 14:09:34 +00:00
|
|
|
self.step.GitSVNDCommit()
|
2014-09-25 13:25:14 +00:00
|
|
|
|
|
|
|
def CLLand(self):
|
2014-09-25 14:09:34 +00:00
|
|
|
self.step.GitDCommit()
|
2014-09-25 13:25:14 +00:00
|
|
|
|
2014-10-07 10:46:04 +00:00
|
|
|
def Tag(self, tag, remote, _):
|
2014-09-30 13:12:44 +00:00
|
|
|
self.step.GitSVNFetch()
|
|
|
|
self.step.Git("rebase %s" % remote)
|
2014-09-25 13:25:14 +00:00
|
|
|
self.step.GitSVNTag(tag)
|
|
|
|
|
|
|
|
|
2014-10-07 10:46:04 +00:00
|
|
|
class GitTagsOnlyMixin(VCInterface):
|
2014-09-26 07:40:09 +00:00
|
|
|
def Pull(self):
|
|
|
|
self.step.GitPull()
|
|
|
|
|
|
|
|
def Fetch(self):
|
|
|
|
self.step.Git("fetch")
|
2014-10-16 13:45:59 +00:00
|
|
|
self.step.GitSVNFetch()
|
2014-09-26 07:40:09 +00:00
|
|
|
|
|
|
|
def GetTags(self):
|
|
|
|
return self.step.Git("tag").strip().splitlines()
|
|
|
|
|
|
|
|
def GetBranches(self):
|
2014-10-14 12:00:22 +00:00
|
|
|
# Get relevant remote branches, e.g. "branch-heads/3.25".
|
2014-09-26 07:40:09 +00:00
|
|
|
branches = filter(
|
2014-10-14 12:00:22 +00:00
|
|
|
lambda s: re.match(r"^branch\-heads/\d+\.\d+$", s),
|
2014-09-26 07:40:09 +00:00
|
|
|
self.step.GitRemotes())
|
2014-10-14 12:00:22 +00:00
|
|
|
# Remove 'branch-heads/' prefix.
|
|
|
|
return map(lambda s: s[13:], branches)
|
2014-09-26 07:40:09 +00:00
|
|
|
|
2014-10-13 12:34:53 +00:00
|
|
|
def MasterBranch(self):
|
|
|
|
return "master"
|
|
|
|
|
|
|
|
def CandidateBranch(self):
|
|
|
|
return "candidates"
|
|
|
|
|
2014-09-26 07:40:09 +00:00
|
|
|
def RemoteMasterBranch(self):
|
|
|
|
return "origin/master"
|
|
|
|
|
|
|
|
def RemoteCandidateBranch(self):
|
|
|
|
return "origin/candidates"
|
|
|
|
|
|
|
|
def RemoteBranch(self, name):
|
2014-09-26 08:39:03 +00:00
|
|
|
if name in ["candidates", "master"]:
|
|
|
|
return "origin/%s" % name
|
2014-10-14 12:10:48 +00:00
|
|
|
return "branch-heads/%s" % name
|
2014-09-26 07:40:09 +00:00
|
|
|
|
2014-10-07 10:46:04 +00:00
|
|
|
def Tag(self, tag, remote, message):
|
|
|
|
# Wait for the commit to appear. Assumes unique commit message titles (this
|
|
|
|
# is the case for all automated merge and push commits - also no title is
|
|
|
|
# the prefix of another title).
|
|
|
|
commit = None
|
2014-11-01 21:53:13 +00:00
|
|
|
for wait_interval in [3, 7, 15, 35, 35]:
|
2014-10-07 10:46:04 +00:00
|
|
|
self.step.Git("fetch")
|
|
|
|
commit = self.step.GitLog(n=1, format="%H", grep=message, branch=remote)
|
|
|
|
if commit:
|
|
|
|
break
|
|
|
|
print("The commit has not replicated to git. Waiting for %s seconds." %
|
|
|
|
wait_interval)
|
|
|
|
self.step._side_effect_handler.Sleep(wait_interval)
|
|
|
|
else:
|
|
|
|
self.step.Die("Couldn't determine commit for setting the tag. Maybe the "
|
|
|
|
"git updater is lagging behind?")
|
|
|
|
|
|
|
|
self.step.Git("tag %s %s" % (tag, commit))
|
|
|
|
self.step.Git("push origin %s" % tag)
|
|
|
|
|
2014-09-26 07:40:09 +00:00
|
|
|
|
2014-10-07 10:46:04 +00:00
|
|
|
class GitReadSvnWriteInterface(GitTagsOnlyMixin, GitSvnInterface):
|
2014-09-26 07:40:09 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2014-11-01 21:53:13 +00:00
|
|
|
class GitInterface(GitTagsOnlyMixin):
|
|
|
|
def Fetch(self):
|
|
|
|
self.step.Git("fetch")
|
|
|
|
|
|
|
|
def GitSvn(self, hsh, branch=""):
|
|
|
|
return ""
|
|
|
|
|
|
|
|
def SvnGit(self, rev, branch=""):
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def Land(self):
|
|
|
|
self.step.Git("push origin")
|
|
|
|
|
|
|
|
def CLLand(self):
|
|
|
|
self.step.GitCLLand()
|
|
|
|
|
|
|
|
|
2014-09-26 07:40:09 +00:00
|
|
|
VC_INTERFACES = {
|
|
|
|
"git_svn": GitSvnInterface,
|
|
|
|
"git_read_svn_write": GitReadSvnWriteInterface,
|
2014-11-01 21:53:13 +00:00
|
|
|
"git": GitInterface,
|
2014-09-26 07:40:09 +00:00
|
|
|
}
|
|
|
|
|
2014-09-25 13:25:14 +00:00
|
|
|
|
2014-02-20 16:39:41 +00:00
|
|
|
class Step(GitRecipesMixin):
|
2014-09-23 09:35:49 +00:00
|
|
|
def __init__(self, text, number, config, state, options, handler):
|
2013-11-08 14:27:16 +00:00
|
|
|
self._text = text
|
|
|
|
self._number = number
|
|
|
|
self._config = config
|
|
|
|
self._state = state
|
|
|
|
self._options = options
|
|
|
|
self._side_effect_handler = handler
|
2014-09-26 07:40:09 +00:00
|
|
|
self.vc = VC_INTERFACES[options.vc_interface]()
|
2014-09-25 13:25:14 +00:00
|
|
|
self.vc.InjectStep(self)
|
2014-09-05 09:19:48 +00:00
|
|
|
|
|
|
|
# The testing configuration might set a different default cwd.
|
|
|
|
self.default_cwd = self._config.get("DEFAULT_CWD") or DEFAULT_CWD
|
|
|
|
|
2013-11-22 09:48:43 +00:00
|
|
|
assert self._number >= 0
|
|
|
|
assert self._config is not None
|
|
|
|
assert self._state is not None
|
|
|
|
assert self._side_effect_handler is not None
|
2013-11-08 14:27:16 +00:00
|
|
|
|
2014-02-19 11:56:48 +00:00
|
|
|
def __getitem__(self, key):
|
|
|
|
# Convenience method to allow direct [] access on step classes for
|
|
|
|
# manipulating the backed state dict.
|
|
|
|
return self._state[key]
|
|
|
|
|
|
|
|
def __setitem__(self, key, value):
|
|
|
|
# Convenience method to allow direct [] access on step classes for
|
|
|
|
# manipulating the backed state dict.
|
|
|
|
self._state[key] = value
|
|
|
|
|
2013-11-08 14:27:16 +00:00
|
|
|
def Config(self, key):
|
|
|
|
return self._config[key]
|
|
|
|
|
|
|
|
def Run(self):
|
2014-02-19 11:56:48 +00:00
|
|
|
# Restore state.
|
2014-09-23 14:41:36 +00:00
|
|
|
state_file = "%s-state.json" % self._config["PERSISTFILE_BASENAME"]
|
2014-02-19 11:56:48 +00:00
|
|
|
if not self._state and os.path.exists(state_file):
|
|
|
|
self._state.update(json.loads(FileToText(state_file)))
|
|
|
|
|
2013-11-08 14:27:16 +00:00
|
|
|
print ">>> Step %d: %s" % (self._number, self._text)
|
2014-04-02 06:59:25 +00:00
|
|
|
try:
|
|
|
|
return self.RunStep()
|
|
|
|
finally:
|
|
|
|
# Persist state.
|
|
|
|
TextToFile(json.dumps(self._state), state_file)
|
2014-02-19 11:56:48 +00:00
|
|
|
|
2014-03-12 10:45:23 +00:00
|
|
|
def RunStep(self): # pragma: no cover
|
2013-11-08 14:27:16 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2013-12-02 09:53:28 +00:00
|
|
|
def Retry(self, cb, retry_on=None, wait_plan=None):
|
|
|
|
""" Retry a function.
|
|
|
|
Params:
|
|
|
|
cb: The function to retry.
|
|
|
|
retry_on: A callback that takes the result of the function and returns
|
|
|
|
True if the function should be retried. A function throwing an
|
|
|
|
exception is always retried.
|
|
|
|
wait_plan: A list of waiting delays between retries in seconds. The
|
|
|
|
maximum number of retries is len(wait_plan).
|
|
|
|
"""
|
|
|
|
retry_on = retry_on or (lambda x: False)
|
|
|
|
wait_plan = list(wait_plan or [])
|
|
|
|
wait_plan.reverse()
|
|
|
|
while True:
|
|
|
|
got_exception = False
|
|
|
|
try:
|
|
|
|
result = cb()
|
2014-09-03 14:38:28 +00:00
|
|
|
except NoRetryException as e:
|
2013-12-16 10:56:52 +00:00
|
|
|
raise e
|
2014-09-03 14:38:28 +00:00
|
|
|
except Exception as e:
|
|
|
|
got_exception = e
|
2013-12-02 09:53:28 +00:00
|
|
|
if got_exception or retry_on(result):
|
2014-03-12 10:45:23 +00:00
|
|
|
if not wait_plan: # pragma: no cover
|
2014-09-03 14:38:28 +00:00
|
|
|
raise Exception("Retried too often. Giving up. Reason: %s" %
|
|
|
|
str(got_exception))
|
2013-12-02 09:53:28 +00:00
|
|
|
wait_time = wait_plan.pop()
|
|
|
|
print "Waiting for %f seconds." % wait_time
|
|
|
|
self._side_effect_handler.Sleep(wait_time)
|
|
|
|
print "Retrying..."
|
|
|
|
else:
|
|
|
|
return result
|
|
|
|
|
2013-11-20 08:49:42 +00:00
|
|
|
def ReadLine(self, default=None):
|
|
|
|
# Don't prompt in forced mode.
|
2013-12-16 10:56:52 +00:00
|
|
|
if self._options.force_readline_defaults and default is not None:
|
2013-11-20 08:49:42 +00:00
|
|
|
print "%s (forced)" % default
|
|
|
|
return default
|
|
|
|
else:
|
|
|
|
return self._side_effect_handler.ReadLine()
|
2013-11-08 14:27:16 +00:00
|
|
|
|
2014-09-05 09:19:48 +00:00
|
|
|
def Command(self, name, args, cwd=None):
|
|
|
|
cmd = lambda: self._side_effect_handler.Command(
|
|
|
|
name, args, "", True, cwd=cwd or self.default_cwd)
|
|
|
|
return self.Retry(cmd, None, [5])
|
|
|
|
|
|
|
|
def Git(self, args="", prefix="", pipe=True, retry_on=None, cwd=None):
|
|
|
|
cmd = lambda: self._side_effect_handler.Command(
|
|
|
|
"git", args, prefix, pipe, cwd=cwd or self.default_cwd)
|
2014-02-19 14:56:19 +00:00
|
|
|
result = self.Retry(cmd, retry_on, [5, 30])
|
|
|
|
if result is None:
|
|
|
|
raise GitFailedException("'git %s' failed." % args)
|
|
|
|
return result
|
2013-11-08 14:27:16 +00:00
|
|
|
|
2014-09-05 09:19:48 +00:00
|
|
|
def SVN(self, args="", prefix="", pipe=True, retry_on=None, cwd=None):
|
|
|
|
cmd = lambda: self._side_effect_handler.Command(
|
|
|
|
"svn", args, prefix, pipe, cwd=cwd or self.default_cwd)
|
2014-02-18 13:09:14 +00:00
|
|
|
return self.Retry(cmd, retry_on, [5, 30])
|
|
|
|
|
2013-11-08 14:27:16 +00:00
|
|
|
def Editor(self, args):
|
2013-12-16 10:56:52 +00:00
|
|
|
if self._options.requires_editor:
|
2014-09-05 09:19:48 +00:00
|
|
|
return self._side_effect_handler.Command(
|
|
|
|
os.environ["EDITOR"],
|
|
|
|
args,
|
|
|
|
pipe=False,
|
|
|
|
cwd=self.default_cwd)
|
2013-11-08 14:27:16 +00:00
|
|
|
|
2014-01-15 15:55:23 +00:00
|
|
|
def ReadURL(self, url, params=None, retry_on=None, wait_plan=None):
|
2013-12-02 09:53:28 +00:00
|
|
|
wait_plan = wait_plan or [3, 60, 600]
|
2014-01-15 15:55:23 +00:00
|
|
|
cmd = lambda: self._side_effect_handler.ReadURL(url, params)
|
2013-12-02 09:53:28 +00:00
|
|
|
return self.Retry(cmd, retry_on, wait_plan)
|
2013-11-22 07:56:00 +00:00
|
|
|
|
2013-12-03 12:38:25 +00:00
|
|
|
def GetDate(self):
|
|
|
|
return self._side_effect_handler.GetDate()
|
|
|
|
|
2013-11-08 14:27:16 +00:00
|
|
|
def Die(self, msg=""):
|
|
|
|
if msg != "":
|
|
|
|
print "Error: %s" % msg
|
|
|
|
print "Exiting"
|
|
|
|
raise Exception(msg)
|
|
|
|
|
2013-12-04 08:47:18 +00:00
|
|
|
def DieNoManualMode(self, msg=""):
|
2014-03-12 10:45:23 +00:00
|
|
|
if not self._options.manual: # pragma: no cover
|
2013-12-04 08:47:18 +00:00
|
|
|
msg = msg or "Only available in manual mode."
|
2013-11-20 08:49:42 +00:00
|
|
|
self.Die(msg)
|
|
|
|
|
2013-11-08 14:27:16 +00:00
|
|
|
def Confirm(self, msg):
|
|
|
|
print "%s [Y/n] " % msg,
|
2013-11-20 08:49:42 +00:00
|
|
|
answer = self.ReadLine(default="Y")
|
2013-11-08 14:27:16 +00:00
|
|
|
return answer == "" or answer == "Y" or answer == "y"
|
|
|
|
|
|
|
|
def DeleteBranch(self, name):
|
2014-02-20 16:39:41 +00:00
|
|
|
for line in self.GitBranch().splitlines():
|
2014-07-16 07:57:13 +00:00
|
|
|
if re.match(r"\*?\s*%s$" % re.escape(name), line):
|
2013-11-08 14:27:16 +00:00
|
|
|
msg = "Branch %s exists, do you want to delete it?" % name
|
|
|
|
if self.Confirm(msg):
|
2014-02-20 16:39:41 +00:00
|
|
|
self.GitDeleteBranch(name)
|
2013-11-08 14:27:16 +00:00
|
|
|
print "Branch %s deleted." % name
|
|
|
|
else:
|
|
|
|
msg = "Can't continue. Please delete branch %s and try again." % name
|
|
|
|
self.Die(msg)
|
|
|
|
|
2014-09-19 13:37:34 +00:00
|
|
|
def InitialEnvironmentChecks(self, cwd):
|
2013-11-08 14:27:16 +00:00
|
|
|
# Cancel if this is not a git checkout.
|
2014-09-19 13:37:34 +00:00
|
|
|
if not os.path.exists(os.path.join(cwd, ".git")): # pragma: no cover
|
2013-11-08 14:27:16 +00:00
|
|
|
self.Die("This is not a git checkout, this script won't work for you.")
|
|
|
|
|
|
|
|
# Cancel if EDITOR is unset or not executable.
|
2013-12-16 10:56:52 +00:00
|
|
|
if (self._options.requires_editor and (not os.environ.get("EDITOR") or
|
2014-09-05 09:19:48 +00:00
|
|
|
self.Command(
|
|
|
|
"which", os.environ["EDITOR"]) is None)): # pragma: no cover
|
2013-11-08 14:27:16 +00:00
|
|
|
self.Die("Please set your EDITOR environment variable, you'll need it.")
|
|
|
|
|
|
|
|
def CommonPrepare(self):
|
|
|
|
# Check for a clean workdir.
|
2014-03-12 10:45:23 +00:00
|
|
|
if not self.GitIsWorkdirClean(): # pragma: no cover
|
2013-11-08 14:27:16 +00:00
|
|
|
self.Die("Workspace is not clean. Please commit or undo your changes.")
|
|
|
|
|
|
|
|
# Persist current branch.
|
2014-02-20 16:39:41 +00:00
|
|
|
self["current_branch"] = self.GitCurrentBranch()
|
2013-11-08 14:27:16 +00:00
|
|
|
|
|
|
|
# Fetch unfetched revisions.
|
2014-09-25 13:25:14 +00:00
|
|
|
self.vc.Fetch()
|
2013-11-08 14:27:16 +00:00
|
|
|
|
2013-11-18 14:10:47 +00:00
|
|
|
def PrepareBranch(self):
|
2013-11-08 14:27:16 +00:00
|
|
|
# Delete the branch that will be created later if it exists already.
|
2014-09-23 14:41:36 +00:00
|
|
|
self.DeleteBranch(self._config["BRANCHNAME"])
|
2013-11-08 14:27:16 +00:00
|
|
|
|
|
|
|
def CommonCleanup(self):
|
2014-10-14 12:19:32 +00:00
|
|
|
if ' ' in self["current_branch"]:
|
|
|
|
self.GitCheckout('master')
|
|
|
|
else:
|
|
|
|
self.GitCheckout(self["current_branch"])
|
2014-09-23 14:41:36 +00:00
|
|
|
if self._config["BRANCHNAME"] != self["current_branch"]:
|
|
|
|
self.GitDeleteBranch(self._config["BRANCHNAME"])
|
2013-11-08 14:27:16 +00:00
|
|
|
|
|
|
|
# Clean up all temporary files.
|
2014-09-23 14:41:36 +00:00
|
|
|
for f in glob.iglob("%s*" % self._config["PERSISTFILE_BASENAME"]):
|
2014-09-05 09:19:48 +00:00
|
|
|
if os.path.isfile(f):
|
|
|
|
os.remove(f)
|
|
|
|
if os.path.isdir(f):
|
|
|
|
shutil.rmtree(f)
|
2013-11-08 14:27:16 +00:00
|
|
|
|
|
|
|
def ReadAndPersistVersion(self, prefix=""):
|
|
|
|
def ReadAndPersist(var_name, def_name):
|
|
|
|
match = re.match(r"^#define %s\s+(\d*)" % def_name, line)
|
|
|
|
if match:
|
|
|
|
value = match.group(1)
|
2014-02-19 11:56:48 +00:00
|
|
|
self["%s%s" % (prefix, var_name)] = value
|
2014-09-23 09:35:49 +00:00
|
|
|
for line in LinesInFile(os.path.join(self.default_cwd, VERSION_FILE)):
|
2013-11-08 14:27:16 +00:00
|
|
|
for (var_name, def_name) in [("major", "MAJOR_VERSION"),
|
|
|
|
("minor", "MINOR_VERSION"),
|
|
|
|
("build", "BUILD_NUMBER"),
|
|
|
|
("patch", "PATCH_LEVEL")]:
|
|
|
|
ReadAndPersist(var_name, def_name)
|
|
|
|
|
|
|
|
def WaitForLGTM(self):
|
|
|
|
print ("Please wait for an LGTM, then type \"LGTM<Return>\" to commit "
|
|
|
|
"your change. (If you need to iterate on the patch or double check "
|
|
|
|
"that it's sane, do so in another shell, but remember to not "
|
|
|
|
"change the headline of the uploaded CL.")
|
|
|
|
answer = ""
|
|
|
|
while answer != "LGTM":
|
|
|
|
print "> ",
|
2013-12-16 10:56:52 +00:00
|
|
|
answer = self.ReadLine(None if self._options.wait_for_lgtm else "LGTM")
|
2013-11-08 14:27:16 +00:00
|
|
|
if answer != "LGTM":
|
|
|
|
print "That was not 'LGTM'."
|
|
|
|
|
|
|
|
def WaitForResolvingConflicts(self, patch_file):
|
|
|
|
print("Applying the patch \"%s\" failed. Either type \"ABORT<Return>\", "
|
|
|
|
"or resolve the conflicts, stage *all* touched files with "
|
|
|
|
"'git add', and type \"RESOLVED<Return>\"")
|
2013-12-04 08:47:18 +00:00
|
|
|
self.DieNoManualMode()
|
2013-11-08 14:27:16 +00:00
|
|
|
answer = ""
|
|
|
|
while answer != "RESOLVED":
|
|
|
|
if answer == "ABORT":
|
|
|
|
self.Die("Applying the patch failed.")
|
|
|
|
if answer != "":
|
|
|
|
print "That was not 'RESOLVED' or 'ABORT'."
|
|
|
|
print "> ",
|
|
|
|
answer = self.ReadLine()
|
|
|
|
|
|
|
|
# Takes a file containing the patch to apply as first argument.
|
2014-02-20 16:39:41 +00:00
|
|
|
def ApplyPatch(self, patch_file, revert=False):
|
2014-02-19 14:56:19 +00:00
|
|
|
try:
|
2014-02-20 16:39:41 +00:00
|
|
|
self.GitApplyPatch(patch_file, revert)
|
2014-02-19 14:56:19 +00:00
|
|
|
except GitFailedException:
|
2013-11-08 14:27:16 +00:00
|
|
|
self.WaitForResolvingConflicts(patch_file)
|
|
|
|
|
2014-09-04 08:42:21 +00:00
|
|
|
def FindLastTrunkPush(
|
|
|
|
self, parent_hash="", branch="", include_patches=False):
|
2014-04-04 07:23:45 +00:00
|
|
|
push_pattern = "^Version [[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*"
|
|
|
|
if not include_patches:
|
|
|
|
# Non-patched versions only have three numbers followed by the "(based
|
|
|
|
# on...) comment."
|
|
|
|
push_pattern += " (based"
|
2014-09-25 13:25:14 +00:00
|
|
|
branch = "" if parent_hash else branch or self.vc.RemoteCandidateBranch()
|
2014-02-20 16:39:41 +00:00
|
|
|
return self.GitLog(n=1, format="%H", grep=push_pattern,
|
|
|
|
parent_hash=parent_hash, branch=branch)
|
2014-02-19 13:40:30 +00:00
|
|
|
|
2014-07-16 07:57:13 +00:00
|
|
|
def ArrayToVersion(self, prefix):
|
|
|
|
return ".".join([self[prefix + "major"],
|
|
|
|
self[prefix + "minor"],
|
|
|
|
self[prefix + "build"],
|
|
|
|
self[prefix + "patch"]])
|
|
|
|
|
|
|
|
def SetVersion(self, version_file, prefix):
|
|
|
|
output = ""
|
|
|
|
for line in FileToText(version_file).splitlines():
|
|
|
|
if line.startswith("#define MAJOR_VERSION"):
|
|
|
|
line = re.sub("\d+$", self[prefix + "major"], line)
|
|
|
|
elif line.startswith("#define MINOR_VERSION"):
|
|
|
|
line = re.sub("\d+$", self[prefix + "minor"], line)
|
|
|
|
elif line.startswith("#define BUILD_NUMBER"):
|
|
|
|
line = re.sub("\d+$", self[prefix + "build"], line)
|
|
|
|
elif line.startswith("#define PATCH_LEVEL"):
|
|
|
|
line = re.sub("\d+$", self[prefix + "patch"], line)
|
|
|
|
output += "%s\n" % line
|
|
|
|
TextToFile(output, version_file)
|
2013-11-08 14:27:16 +00:00
|
|
|
|
2014-09-07 08:02:05 +00:00
|
|
|
def SVNCommit(self, root, commit_message):
|
|
|
|
patch = self.GitDiff("HEAD^", "HEAD")
|
2014-09-23 14:41:36 +00:00
|
|
|
TextToFile(patch, self._config["PATCH_FILE"])
|
2014-09-07 08:11:32 +00:00
|
|
|
self.Command("svn", "update", cwd=self._options.svn)
|
|
|
|
if self.Command("svn", "status", cwd=self._options.svn) != "":
|
|
|
|
self.Die("SVN checkout not clean.")
|
2014-09-07 08:02:05 +00:00
|
|
|
if not self.Command("patch", "-d %s -p1 -i %s" %
|
2014-09-23 14:41:36 +00:00
|
|
|
(root, self._config["PATCH_FILE"]),
|
2014-09-07 08:02:05 +00:00
|
|
|
cwd=self._options.svn):
|
|
|
|
self.Die("Could not apply patch.")
|
|
|
|
self.Command(
|
|
|
|
"svn",
|
|
|
|
"commit --non-interactive --username=%s --config-dir=%s -m \"%s\"" %
|
|
|
|
(self._options.author, self._options.svn_config, commit_message),
|
|
|
|
cwd=self._options.svn)
|
|
|
|
|
|
|
|
|
2013-11-08 14:27:16 +00:00
|
|
|
class UploadStep(Step):
|
2013-11-22 09:48:43 +00:00
|
|
|
MESSAGE = "Upload for code review."
|
2013-11-08 14:27:16 +00:00
|
|
|
|
|
|
|
def RunStep(self):
|
2014-02-18 13:09:14 +00:00
|
|
|
if self._options.reviewer:
|
|
|
|
print "Using account %s for review." % self._options.reviewer
|
|
|
|
reviewer = self._options.reviewer
|
2013-11-20 08:49:42 +00:00
|
|
|
else:
|
|
|
|
print "Please enter the email address of a V8 reviewer for your patch: ",
|
2013-12-04 08:47:18 +00:00
|
|
|
self.DieNoManualMode("A reviewer must be specified in forced mode.")
|
2013-11-20 08:49:42 +00:00
|
|
|
reviewer = self.ReadLine()
|
2014-09-10 07:51:13 +00:00
|
|
|
self.GitUpload(reviewer, self._options.author, self._options.force_upload,
|
2014-09-25 11:28:27 +00:00
|
|
|
bypass_hooks=self._options.bypass_upload_hooks,
|
|
|
|
cc=self._options.cc)
|
2013-11-18 14:10:47 +00:00
|
|
|
|
|
|
|
|
2014-04-08 12:07:49 +00:00
|
|
|
class DetermineV8Sheriff(Step):
|
|
|
|
MESSAGE = "Determine the V8 sheriff for code review."
|
|
|
|
|
|
|
|
def RunStep(self):
|
|
|
|
self["sheriff"] = None
|
|
|
|
if not self._options.sheriff: # pragma: no cover
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
# The googlers mapping maps @google.com accounts to @chromium.org
|
|
|
|
# accounts.
|
|
|
|
googlers = imp.load_source('googlers_mapping',
|
|
|
|
self._options.googlers_mapping)
|
|
|
|
googlers = googlers.list_to_dict(googlers.get_list())
|
|
|
|
except: # pragma: no cover
|
|
|
|
print "Skip determining sheriff without googler mapping."
|
|
|
|
return
|
|
|
|
|
|
|
|
# The sheriff determined by the rotation on the waterfall has a
|
|
|
|
# @google.com account.
|
|
|
|
url = "https://chromium-build.appspot.com/p/chromium/sheriff_v8.js"
|
|
|
|
match = re.match(r"document\.write\('(\w+)'\)", self.ReadURL(url))
|
|
|
|
|
|
|
|
# If "channel is sheriff", we can't match an account.
|
|
|
|
if match:
|
|
|
|
g_name = match.group(1)
|
|
|
|
self["sheriff"] = googlers.get(g_name + "@google.com",
|
|
|
|
g_name + "@chromium.org")
|
|
|
|
self._options.reviewer = self["sheriff"]
|
|
|
|
print "Found active sheriff: %s" % self["sheriff"]
|
|
|
|
else:
|
|
|
|
print "No active sheriff found."
|
|
|
|
|
|
|
|
|
2013-11-22 09:48:43 +00:00
|
|
|
def MakeStep(step_class=Step, number=0, state=None, config=None,
|
|
|
|
options=None, side_effect_handler=DEFAULT_SIDE_EFFECT_HANDLER):
|
|
|
|
# Allow to pass in empty dictionaries.
|
|
|
|
state = state if state is not None else {}
|
|
|
|
config = config if config is not None else {}
|
|
|
|
|
|
|
|
try:
|
|
|
|
message = step_class.MESSAGE
|
|
|
|
except AttributeError:
|
|
|
|
message = step_class.__name__
|
|
|
|
|
2014-09-23 09:35:49 +00:00
|
|
|
return step_class(message, number=number, config=config,
|
2013-11-22 09:48:43 +00:00
|
|
|
state=state, options=options,
|
|
|
|
handler=side_effect_handler)
|
|
|
|
|
|
|
|
|
2014-03-04 23:27:27 +00:00
|
|
|
class ScriptsBase(object):
|
2014-09-23 14:41:36 +00:00
|
|
|
def __init__(self,
|
|
|
|
config=None,
|
|
|
|
side_effect_handler=DEFAULT_SIDE_EFFECT_HANDLER,
|
2014-03-04 23:27:27 +00:00
|
|
|
state=None):
|
2014-09-23 14:41:36 +00:00
|
|
|
self._config = config or self._Config()
|
2014-03-04 23:27:27 +00:00
|
|
|
self._side_effect_handler = side_effect_handler
|
|
|
|
self._state = state if state is not None else {}
|
|
|
|
|
|
|
|
def _Description(self):
|
|
|
|
return None
|
|
|
|
|
|
|
|
def _PrepareOptions(self, parser):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _ProcessOptions(self, options):
|
|
|
|
return True
|
|
|
|
|
2014-03-12 10:45:23 +00:00
|
|
|
def _Steps(self): # pragma: no cover
|
2014-03-04 23:27:27 +00:00
|
|
|
raise Exception("Not implemented.")
|
|
|
|
|
2014-09-23 14:41:36 +00:00
|
|
|
def _Config(self):
|
|
|
|
return {}
|
|
|
|
|
2014-03-04 23:27:27 +00:00
|
|
|
def MakeOptions(self, args=None):
|
|
|
|
parser = argparse.ArgumentParser(description=self._Description())
|
|
|
|
parser.add_argument("-a", "--author", default="",
|
|
|
|
help="The author email used for rietveld.")
|
2014-09-03 08:29:53 +00:00
|
|
|
parser.add_argument("--dry-run", default=False, action="store_true",
|
|
|
|
help="Perform only read-only actions.")
|
2014-04-08 12:07:49 +00:00
|
|
|
parser.add_argument("-g", "--googlers-mapping",
|
|
|
|
help="Path to the script mapping google accounts.")
|
2014-03-04 23:27:27 +00:00
|
|
|
parser.add_argument("-r", "--reviewer", default="",
|
|
|
|
help="The account name to be used for reviews.")
|
2014-04-08 12:07:49 +00:00
|
|
|
parser.add_argument("--sheriff", default=False, action="store_true",
|
|
|
|
help=("Determine current sheriff to review CLs. On "
|
|
|
|
"success, this will overwrite the reviewer "
|
|
|
|
"option."))
|
2014-09-07 08:02:05 +00:00
|
|
|
parser.add_argument("--svn",
|
|
|
|
help=("Optional full svn checkout for the commit."
|
|
|
|
"The folder needs to be the svn root."))
|
|
|
|
parser.add_argument("--svn-config",
|
|
|
|
help=("Optional folder used as svn --config-dir."))
|
2014-03-04 23:27:27 +00:00
|
|
|
parser.add_argument("-s", "--step",
|
2014-04-08 12:07:49 +00:00
|
|
|
help="Specify the step where to start work. Default: 0.",
|
|
|
|
default=0, type=int)
|
2014-09-26 07:40:09 +00:00
|
|
|
parser.add_argument("--vc-interface",
|
|
|
|
help=("Choose VC interface out of git_svn|"
|
|
|
|
"git_read_svn_write."))
|
2014-03-04 23:27:27 +00:00
|
|
|
self._PrepareOptions(parser)
|
|
|
|
|
2014-03-12 10:45:23 +00:00
|
|
|
if args is None: # pragma: no cover
|
2014-03-04 23:27:27 +00:00
|
|
|
options = parser.parse_args()
|
|
|
|
else:
|
|
|
|
options = parser.parse_args(args)
|
|
|
|
|
|
|
|
# Process common options.
|
2014-03-12 10:45:23 +00:00
|
|
|
if options.step < 0: # pragma: no cover
|
2014-03-04 23:27:27 +00:00
|
|
|
print "Bad step number %d" % options.step
|
|
|
|
parser.print_help()
|
|
|
|
return None
|
2014-04-08 12:07:49 +00:00
|
|
|
if options.sheriff and not options.googlers_mapping: # pragma: no cover
|
|
|
|
print "To determine the current sheriff, requires the googler mapping"
|
|
|
|
parser.print_help()
|
|
|
|
return None
|
2014-09-07 08:02:05 +00:00
|
|
|
if options.svn and not options.svn_config:
|
|
|
|
print "Using pure svn for committing requires also --svn-config"
|
|
|
|
parser.print_help()
|
|
|
|
return None
|
2014-03-04 23:27:27 +00:00
|
|
|
|
|
|
|
# Defaults for options, common to all scripts.
|
|
|
|
options.manual = getattr(options, "manual", True)
|
|
|
|
options.force = getattr(options, "force", False)
|
2014-09-10 07:51:13 +00:00
|
|
|
options.bypass_upload_hooks = False
|
2014-03-04 23:27:27 +00:00
|
|
|
|
|
|
|
# Derived options.
|
|
|
|
options.requires_editor = not options.force
|
|
|
|
options.wait_for_lgtm = not options.force
|
|
|
|
options.force_readline_defaults = not options.manual
|
|
|
|
options.force_upload = not options.manual
|
|
|
|
|
|
|
|
# Process script specific options.
|
|
|
|
if not self._ProcessOptions(options):
|
|
|
|
parser.print_help()
|
|
|
|
return None
|
2014-09-26 07:40:09 +00:00
|
|
|
|
|
|
|
if not options.vc_interface:
|
2014-10-23 14:27:15 +00:00
|
|
|
options.vc_interface = "git_read_svn_write"
|
2014-03-04 23:27:27 +00:00
|
|
|
return options
|
|
|
|
|
|
|
|
def RunSteps(self, step_classes, args=None):
|
|
|
|
options = self.MakeOptions(args)
|
|
|
|
if not options:
|
|
|
|
return 1
|
|
|
|
|
2014-09-23 14:41:36 +00:00
|
|
|
state_file = "%s-state.json" % self._config["PERSISTFILE_BASENAME"]
|
2014-03-04 23:27:27 +00:00
|
|
|
if options.step == 0 and os.path.exists(state_file):
|
|
|
|
os.remove(state_file)
|
|
|
|
|
|
|
|
steps = []
|
|
|
|
for (number, step_class) in enumerate(step_classes):
|
|
|
|
steps.append(MakeStep(step_class, number, self._state, self._config,
|
|
|
|
options, self._side_effect_handler))
|
|
|
|
for step in steps[options.step:]:
|
2014-04-02 06:59:25 +00:00
|
|
|
if step.Run():
|
2014-09-04 10:19:44 +00:00
|
|
|
return 0
|
2014-03-04 23:27:27 +00:00
|
|
|
return 0
|
|
|
|
|
|
|
|
def Run(self, args=None):
|
|
|
|
return self.RunSteps(self._Steps(), args)
|