2 """Downloads a prebuilt gn binary to a place where gn.py can find it."""
4 from __future__
import print_function
13 def download_and_unpack(url
, output_dir
, gn
):
14 """Download an archive from url and extract gn from it into output_dir."""
15 print('downloading %s ...' % url
, end
='')
17 data
= urllib2
.urlopen(url
).read()
19 zipfile
.ZipFile(io
.BytesIO(data
)).extract(gn
, path
=output_dir
)
22 def set_executable_bit(path
):
23 mode
= os
.stat(path
).st_mode
24 mode |
= (mode
& 0o444) >> 2 # Copy R bits to X.
25 os
.chmod(path
, mode
) # No-op on Windows.
30 if platform
.machine() not in ('AMD64', 'x86_64'):
32 if sys
.platform
.startswith('linux'):
34 if sys
.platform
== 'darwin':
36 if sys
.platform
== 'win32':
37 return 'windows-amd64'
41 platform
= get_platform()
43 print('no prebuilt binary for', sys
.platform
)
46 dirname
= os
.path
.join(os
.path
.dirname(__file__
), 'bin', platform
)
47 if not os
.path
.exists(dirname
):
50 url
= 'https://chrome-infra-packages.appspot.com/dl/gn/gn/%s/+/latest'
51 gn
= 'gn' + ('.exe' if sys
.platform
== 'win32' else '')
52 download_and_unpack(url
% platform
, dirname
, gn
)
53 set_executable_bit(os
.path
.join(dirname
, gn
))
56 if __name__
== '__main__':