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 |
| 27 import re |
26 import sys | 28 import sys |
27 | 29 |
| 30 from common_includes import * |
| 31 |
28 TARGET_SUBDIR = os.path.join("deps", "v8") | 32 TARGET_SUBDIR = os.path.join("deps", "v8") |
| 33 VERSION_FILE = os.path.join("include", "v8-version.h") |
| 34 VERSION_PATTERN = r'(?<=#define V8_PATCH_LEVEL )\d+' |
| 35 |
| 36 def Clean(options): |
| 37 print ">> Cleaning target directory." |
| 38 subprocess.check_call(["git", "clean", "-fd"], |
| 39 cwd = os.path.join(options.node_path, TARGET_SUBDIR)) |
29 | 40 |
30 def CherryPick(options): | 41 def CherryPick(options): |
31 print ">> Apply patch." | 42 print ">> Apply patch." |
32 patch = subprocess.Popen(["git", "diff-tree", "-p", options.commit], | 43 patch = subprocess.Popen(["git", "diff-tree", "-p", options.commit], |
33 stdout=subprocess.PIPE, cwd=options.v8_path) | 44 stdout=subprocess.PIPE, cwd=options.v8_path) |
34 patch.wait() | 45 patch.wait() |
35 try: | 46 try: |
36 subprocess.check_output(["git", "apply", "-3", "--directory=%s" % TARGET_SUB
DIR], | 47 subprocess.check_output(["git", "apply", "-3", "--directory=%s" % TARGET_SUB
DIR], |
37 stdin=patch.stdout, cwd=options.node_path) | 48 stdin=patch.stdout, cwd=options.node_path) |
38 except: | 49 except: |
39 print ">> In another shell, please resolve patch conflicts" | 50 print ">> In another shell, please resolve patch conflicts" |
40 print ">> and `git add` affected files." | 51 print ">> and `git add` affected files." |
41 print ">> Finally continue by entering RESOLVED." | 52 print ">> Finally continue by entering RESOLVED." |
42 while raw_input("[RESOLVED]") != "RESOLVED": | 53 while raw_input("[RESOLVED]") != "RESOLVED": |
43 print ">> You need to type RESOLVED" | 54 print ">> You need to type RESOLVED" |
44 | 55 |
| 56 def UpdateVersion(options): |
| 57 print ">> Increment patch level." |
| 58 version_file = os.path.join(options.node_path, TARGET_SUBDIR, VERSION_FILE) |
| 59 text = FileToText(version_file) |
| 60 def increment(match): |
| 61 patch = int(match.group(0)) |
| 62 return str(patch + 1) |
| 63 text = re.sub(VERSION_PATTERN, increment, text, flags=re.MULTILINE) |
| 64 TextToFile(text, version_file) |
| 65 |
45 def CreateCommit(options): | 66 def CreateCommit(options): |
46 print ">> Creating commit." | 67 print ">> Creating commit." |
47 # Find short hash from source. | 68 # Find short hash from source. |
48 shorthash = subprocess.check_output( | 69 shorthash = subprocess.check_output( |
49 ["git", "rev-parse", "--short", options.commit], | 70 ["git", "rev-parse", "--short", options.commit], |
50 cwd=options.v8_path).strip() | 71 cwd=options.v8_path).strip() |
51 | 72 |
52 # Commit message | 73 # Commit message |
53 title = "deps: backport %s from upstream V8" % shorthash | 74 title = "deps: backport %s from upstream V8" % shorthash |
54 body = subprocess.check_output( | 75 body = subprocess.check_output( |
(...skipping 22 matching lines...) Expand all Loading... |
77 help="Skip editing commit message") | 98 help="Skip editing commit message") |
78 options = parser.parse_args(args) | 99 options = parser.parse_args(args) |
79 options.v8_path = os.path.abspath(options.v8_path) | 100 options.v8_path = os.path.abspath(options.v8_path) |
80 assert os.path.isdir(options.v8_path) | 101 assert os.path.isdir(options.v8_path) |
81 options.node_path = os.path.abspath(options.node_path) | 102 options.node_path = os.path.abspath(options.node_path) |
82 assert os.path.isdir(options.node_path) | 103 assert os.path.isdir(options.node_path) |
83 return options | 104 return options |
84 | 105 |
85 def Main(args): | 106 def Main(args): |
86 options = ParseOptions(args) | 107 options = ParseOptions(args) |
| 108 Clean(options) |
87 try: | 109 try: |
88 CherryPick(options) | 110 CherryPick(options) |
| 111 UpdateVersion(options) |
89 CreateCommit(options) | 112 CreateCommit(options) |
90 except: | 113 except: |
91 print ">> Failed. Resetting." | 114 print ">> Failed. Resetting." |
92 subprocess.check_output(["git", "reset", "--hard"], cwd=options.node_path) | 115 subprocess.check_output(["git", "reset", "--hard"], cwd=options.node_path) |
93 raise | 116 raise |
94 | 117 |
95 if __name__ == "__main__": | 118 if __name__ == "__main__": |
96 Main(sys.argv[1:]) | 119 Main(sys.argv[1:]) |
OLD | NEW |