OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 # vim: set ts=2 sw=2 et sts=2 ai: |
| 6 |
| 7 """Minimal tool to download binutils from Google storage. |
| 8 |
| 9 TODO(mithro): Replace with generic download_and_extract tool. |
| 10 """ |
| 11 |
| 12 import os |
| 13 import platform |
| 14 import re |
| 15 import shutil |
| 16 import subprocess |
| 17 import sys |
| 18 |
| 19 |
| 20 BINUTILS_DIR = os.path.abspath(os.path.dirname(__file__)) |
| 21 BINUTILS_FILE = 'binutils.tar.bz2' |
| 22 BINUTILS_TOOLS = ['bin/ld.gold', 'bin/objcopy', 'bin/objdump'] |
| 23 BINUTILS_OUT = 'Release' |
| 24 |
| 25 DETECT_HOST_ARCH = os.path.abspath(os.path.join( |
| 26 BINUTILS_DIR, '../../build/linux/detect_host_arch.py')) |
| 27 |
| 28 |
| 29 def ReadFile(filename): |
| 30 with file(filename, 'r') as f: |
| 31 return f.read().strip() |
| 32 |
| 33 |
| 34 def WriteFile(filename, content): |
| 35 assert not os.path.exists(filename) |
| 36 with file(filename, 'w') as f: |
| 37 f.write(content) |
| 38 f.write('\n') |
| 39 |
| 40 |
| 41 def GetArch(): |
| 42 gyp_host_arch = re.search( |
| 43 'host_arch=([^ ]*)', os.environ.get('GYP_DEFINES', '')) |
| 44 if gyp_host_arch: |
| 45 return gyp_host_arch.group(1) |
| 46 |
| 47 return subprocess.check_output(['python', DETECT_HOST_ARCH]).strip() |
| 48 |
| 49 |
| 50 def main(args): |
| 51 if not sys.platform.startswith('linux'): |
| 52 return 0 |
| 53 |
| 54 archdir = os.path.join(BINUTILS_DIR, 'Linux_' + GetArch()) |
| 55 tarball = os.path.join(archdir, BINUTILS_FILE) |
| 56 outdir = os.path.join(archdir, BINUTILS_OUT) |
| 57 |
| 58 sha1file = tarball + '.sha1' |
| 59 if not os.path.exists(sha1file): |
| 60 print "WARNING: No binutils found for your architecture (%s)!" % GetArch() |
| 61 return 0 |
| 62 |
| 63 checksum = ReadFile(sha1file) |
| 64 |
| 65 stampfile = tarball + '.stamp' |
| 66 if os.path.exists(stampfile): |
| 67 if checksum == ReadFile(stampfile): |
| 68 return 0 |
| 69 else: |
| 70 os.unlink(stampfile) |
| 71 |
| 72 print "Downloading", tarball |
| 73 subprocess.check_call([ |
| 74 'download_from_google_storage', |
| 75 '--no_resume', |
| 76 '--no_auth', |
| 77 '--bucket', 'chromium-binutils', |
| 78 '-s', sha1file]) |
| 79 assert os.path.exists(tarball) |
| 80 |
| 81 if os.path.exists(outdir): |
| 82 shutil.rmtree(outdir) |
| 83 assert not os.path.exists(outdir) |
| 84 os.makedirs(outdir) |
| 85 assert os.path.exists(outdir) |
| 86 |
| 87 print "Extracting", tarball |
| 88 subprocess.check_call(['tar', 'axf', tarball], cwd=outdir) |
| 89 |
| 90 for tool in BINUTILS_TOOLS: |
| 91 assert os.path.exists(os.path.join(outdir, tool)) |
| 92 |
| 93 WriteFile(stampfile, checksum) |
| 94 return 0 |
| 95 |
| 96 |
| 97 if __name__ == '__main__': |
| 98 sys.exit(main(sys.argv)) |
OLD | NEW |