Chromium Code Reviews| Index: third_party/binutils/download.py |
| diff --git a/third_party/binutils/download.py b/third_party/binutils/download.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..be819c21c75a1cc536b79c70e5fd62a6166af597 |
| --- /dev/null |
| +++ b/third_party/binutils/download.py |
| @@ -0,0 +1,89 @@ |
| +#!/usr/bin/env python |
| +# Copyright 2014 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| +# vim: set ts=2 sw=2 et sts=2 ai: |
| + |
| +"""Minimal tool to download binutils from Google storage. |
| + |
| +TODO(mithro): Replace with generic download_and_extract tool. |
| +""" |
| + |
| +import os |
| +import platform |
| +import re |
| +import shutil |
| +import subprocess |
| +import sys |
| + |
| + |
| +BINUTILS_DIR = os.path.abspath(os.path.dirname(__file__)) |
| +BINUTILS_FILE = 'binutils.tar.bz2' |
| +BINUTILS_OUT = os.path.join(BINUTILS_DIR, 'Release') |
| +BINUTILS_TOOLS = ['bin/ld.gold', 'bin/objcopy', 'bin/objdump'] |
| + |
| + |
| +def ReadFile(filename): |
| + with file(filename, 'r') as f: |
| + return f.read().strip() |
| + |
| + |
| +def WriteFile(filename, content): |
| + assert not os.path.exists(filename) |
| + with file(filename, 'w') as f: |
| + f.write(content) |
| + f.write('\n') |
| + |
| + |
| +def main(args): |
| + if not sys.platform.startswith('linux'): |
| + return 0 |
| + |
| + if re.search('64', platform.processor(), re.I): |
|
Lei Zhang
2014/04/02 21:30:13
This may not work right for 32-bit userland + 64-b
|
| + arch_dir = 'Linux_x64' |
| + elif re.search('(i[3456]86)|(i86pc)', platform.processor(), re.I): |
| + arch_dir = 'Linux_ia32' |
| + else: |
| + print "WARNING: No compatible binutils found for your system!" |
| + return 0 |
| + |
| + tarball = os.path.join(BINUTILS_DIR, arch_dir, BINUTILS_FILE) |
| + sha1file = tarball + '.sha1' |
| + stampfile = tarball + '.stamp' |
| + assert os.path.exists(sha1file) |
| + |
| + checksum = ReadFile(sha1file) |
| + |
| + if os.path.exists(stampfile): |
| + if checksum == ReadFile(stampfile): |
| + return 0 |
| + else: |
| + os.unlink(stampfile) |
| + |
| + print "Downloading", tarball |
| + subprocess.check_call([ |
| + 'download_from_google_storage', |
| + '--no_resume', |
| + '--no_auth', |
| + '--bucket', 'chromium-binutils', |
| + '-s', sha1file]) |
| + assert os.path.exists(tarball) |
| + |
| + if os.path.exists(BINUTILS_OUT): |
| + shutil.rmtree(BINUTILS_OUT) |
| + assert not os.path.exists(BINUTILS_OUT) |
| + os.makedirs(BINUTILS_OUT) |
| + assert os.path.exists(BINUTILS_OUT) |
| + |
| + print "Extracting", tarball |
| + subprocess.check_call(['tar', 'axf', tarball], cwd=BINUTILS_OUT) |
| + |
| + for tool in BINUTILS_TOOLS: |
| + assert os.path.exists(os.path.join(BINUTILS_OUT, tool)) |
| + |
| + WriteFile(stampfile, checksum) |
| + return 0 |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main(sys.argv)) |