OLD | NEW |
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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 def GetUTCStamp(self): | 248 def GetUTCStamp(self): |
249 return time.mktime(datetime.datetime.utcnow().timetuple()) | 249 return time.mktime(datetime.datetime.utcnow().timetuple()) |
250 | 250 |
251 DEFAULT_SIDE_EFFECT_HANDLER = SideEffectHandler() | 251 DEFAULT_SIDE_EFFECT_HANDLER = SideEffectHandler() |
252 | 252 |
253 | 253 |
254 class NoRetryException(Exception): | 254 class NoRetryException(Exception): |
255 pass | 255 pass |
256 | 256 |
257 | 257 |
| 258 class VCInterface(object): |
| 259 def InjectStep(self, step): |
| 260 self.step=step |
| 261 |
| 262 def Pull(self): |
| 263 raise NotImplementedError() |
| 264 |
| 265 def Fetch(self): |
| 266 raise NotImplementedError() |
| 267 |
| 268 def GetTags(self): |
| 269 raise NotImplementedError() |
| 270 |
| 271 def GetBranches(self): |
| 272 raise NotImplementedError() |
| 273 |
| 274 def GitSvn(self, hsh, branch=""): |
| 275 raise NotImplementedError() |
| 276 |
| 277 def SvnGit(self, rev, branch=""): |
| 278 raise NotImplementedError() |
| 279 |
| 280 def RemoteMasterBranch(self): |
| 281 raise NotImplementedError() |
| 282 |
| 283 def RemoteCandidateBranch(self): |
| 284 raise NotImplementedError() |
| 285 |
| 286 def RemoteBranch(self, name): |
| 287 raise NotImplementedError() |
| 288 |
| 289 def Land(self): |
| 290 raise NotImplementedError() |
| 291 |
| 292 def CLLand(self): |
| 293 raise NotImplementedError() |
| 294 |
| 295 # TODO(machenbach): There is some svn knowledge in this interface. In svn, |
| 296 # tag and commit are different remote commands, while in git we would commit |
| 297 # and tag locally and then push/land in one unique step. |
| 298 def Tag(self, tag): |
| 299 raise NotImplementedError() |
| 300 |
| 301 |
| 302 class GitSvnInterface(VCInterface): |
| 303 def Pull(self): |
| 304 self.step.GitSVNRebase() |
| 305 |
| 306 def Fetch(self): |
| 307 self.step.GitSVNFetch() |
| 308 |
| 309 def GetTags(self): |
| 310 # Get remote tags. |
| 311 tags = filter(lambda s: re.match(r"^svn/tags/[\d+\.]+$", s), |
| 312 self.step.GitRemotes()) |
| 313 |
| 314 # Remove 'svn/tags/' prefix. |
| 315 return map(lambda s: s[9:], tags) |
| 316 |
| 317 def GetBranches(self): |
| 318 # Get relevant remote branches, e.g. "svn/3.25". |
| 319 branches = filter(lambda s: re.match(r"^svn/\d+\.\d+$", s), |
| 320 self.step.GitRemotes()) |
| 321 # Remove 'svn/' prefix. |
| 322 return map(lambda s: s[4:], branches) |
| 323 |
| 324 def GitSvn(self, hsh, branch=""): |
| 325 return self.step.GitSVNFindSVNRev(hsh, branch) |
| 326 |
| 327 def SvnGit(self, rev, branch=""): |
| 328 return self.step.GitSVNFindGitHash(rev, branch) |
| 329 |
| 330 def RemoteMasterBranch(self): |
| 331 return "svn/bleeding_edge" |
| 332 |
| 333 def RemoteCandidateBranch(self): |
| 334 return "svn/trunk" |
| 335 |
| 336 def RemoteBranch(self, name): |
| 337 return "svn/%s" % name |
| 338 |
| 339 def Land(self): |
| 340 return self.step.GitSVNDCommit() |
| 341 |
| 342 def CLLand(self): |
| 343 return self.step.GitDCommit() |
| 344 |
| 345 def Tag(self, tag): |
| 346 self.step.GitSVNTag(tag) |
| 347 |
| 348 |
| 349 |
258 class Step(GitRecipesMixin): | 350 class Step(GitRecipesMixin): |
259 def __init__(self, text, number, config, state, options, handler): | 351 def __init__(self, text, number, config, state, options, handler): |
260 self._text = text | 352 self._text = text |
261 self._number = number | 353 self._number = number |
262 self._config = config | 354 self._config = config |
263 self._state = state | 355 self._state = state |
264 self._options = options | 356 self._options = options |
265 self._side_effect_handler = handler | 357 self._side_effect_handler = handler |
| 358 self.vc = GitSvnInterface() |
| 359 self.vc.InjectStep(self) |
266 | 360 |
267 # The testing configuration might set a different default cwd. | 361 # The testing configuration might set a different default cwd. |
268 self.default_cwd = self._config.get("DEFAULT_CWD") or DEFAULT_CWD | 362 self.default_cwd = self._config.get("DEFAULT_CWD") or DEFAULT_CWD |
269 | 363 |
270 assert self._number >= 0 | 364 assert self._number >= 0 |
271 assert self._config is not None | 365 assert self._config is not None |
272 assert self._state is not None | 366 assert self._state is not None |
273 assert self._side_effect_handler is not None | 367 assert self._side_effect_handler is not None |
274 | 368 |
275 def __getitem__(self, key): | 369 def __getitem__(self, key): |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 | 509 |
416 def CommonPrepare(self): | 510 def CommonPrepare(self): |
417 # Check for a clean workdir. | 511 # Check for a clean workdir. |
418 if not self.GitIsWorkdirClean(): # pragma: no cover | 512 if not self.GitIsWorkdirClean(): # pragma: no cover |
419 self.Die("Workspace is not clean. Please commit or undo your changes.") | 513 self.Die("Workspace is not clean. Please commit or undo your changes.") |
420 | 514 |
421 # Persist current branch. | 515 # Persist current branch. |
422 self["current_branch"] = self.GitCurrentBranch() | 516 self["current_branch"] = self.GitCurrentBranch() |
423 | 517 |
424 # Fetch unfetched revisions. | 518 # Fetch unfetched revisions. |
425 self.GitSVNFetch() | 519 self.vc.Fetch() |
426 | 520 |
427 def PrepareBranch(self): | 521 def PrepareBranch(self): |
428 # Delete the branch that will be created later if it exists already. | 522 # Delete the branch that will be created later if it exists already. |
429 self.DeleteBranch(self._config["BRANCHNAME"]) | 523 self.DeleteBranch(self._config["BRANCHNAME"]) |
430 | 524 |
431 def CommonCleanup(self): | 525 def CommonCleanup(self): |
432 self.GitCheckout(self["current_branch"]) | 526 self.GitCheckout(self["current_branch"]) |
433 if self._config["BRANCHNAME"] != self["current_branch"]: | 527 if self._config["BRANCHNAME"] != self["current_branch"]: |
434 self.GitDeleteBranch(self._config["BRANCHNAME"]) | 528 self.GitDeleteBranch(self._config["BRANCHNAME"]) |
435 | 529 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 except GitFailedException: | 580 except GitFailedException: |
487 self.WaitForResolvingConflicts(patch_file) | 581 self.WaitForResolvingConflicts(patch_file) |
488 | 582 |
489 def FindLastTrunkPush( | 583 def FindLastTrunkPush( |
490 self, parent_hash="", branch="", include_patches=False): | 584 self, parent_hash="", branch="", include_patches=False): |
491 push_pattern = "^Version [[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*" | 585 push_pattern = "^Version [[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*" |
492 if not include_patches: | 586 if not include_patches: |
493 # Non-patched versions only have three numbers followed by the "(based | 587 # Non-patched versions only have three numbers followed by the "(based |
494 # on...) comment." | 588 # on...) comment." |
495 push_pattern += " (based" | 589 push_pattern += " (based" |
496 branch = "" if parent_hash else branch or "svn/trunk" | 590 branch = "" if parent_hash else branch or self.vc.RemoteCandidateBranch() |
497 return self.GitLog(n=1, format="%H", grep=push_pattern, | 591 return self.GitLog(n=1, format="%H", grep=push_pattern, |
498 parent_hash=parent_hash, branch=branch) | 592 parent_hash=parent_hash, branch=branch) |
499 | 593 |
500 def ArrayToVersion(self, prefix): | 594 def ArrayToVersion(self, prefix): |
501 return ".".join([self[prefix + "major"], | 595 return ".".join([self[prefix + "major"], |
502 self[prefix + "minor"], | 596 self[prefix + "minor"], |
503 self[prefix + "build"], | 597 self[prefix + "build"], |
504 self[prefix + "patch"]]) | 598 self[prefix + "patch"]]) |
505 | 599 |
506 def SetVersion(self, version_file, prefix): | 600 def SetVersion(self, version_file, prefix): |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 for (number, step_class) in enumerate(step_classes): | 790 for (number, step_class) in enumerate(step_classes): |
697 steps.append(MakeStep(step_class, number, self._state, self._config, | 791 steps.append(MakeStep(step_class, number, self._state, self._config, |
698 options, self._side_effect_handler)) | 792 options, self._side_effect_handler)) |
699 for step in steps[options.step:]: | 793 for step in steps[options.step:]: |
700 if step.Run(): | 794 if step.Run(): |
701 return 0 | 795 return 0 |
702 return 0 | 796 return 0 |
703 | 797 |
704 def Run(self, args=None): | 798 def Run(self, args=None): |
705 return self.RunSteps(self._Steps(), args) | 799 return self.RunSteps(self._Steps(), args) |
OLD | NEW |