OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2017 the V8 project authors. All rights reserved. | 2 # Copyright 2017 the V8 project authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """ | 6 """ |
7 Use this script to cherry-pick a V8 commit to backport to a Node.js checkout. | 7 Use this script to cherry-pick a V8 commit to backport to a Node.js checkout. |
8 | 8 |
9 Requirements: | 9 Requirements: |
10 - Node.js checkout to backport to. | 10 - Node.js checkout to backport to. |
11 - V8 checkout that contains the commit to cherry-pick. | 11 - V8 checkout that contains the commit to cherry-pick. |
12 | 12 |
13 Usage: | 13 Usage: |
14 $ backport_node.py <path_to_v8> <path_to_node> <commit-hash> | 14 $ backport_node.py <path_to_v8> <path_to_node> <commit-hash> |
15 | 15 |
16 This will apply the commit to <path_to_node>/deps/v8 and create a commit in | 16 This will apply the commit to <path_to_node>/deps/v8 and create a commit in |
17 the Node.js checkout and copy over the original commit message. | 17 the Node.js checkout, increment patch level, and copy over the original |
18 commit message. | |
18 | 19 |
19 Optional flags: | 20 Optional flags: |
20 --no-review Run `gclient sync` on the V8 checkout before updating. | 21 --no-review Run `gclient sync` on the V8 checkout before updating. |
21 """ | 22 """ |
22 | 23 |
23 import argparse | 24 import argparse |
24 import os | 25 import os |
25 import subprocess | 26 import subprocess |
26 import sys | 27 import sys |
28 import re | |
Michael Achenbach
2017/04/27 13:22:04
nit: sort imports, separate local imports with an
Yang
2017/04/27 14:18:57
Done.
| |
29 from common_includes import * | |
27 | 30 |
28 TARGET_SUBDIR = os.path.join("deps", "v8") | 31 TARGET_SUBDIR = os.path.join("deps", "v8") |
32 VERSION_FILE = os.path.join("include", "v8-version.h") | |
33 VERSION_PATTERN = r'(?<=#define V8_PATCH_LEVEL )\d+' | |
34 | |
35 def Clean(options): | |
36 print ">> Cleaning target directory." | |
37 subprocess.check_call(["git", "clean", "-fd"], | |
38 cwd = os.path.join(options.node_path, TARGET_SUBDIR)) | |
29 | 39 |
30 def CherryPick(options): | 40 def CherryPick(options): |
31 print ">> Apply patch." | 41 print ">> Apply patch." |
32 patch = subprocess.Popen(["git", "diff-tree", "-p", options.commit], | 42 patch = subprocess.Popen(["git", "diff-tree", "-p", options.commit], |
33 stdout=subprocess.PIPE, cwd=options.v8_path) | 43 stdout=subprocess.PIPE, cwd=options.v8_path) |
34 patch.wait() | 44 patch.wait() |
35 try: | 45 try: |
36 subprocess.check_output(["git", "apply", "-3", "--directory=%s" % TARGET_SUB DIR], | 46 subprocess.check_output(["git", "apply", "-3", "--directory=%s" % TARGET_SUB DIR], |
37 stdin=patch.stdout, cwd=options.node_path) | 47 stdin=patch.stdout, cwd=options.node_path) |
38 except: | 48 except: |
39 print ">> In another shell, please resolve patch conflicts" | 49 print ">> In another shell, please resolve patch conflicts" |
40 print ">> and `git add` affected files." | 50 print ">> and `git add` affected files." |
41 print ">> Finally continue by entering RESOLVED." | 51 print ">> Finally continue by entering RESOLVED." |
42 while raw_input("[RESOLVED]") != "RESOLVED": | 52 while raw_input("[RESOLVED]") != "RESOLVED": |
43 print ">> You need to type RESOLVED" | 53 print ">> You need to type RESOLVED" |
44 | 54 |
55 def UpdateVersion(options): | |
56 print ">> Increment patch level." | |
57 version_file = os.path.join(options.node_path, TARGET_SUBDIR, VERSION_FILE) | |
58 text = FileToText(version_file) | |
59 def increment(match): | |
60 patch = int(match.group(0)) | |
61 return str(patch + 1) | |
62 text = re.sub(VERSION_PATTERN, increment, text, flags=re.MULTILINE) | |
63 TextToFile(text, version_file) | |
64 | |
45 def CreateCommit(options): | 65 def CreateCommit(options): |
46 print ">> Creating commit." | 66 print ">> Creating commit." |
47 # Find short hash from source. | 67 # Find short hash from source. |
48 shorthash = subprocess.check_output( | 68 shorthash = subprocess.check_output( |
49 ["git", "rev-parse", "--short", options.commit], | 69 ["git", "rev-parse", "--short", options.commit], |
50 cwd=options.v8_path).strip() | 70 cwd=options.v8_path).strip() |
51 | 71 |
52 # Commit message | 72 # Commit message |
53 title = "deps: backport %s from upstream V8" % shorthash | 73 title = "deps: backport %s from upstream V8" % shorthash |
54 body = subprocess.check_output( | 74 body = subprocess.check_output( |
(...skipping 22 matching lines...) Expand all Loading... | |
77 help="Skip editing commit message") | 97 help="Skip editing commit message") |
78 options = parser.parse_args(args) | 98 options = parser.parse_args(args) |
79 options.v8_path = os.path.abspath(options.v8_path) | 99 options.v8_path = os.path.abspath(options.v8_path) |
80 assert os.path.isdir(options.v8_path) | 100 assert os.path.isdir(options.v8_path) |
81 options.node_path = os.path.abspath(options.node_path) | 101 options.node_path = os.path.abspath(options.node_path) |
82 assert os.path.isdir(options.node_path) | 102 assert os.path.isdir(options.node_path) |
83 return options | 103 return options |
84 | 104 |
85 def Main(args): | 105 def Main(args): |
86 options = ParseOptions(args) | 106 options = ParseOptions(args) |
107 Clean(options) | |
87 try: | 108 try: |
88 CherryPick(options) | 109 CherryPick(options) |
110 UpdateVersion(options) | |
89 CreateCommit(options) | 111 CreateCommit(options) |
90 except: | 112 except: |
91 print ">> Failed. Resetting." | 113 print ">> Failed. Resetting." |
92 subprocess.check_output(["git", "reset", "--hard"], cwd=options.node_path) | 114 subprocess.check_output(["git", "reset", "--hard"], cwd=options.node_path) |
93 raise | 115 raise |
94 | 116 |
95 if __name__ == "__main__": | 117 if __name__ == "__main__": |
96 Main(sys.argv[1:]) | 118 Main(sys.argv[1:]) |
OLD | NEW |