[tools] Make node update script patch application more robust

Bug: v8:6154
NOTRY=true

Change-Id: I877dfdbab01df6356e83ee81ca75d54a951b9cab
Reviewed-on: https://chromium-review.googlesource.com/468886
Reviewed-by: Franziska Hinkelmann <franzih@chromium.org>
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44421}
This commit is contained in:
Michael Achenbach 2017-04-05 12:02:58 +02:00 committed by Commit Bot
parent 2ac17e34cd
commit f0c7bbec61

View File

@ -43,26 +43,18 @@ def UninitGit(path):
print ">> Cleaning up %s" % path print ">> Cleaning up %s" % path
shutil.rmtree(target) shutil.rmtree(target)
def ApplyIndex(source, target): def CommitPatch(options):
if not subprocess.check_output(["git", "diff", "--cached"], cwd=source): """Makes a dummy commit for the changes in the index.
print ">> Ignoring empty patch"
return
print ">> Applying patch" On trybots, bot_updated applies the patch to the index. We commit it to make
diff_proc = subprocess.Popen( the fake git clone fetch it into node.js. We can leave the commit, as
["git", "diff", "--cached"], bot_update will ensure a clean state on each run.
cwd=source, """
stdout=subprocess.PIPE, print ">> Comitting patch"
subprocess.check_call(
["git", "commit", "--allow-empty", "-m", "placeholder-commit"],
cwd=options.v8_path,
) )
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): def UpdateTarget(repository, options):
source = os.path.join(options.v8_path, *repository) source = os.path.join(options.v8_path, *repository)
@ -84,8 +76,6 @@ def UpdateTarget(repository, options):
try: try:
for command in git_commands: for command in git_commands:
subprocess.check_call(command, cwd=target) subprocess.check_call(command, cwd=target)
if options.with_patch:
ApplyIndex(source, target)
except: except:
raise raise
finally: finally:
@ -144,6 +134,9 @@ def Main(args):
options = ParseOptions(args) options = ParseOptions(args)
if options.gclient: if options.gclient:
RunGclient(options.v8_path) RunGclient(options.v8_path)
# Commit patch on trybots to main V8 repository.
if options.with_patch:
CommitPatch(options)
# Update main V8 repository. # Update main V8 repository.
UpdateTarget([""], options) UpdateTarget([""], options)
# Patch .gitignore before updating sub-repositories. # Patch .gitignore before updating sub-repositories.