Chromium Code Reviews| Index: build/linux/sysroot_scripts/install-sysroot.py |
| diff --git a/build/linux/sysroot_scripts/install-sysroot.py b/build/linux/sysroot_scripts/install-sysroot.py |
| index dc492c6a56efb84de9ccef7f9acfb0c20025a13d..e342364c1cd22f991e6efebb9cc58c0dfbad93cd 100755 |
| --- a/build/linux/sysroot_scripts/install-sysroot.py |
| +++ b/build/linux/sysroot_scripts/install-sysroot.py |
| @@ -24,6 +24,7 @@ import re |
| import shutil |
| import subprocess |
| import sys |
| +import time |
| SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| sys.path.append(os.path.dirname(os.path.dirname(SCRIPT_DIR))) |
| @@ -135,7 +136,14 @@ def InstallDefaultSysroots(): |
| InstallSysroot(target_arch) |
| -def main(): |
| +def main(args): |
| + parser = optparse.OptionParser('usage: %prog [OPTIONS]', description=__doc__) |
| + parser.add_option('--running-as-hook', action='store_true', |
| + default=False, help='Used when running from gclient hooks.' |
| + ' Installs default sysroot images.') |
| + parser.add_option('--arch', type='choice', choices=valid_archs, |
| + help='Sysroot architecture: %s' % ', '.join(valid_archs)) |
| + options, _ = parser.parse_args(args) |
| if options.running_as_hook and not sys.platform.startswith('linux'): |
| return 0 |
| @@ -143,13 +151,35 @@ def main(): |
| InstallDefaultSysroots() |
| else: |
| if not options.arch: |
| - print 'You much specify either --arch or --running-as-hook' |
| - return 1 |
| + raise Error('You much specify either --arch or --running-as-hook') |
| InstallSysroot(options.arch) |
| return 0 |
| +def DownloadURL(url, filename): |
| + print 'Downloading %s' % url |
| + sys.stdout.flush() |
| + sys.stderr.flush() |
| + |
| + # Re-try download in order to mitigate network falkiness. |
|
Lei Zhang
2016/02/17 20:49:51
typo
|
| + num_retries = 3 |
| + retry_wait = 5 # Doubled at each retry. |
| + cmd = ['curl', '--fail', '-L', url, '-o', filename] |
| + while True: |
| + rtn = subprocess.call(cmd) |
| + if rtn == 0: |
| + return |
| + elif num_retries: |
|
Lei Zhang
2016/02/17 20:49:51
no elif / else after a return.
|
| + # Curl failed. Retry |
| + print 'Retrying in %d s ...' % retry_wait |
| + time.sleep(retry_wait) |
| + num_retries -= 1 |
| + retry_wait *= 2 |
| + else: |
| + raise Error('download command failed (%s): %s' % (rtn, cmd)) |
|
Lei Zhang
2016/02/17 20:49:51
%s seems to work, but shouldn't it be %d since |rt
|
| + |
| + |
| def InstallSysroot(target_arch): |
| # The sysroot directory should match the one specified in build/common.gypi. |
| # TODO(thestig) Consider putting this else where to avoid having to recreate |
| @@ -193,10 +223,7 @@ def InstallSysroot(target_arch): |
| shutil.rmtree(sysroot) |
| os.mkdir(sysroot) |
| tarball = os.path.join(sysroot, tarball_filename) |
| - print 'Downloading %s' % url |
| - sys.stdout.flush() |
| - sys.stderr.flush() |
| - subprocess.check_call(['curl', '--fail', '-L', url, '-o', tarball]) |
| + DownloadURL(url, tarball) |
| sha1sum = GetSha1(tarball) |
| if sha1sum != tarball_sha1sum: |
| raise Error('Tarball sha1sum is wrong.' |
| @@ -209,11 +236,8 @@ def InstallSysroot(target_arch): |
| if __name__ == '__main__': |
| - parser = optparse.OptionParser('usage: %prog [OPTIONS]', description=__doc__) |
| - parser.add_option('--running-as-hook', action='store_true', |
| - default=False, help='Used when running from gclient hooks.' |
| - ' Installs default sysroot images.') |
| - parser.add_option('--arch', type='choice', choices=valid_archs, |
| - help='Sysroot architecture: %s' % ', '.join(valid_archs)) |
| - options, _ = parser.parse_args() |
| - sys.exit(main()) |
| + try: |
| + sys.exit(main(sys.argv[1:])) |
| + except Error as e: |
| + sys.stderr.write(str(e) + '\n') |
| + sys.exit(1) |