Skip to content

Commit b82c5e7

Browse files
mi-acCommit Bot
authored andcommitted
[tools] Make node udpate script able to apply patches
Bug: v8:6154 NOTRY=true Change-Id: I7f18efaf2f86b9dfa43f249d817777f19ee29c9b Reviewed-on: https://chromium-review.googlesource.com/467427 Reviewed-by: Franziska Hinkelmann <franzih@chromium.org> Reviewed-by: Yang Guo <yangguo@chromium.org> Commit-Queue: Michael Achenbach <machenbach@chromium.org> Cr-Commit-Position: refs/heads/master@{#44399}
1 parent a065579 commit b82c5e7

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

tools/release/test_update_node.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,13 @@ def testUpdate(self):
8484
shutil.copytree(src=os.path.join(TEST_DATA, 'node'), dst=node_cwd)
8585
gitify(os.path.join(node_cwd))
8686

87+
# Add a patch.
88+
with open(os.path.join(v8_cwd, 'v8_foo'), 'w') as f:
89+
f.write('zonk')
90+
subprocess.check_call(['git', 'add', 'v8_foo'], cwd=v8_cwd)
91+
8792
# Run update script.
88-
update_node.Main([v8_cwd, node_cwd, "--commit"])
93+
update_node.Main([v8_cwd, node_cwd, "--commit", "--with-patch"])
8994

9095
# Check expectations.
9196
with open(os.path.join(node_cwd, 'deps', 'v8', '.gitignore')) as f:
@@ -97,9 +102,18 @@ def testUpdate(self):
97102
for f in REMOVED_FILES:
98103
removed_file = os.path.join(node_cwd, 'deps', 'v8', *f.split('/'))
99104
self.assertFalse(os.path.exists(removed_file))
100-
gitlog = subprocess.check_output(['git', 'diff', 'master', '--summary'],
101-
cwd=node_cwd)
105+
gitlog = subprocess.check_output(
106+
['git', 'diff', 'master', '--summary'],
107+
cwd=node_cwd,
108+
)
102109
self.assertEquals(EXPECTED_GIT_DIFF.strip(), gitlog.strip())
103110

111+
# Check patch.
112+
gitlog = subprocess.check_output(
113+
['git', 'diff', 'master', '--cached', '--', 'deps/v8/v8_foo'],
114+
cwd=node_cwd,
115+
)
116+
self.assertIn('+zonk', gitlog.strip())
117+
104118
if __name__ == "__main__":
105119
unittest.main()

tools/release/update_node.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,27 @@ def UninitGit(path):
4343
print ">> Cleaning up %s" % path
4444
shutil.rmtree(target)
4545

46+
def ApplyIndex(source, target):
47+
if not subprocess.check_output(["git", "diff", "--cached"], cwd=source):
48+
print ">> Ignoring empty patch"
49+
return
50+
51+
print ">> Applying patch"
52+
diff_proc = subprocess.Popen(
53+
["git", "diff", "--cached"],
54+
cwd=source,
55+
stdout=subprocess.PIPE,
56+
)
57+
apply_proc = subprocess.Popen(
58+
["git", "apply", "--index"],
59+
cwd=target,
60+
stdin=diff_proc.stdout,
61+
)
62+
diff_proc.stdout.close()
63+
apply_proc.communicate()
64+
if apply_proc.returncode != 0:
65+
raise Exception("Error applying patch")
66+
4667
def UpdateTarget(repository, options):
4768
source = os.path.join(options.v8_path, *repository)
4869
target = os.path.join(options.node_path, TARGET_SUBDIR, *repository)
@@ -63,6 +84,8 @@ def UpdateTarget(repository, options):
6384
try:
6485
for command in git_commands:
6586
subprocess.check_call(command, cwd=target)
87+
if options.with_patch:
88+
ApplyIndex(source, target)
6689
except:
6790
raise
6891
finally:
@@ -108,6 +131,8 @@ def ParseOptions(args):
108131
parser.add_argument("node_path", help="Path to Node.js checkout")
109132
parser.add_argument("--gclient", action="store_true", help="Run gclient sync")
110133
parser.add_argument("--commit", action="store_true", help="Create commit")
134+
parser.add_argument("--with-patch", action="store_true",
135+
help="Apply also staged files")
111136
options = parser.parse_args(args)
112137
assert os.path.isdir(options.v8_path)
113138
options.v8_path = os.path.abspath(options.v8_path)

0 commit comments

Comments
 (0)