Commit b82c5e76 authored by Michael Achenbach's avatar Michael Achenbach Committed by Commit Bot

[tools] Make node udpate script able to apply patches

Bug: v8:6154
NOTRY=true

Change-Id: I7f18efaf2f86b9dfa43f249d817777f19ee29c9b
Reviewed-on: https://chromium-review.googlesource.com/467427Reviewed-by: 's avatarFranziska Hinkelmann <franzih@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44399}
parent a0655790
......@@ -84,8 +84,13 @@ class TestUpdateNode(unittest.TestCase):
shutil.copytree(src=os.path.join(TEST_DATA, 'node'), dst=node_cwd)
gitify(os.path.join(node_cwd))
# Add a patch.
with open(os.path.join(v8_cwd, 'v8_foo'), 'w') as f:
f.write('zonk')
subprocess.check_call(['git', 'add', 'v8_foo'], cwd=v8_cwd)
# Run update script.
update_node.Main([v8_cwd, node_cwd, "--commit"])
update_node.Main([v8_cwd, node_cwd, "--commit", "--with-patch"])
# Check expectations.
with open(os.path.join(node_cwd, 'deps', 'v8', '.gitignore')) as f:
......@@ -97,9 +102,18 @@ class TestUpdateNode(unittest.TestCase):
for f in REMOVED_FILES:
removed_file = os.path.join(node_cwd, 'deps', 'v8', *f.split('/'))
self.assertFalse(os.path.exists(removed_file))
gitlog = subprocess.check_output(['git', 'diff', 'master', '--summary'],
cwd=node_cwd)
gitlog = subprocess.check_output(
['git', 'diff', 'master', '--summary'],
cwd=node_cwd,
)
self.assertEquals(EXPECTED_GIT_DIFF.strip(), gitlog.strip())
# Check patch.
gitlog = subprocess.check_output(
['git', 'diff', 'master', '--cached', '--', 'deps/v8/v8_foo'],
cwd=node_cwd,
)
self.assertIn('+zonk', gitlog.strip())
if __name__ == "__main__":
unittest.main()
......@@ -43,6 +43,27 @@ def UninitGit(path):
print ">> Cleaning up %s" % path
shutil.rmtree(target)
def ApplyIndex(source, target):
if not subprocess.check_output(["git", "diff", "--cached"], cwd=source):
print ">> Ignoring empty patch"
return
print ">> Applying patch"
diff_proc = subprocess.Popen(
["git", "diff", "--cached"],
cwd=source,
stdout=subprocess.PIPE,
)
apply_proc = subprocess.Popen(
["git", "apply", "--index"],
cwd=target,
stdin=diff_proc.stdout,
)
diff_proc.stdout.close()
apply_proc.communicate()
if apply_proc.returncode != 0:
raise Exception("Error applying patch")
def UpdateTarget(repository, options):
source = os.path.join(options.v8_path, *repository)
target = os.path.join(options.node_path, TARGET_SUBDIR, *repository)
......@@ -63,6 +84,8 @@ def UpdateTarget(repository, options):
try:
for command in git_commands:
subprocess.check_call(command, cwd=target)
if options.with_patch:
ApplyIndex(source, target)
except:
raise
finally:
......@@ -108,6 +131,8 @@ def ParseOptions(args):
parser.add_argument("node_path", help="Path to Node.js checkout")
parser.add_argument("--gclient", action="store_true", help="Run gclient sync")
parser.add_argument("--commit", action="store_true", help="Create commit")
parser.add_argument("--with-patch", action="store_true",
help="Apply also staged files")
options = parser.parse_args(args)
assert os.path.isdir(options.v8_path)
options.v8_path = os.path.abspath(options.v8_path)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment