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_OUT = os.path.join(BINUTILS_DIR, 'Release') | |
23 BINUTILS_TOOLS = ['bin/ld.gold', 'bin/objcopy', 'bin/objdump'] | |
24 | |
25 | |
26 def ReadFile(filename): | |
27 with file(filename, 'r') as f: | |
28 return f.read().strip() | |
29 | |
30 | |
31 def WriteFile(filename, content): | |
32 assert not os.path.exists(filename) | |
33 with file(filename, 'w') as f: | |
34 f.write(content) | |
35 f.write('\n') | |
36 | |
37 | |
38 def main(args): | |
39 if not sys.platform.startswith('linux'): | |
40 return 0 | |
41 | |
42 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
| |
43 arch_dir = 'Linux_x64' | |
44 elif re.search('(i[3456]86)|(i86pc)', platform.processor(), re.I): | |
45 arch_dir = 'Linux_ia32' | |
46 else: | |
47 print "WARNING: No compatible binutils found for your system!" | |
48 return 0 | |
49 | |
50 tarball = os.path.join(BINUTILS_DIR, arch_dir, BINUTILS_FILE) | |
51 sha1file = tarball + '.sha1' | |
52 stampfile = tarball + '.stamp' | |
53 assert os.path.exists(sha1file) | |
54 | |
55 checksum = ReadFile(sha1file) | |
56 | |
57 if os.path.exists(stampfile): | |
58 if checksum == ReadFile(stampfile): | |
59 return 0 | |
60 else: | |
61 os.unlink(stampfile) | |
62 | |
63 print "Downloading", tarball | |
64 subprocess.check_call([ | |
65 'download_from_google_storage', | |
66 '--no_resume', | |
67 '--no_auth', | |
68 '--bucket', 'chromium-binutils', | |
69 '-s', sha1file]) | |
70 assert os.path.exists(tarball) | |
71 | |
72 if os.path.exists(BINUTILS_OUT): | |
73 shutil.rmtree(BINUTILS_OUT) | |
74 assert not os.path.exists(BINUTILS_OUT) | |
75 os.makedirs(BINUTILS_OUT) | |
76 assert os.path.exists(BINUTILS_OUT) | |
77 | |
78 print "Extracting", tarball | |
79 subprocess.check_call(['tar', 'axf', tarball], cwd=BINUTILS_OUT) | |
80 | |
81 for tool in BINUTILS_TOOLS: | |
82 assert os.path.exists(os.path.join(BINUTILS_OUT, tool)) | |
83 | |
84 WriteFile(stampfile, checksum) | |
85 return 0 | |
86 | |
87 | |
88 if __name__ == '__main__': | |
89 sys.exit(main(sys.argv)) | |
OLD | NEW |