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

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

Issue 71163006: Merge bleeding_edge r17376:17693. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Fix all.gyp Created 7 years, 1 month 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/presubmit.py ('k') | tools/push-to-trunk/push_to_trunk.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2013 the V8 project authors. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following
11 # disclaimer in the documentation and/or other materials provided
12 # with the distribution.
13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived
15 # from this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 import os
30 import re
31 import subprocess
32 import sys
33
34 PERSISTFILE_BASENAME = "PERSISTFILE_BASENAME"
35 TEMP_BRANCH = "TEMP_BRANCH"
36 BRANCHNAME = "BRANCHNAME"
37 DOT_GIT_LOCATION = "DOT_GIT_LOCATION"
38 VERSION_FILE = "VERSION_FILE"
39 CHANGELOG_FILE = "CHANGELOG_FILE"
40 CHANGELOG_ENTRY_FILE = "CHANGELOG_ENTRY_FILE"
41 COMMITMSG_FILE = "COMMITMSG_FILE"
42 PATCH_FILE = "PATCH_FILE"
43
44
45 def TextToFile(text, file_name):
46 with open(file_name, "w") as f:
47 f.write(text)
48
49
50 def AppendToFile(text, file_name):
51 with open(file_name, "a") as f:
52 f.write(text)
53
54
55 def LinesInFile(file_name):
56 with open(file_name) as f:
57 for line in f:
58 yield line
59
60
61 def FileToText(file_name):
62 with open(file_name) as f:
63 return f.read()
64
65
66 def MSub(rexp, replacement, text):
67 return re.sub(rexp, replacement, text, flags=re.MULTILINE)
68
69
70 def GetLastChangeLogEntries(change_log_file):
71 result = []
72 for line in LinesInFile(change_log_file):
73 if re.search(r"^\d{4}-\d{2}-\d{2}:", line) and result: break
74 result.append(line)
75 return "".join(result)
76
77
78 # Some commands don't like the pipe, e.g. calling vi from within the script or
79 # from subscripts like git cl upload.
80 def Command(cmd, args="", prefix="", pipe=True):
81 cmd_line = "%s %s %s" % (prefix, cmd, args)
82 print "Command: %s" % cmd_line
83 try:
84 if pipe:
85 return subprocess.check_output(cmd_line, shell=True)
86 else:
87 return subprocess.check_call(cmd_line, shell=True)
88 except subprocess.CalledProcessError:
89 return None
90
91
92 # Wrapper for side effects.
93 class SideEffectHandler(object):
94 def Command(self, cmd, args="", prefix="", pipe=True):
95 return Command(cmd, args, prefix, pipe)
96
97 def ReadLine(self):
98 return sys.stdin.readline().strip()
99
100 DEFAULT_SIDE_EFFECT_HANDLER = SideEffectHandler()
101
102
103 class Step(object):
104 def __init__(self, text="", requires=None):
105 self._text = text
106 self._number = -1
107 self._requires = requires
108 self._side_effect_handler = DEFAULT_SIDE_EFFECT_HANDLER
109
110 def SetNumber(self, number):
111 self._number = number
112
113 def SetConfig(self, config):
114 self._config = config
115
116 def SetState(self, state):
117 self._state = state
118
119 def SetOptions(self, options):
120 self._options = options
121
122 def SetSideEffectHandler(self, handler):
123 self._side_effect_handler = handler
124
125 def Config(self, key):
126 return self._config[key]
127
128 def Run(self):
129 assert self._number >= 0
130 assert self._config is not None
131 assert self._state is not None
132 assert self._side_effect_handler is not None
133 if self._requires:
134 self.RestoreIfUnset(self._requires)
135 if not self._state[self._requires]:
136 return
137 print ">>> Step %d: %s" % (self._number, self._text)
138 self.RunStep()
139
140 def RunStep(self):
141 raise NotImplementedError
142
143 def ReadLine(self):
144 return self._side_effect_handler.ReadLine()
145
146 def Git(self, args="", prefix="", pipe=True):
147 return self._side_effect_handler.Command("git", args, prefix, pipe)
148
149 def Editor(self, args):
150 return self._side_effect_handler.Command(os.environ["EDITOR"], args,
151 pipe=False)
152
153 def Die(self, msg=""):
154 if msg != "":
155 print "Error: %s" % msg
156 print "Exiting"
157 raise Exception(msg)
158
159 def Confirm(self, msg):
160 print "%s [Y/n] " % msg,
161 answer = self.ReadLine()
162 return answer == "" or answer == "Y" or answer == "y"
163
164 def DeleteBranch(self, name):
165 git_result = self.Git("branch").strip()
166 for line in git_result.splitlines():
167 if re.match(r".*\s+%s$" % name, line):
168 msg = "Branch %s exists, do you want to delete it?" % name
169 if self.Confirm(msg):
170 if self.Git("branch -D %s" % name) is None:
171 self.Die("Deleting branch '%s' failed." % name)
172 print "Branch %s deleted." % name
173 else:
174 msg = "Can't continue. Please delete branch %s and try again." % name
175 self.Die(msg)
176
177 def Persist(self, var, value):
178 value = value or "__EMPTY__"
179 TextToFile(value, "%s-%s" % (self._config[PERSISTFILE_BASENAME], var))
180
181 def Restore(self, var):
182 value = FileToText("%s-%s" % (self._config[PERSISTFILE_BASENAME], var))
183 value = value or self.Die("Variable '%s' could not be restored." % var)
184 return "" if value == "__EMPTY__" else value
185
186 def RestoreIfUnset(self, var_name):
187 if self._state.get(var_name) is None:
188 self._state[var_name] = self.Restore(var_name)
189
190 def InitialEnvironmentChecks(self):
191 # Cancel if this is not a git checkout.
192 if not os.path.exists(self._config[DOT_GIT_LOCATION]):
193 self.Die("This is not a git checkout, this script won't work for you.")
194
195 # Cancel if EDITOR is unset or not executable.
196 if (not os.environ.get("EDITOR") or
197 Command("which", os.environ["EDITOR"]) is None):
198 self.Die("Please set your EDITOR environment variable, you'll need it.")
199
200 def CommonPrepare(self):
201 # Check for a clean workdir.
202 if self.Git("status -s -uno").strip() != "":
203 self.Die("Workspace is not clean. Please commit or undo your changes.")
204
205 # Persist current branch.
206 current_branch = ""
207 git_result = self.Git("status -s -b -uno").strip()
208 for line in git_result.splitlines():
209 match = re.match(r"^## (.+)", line)
210 if match:
211 current_branch = match.group(1)
212 break
213 self.Persist("current_branch", current_branch)
214
215 # Fetch unfetched revisions.
216 if self.Git("svn fetch") is None:
217 self.Die("'git svn fetch' failed.")
218
219 # Get ahold of a safe temporary branch and check it out.
220 if current_branch != self._config[TEMP_BRANCH]:
221 self.DeleteBranch(self._config[TEMP_BRANCH])
222 self.Git("checkout -b %s" % self._config[TEMP_BRANCH])
223
224 # Delete the branch that will be created later if it exists already.
225 self.DeleteBranch(self._config[BRANCHNAME])
226
227 def CommonCleanup(self):
228 self.RestoreIfUnset("current_branch")
229 self.Git("checkout -f %s" % self._state["current_branch"])
230 if self._config[TEMP_BRANCH] != self._state["current_branch"]:
231 self.Git("branch -D %s" % self._config[TEMP_BRANCH])
232 if self._config[BRANCHNAME] != self._state["current_branch"]:
233 self.Git("branch -D %s" % self._config[BRANCHNAME])
234
235 # Clean up all temporary files.
236 Command("rm", "-f %s*" % self._config[PERSISTFILE_BASENAME])
237
238 def ReadAndPersistVersion(self, prefix=""):
239 def ReadAndPersist(var_name, def_name):
240 match = re.match(r"^#define %s\s+(\d*)" % def_name, line)
241 if match:
242 value = match.group(1)
243 self.Persist("%s%s" % (prefix, var_name), value)
244 self._state["%s%s" % (prefix, var_name)] = value
245 for line in LinesInFile(self._config[VERSION_FILE]):
246 for (var_name, def_name) in [("major", "MAJOR_VERSION"),
247 ("minor", "MINOR_VERSION"),
248 ("build", "BUILD_NUMBER"),
249 ("patch", "PATCH_LEVEL")]:
250 ReadAndPersist(var_name, def_name)
251
252 def RestoreVersionIfUnset(self, prefix=""):
253 for v in ["major", "minor", "build", "patch"]:
254 self.RestoreIfUnset("%s%s" % (prefix, v))
255
256 def WaitForLGTM(self):
257 print ("Please wait for an LGTM, then type \"LGTM<Return>\" to commit "
258 "your change. (If you need to iterate on the patch or double check "
259 "that it's sane, do so in another shell, but remember to not "
260 "change the headline of the uploaded CL.")
261 answer = ""
262 while answer != "LGTM":
263 print "> ",
264 answer = self.ReadLine()
265 if answer != "LGTM":
266 print "That was not 'LGTM'."
267
268 def WaitForResolvingConflicts(self, patch_file):
269 print("Applying the patch \"%s\" failed. Either type \"ABORT<Return>\", "
270 "or resolve the conflicts, stage *all* touched files with "
271 "'git add', and type \"RESOLVED<Return>\"")
272 answer = ""
273 while answer != "RESOLVED":
274 if answer == "ABORT":
275 self.Die("Applying the patch failed.")
276 if answer != "":
277 print "That was not 'RESOLVED' or 'ABORT'."
278 print "> ",
279 answer = self.ReadLine()
280
281 # Takes a file containing the patch to apply as first argument.
282 def ApplyPatch(self, patch_file, reverse_patch=""):
283 args = "apply --index --reject %s \"%s\"" % (reverse_patch, patch_file)
284 if self.Git(args) is None:
285 self.WaitForResolvingConflicts(patch_file)
286
287
288 class UploadStep(Step):
289 def __init__(self):
290 Step.__init__(self, "Upload for code review.")
291
292 def RunStep(self):
293 print "Please enter the email address of a V8 reviewer for your patch: ",
294 reviewer = self.ReadLine()
295 args = "cl upload -r \"%s\" --send-mail" % reviewer
296 if self.Git(args,pipe=False) is None:
297 self.Die("'git cl upload' failed, please try again.")
OLDNEW
« no previous file with comments | « tools/presubmit.py ('k') | tools/push-to-trunk/push_to_trunk.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698