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:
7 """Minimal tool to download binutils from Google storage.
9 TODO(mithro): Replace with generic download_and_extract tool.
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'
25 DETECT_HOST_ARCH
= os
.path
.abspath(os
.path
.join(
26 BINUTILS_DIR
, '../../build/detect_host_arch.py'))
29 def ReadFile(filename
):
30 with
file(filename
, 'r') as f
:
31 return f
.read().strip()
34 def WriteFile(filename
, content
):
35 assert not os
.path
.exists(filename
)
36 with
file(filename
, 'w') as f
:
42 gyp_host_arch
= re
.search(
43 'host_arch=(\S*)', os
.environ
.get('GYP_DEFINES', ''))
45 arch
= gyp_host_arch
.group(1)
46 # This matches detect_host_arch.py.
51 return subprocess
.check_output(['python', DETECT_HOST_ARCH
]).strip()
54 def FetchAndExtract(arch
):
55 archdir
= os
.path
.join(BINUTILS_DIR
, 'Linux_' + arch
)
56 tarball
= os
.path
.join(archdir
, BINUTILS_FILE
)
57 outdir
= os
.path
.join(archdir
, BINUTILS_OUT
)
59 sha1file
= tarball
+ '.sha1'
60 if not os
.path
.exists(sha1file
):
61 print "WARNING: No binutils found for your architecture (%s)!" % arch
64 checksum
= ReadFile(sha1file
)
66 stampfile
= tarball
+ '.stamp'
67 if os
.path
.exists(stampfile
):
68 if (os
.path
.exists(tarball
) and
69 os
.path
.exists(outdir
) and
70 checksum
== ReadFile(stampfile
)):
75 print "Downloading", tarball
76 subprocess
.check_call([
77 'download_from_google_storage',
80 '--bucket', 'chromium-binutils',
82 assert os
.path
.exists(tarball
)
84 if os
.path
.exists(outdir
):
86 assert not os
.path
.exists(outdir
)
88 assert os
.path
.exists(outdir
)
90 print "Extracting", tarball
91 subprocess
.check_call(['tar', 'axf', tarball
], cwd
=outdir
)
93 for tool
in BINUTILS_TOOLS
:
94 assert os
.path
.exists(os
.path
.join(outdir
, tool
))
96 WriteFile(stampfile
, checksum
)
101 if not sys
.platform
.startswith('linux'):
106 return FetchAndExtract(arch
)
108 ret
= FetchAndExtract(arch
)
111 # Fetch the x64 toolchain as well for official bots with 64-bit kernels.
112 return FetchAndExtract('x64')
113 print "Host architecture %s is not supported." % arch
117 if __name__
== '__main__':
118 sys
.exit(main(sys
.argv
))