0

ensure_gn_version.py: reinstall if tool is missing

It's pretty easy to wedge things currently if you do:
  rm buildtools/linux64/gn

ensure_gn_version.py then gets stuck in a crashing loop where it
tries to run the tool with --version but it always fails w/ENOENT.
So improve the logic to redownload things when they're missing.

Change-Id: Id19c1fdbf9b1ed69930f5a6e3f192e1879ce8d62
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1697947
Auto-Submit: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Dirk Pranke <dpranke@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676659}
This commit is contained in:
Mike Frysinger
2019-07-12 00:00:57 +00:00
committed by Commit Bot
parent df3602cfdf
commit ade23986de

@ -18,6 +18,7 @@ TODO(crbug.com/944667): remove this script when it is no longer needed.
from __future__ import print_function
import argparse
import errno
import io
import os
import re
@ -67,14 +68,22 @@ def main():
except subprocess.CalledProcessError as e:
print('`%s` returned %d:\n%s' % (cmd_str, e.returncode, e.output))
return 1
except OSError as e:
if e.errno != errno.ENOENT:
print('`%s` failed:\n%s' % (cmd_str, e))
return 1
# The tool doesn't exist, so redownload it.
out = ''
except Exception as e:
print('`%s` failed:\n%s' % (cmd_str, e))
return 1
current_revision = re.findall(r'\((.*)\)', out)[0]
if desired_revision.startswith(current_revision):
# We're on the right version, so we're done.
return 0
if out:
current_revision = re.findall(r'\((.*)\)', out)[0]
if desired_revision.startswith(current_revision):
# We're on the right version, so we're done.
return 0
print("`%s` returned '%s', which wasn't what we were expecting."
% (cmd_str, out.strip()))