2016-07-22 10:34:25 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# Copyright 2016 Google Inc.
|
|
|
|
#
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
2017-01-13 18:49:18 +00:00
|
|
|
import hashlib
|
2017-01-12 18:20:38 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import stat
|
2016-07-22 10:34:25 +00:00
|
|
|
import sys
|
2017-01-12 18:20:38 +00:00
|
|
|
import urllib2
|
2016-07-22 10:34:25 +00:00
|
|
|
|
2017-01-13 18:49:18 +00:00
|
|
|
os.chdir(os.path.join(os.path.dirname(__file__), os.pardir))
|
2016-07-22 10:34:25 +00:00
|
|
|
|
2018-02-15 15:41:10 +00:00
|
|
|
dst = 'bin/gn.exe' if 'win32' in sys.platform else 'bin/gn'
|
2017-01-12 18:20:38 +00:00
|
|
|
|
2019-09-26 19:52:47 +00:00
|
|
|
sha1 = '3523d50538357829725d4ed74b777a572ce0ac74' if 'linux' in sys.platform else \
|
|
|
|
'd43122f6140d0711518aa909980cb009c4fbce3d' if 'darwin' in sys.platform else \
|
|
|
|
'e20768d93a6b4400de0d03bb8ceb46facdbe3883' # Windows
|
2017-01-13 18:49:18 +00:00
|
|
|
|
|
|
|
def sha1_of_file(path):
|
|
|
|
h = hashlib.sha1()
|
|
|
|
if os.path.isfile(path):
|
|
|
|
with open(path, 'rb') as f:
|
|
|
|
h.update(f.read())
|
|
|
|
return h.hexdigest()
|
|
|
|
|
2018-02-15 15:41:10 +00:00
|
|
|
if sha1_of_file(dst) != sha1:
|
|
|
|
with open(dst, 'wb') as f:
|
2017-01-12 18:20:38 +00:00
|
|
|
f.write(urllib2.urlopen('https://chromium-gn.storage-download.googleapis.com/' + sha1).read())
|
|
|
|
|
2018-02-15 15:41:10 +00:00
|
|
|
os.chmod(dst, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
|
|
|
|
stat.S_IRGRP | stat.S_IXGRP |
|
|
|
|
stat.S_IROTH | stat.S_IXOTH )
|
2017-01-13 18:49:18 +00:00
|
|
|
|
2018-02-15 15:41:10 +00:00
|
|
|
# We'll also copy to a path that depot_tools' GN wrapper will expect to find the binary.
|
|
|
|
copy_path = 'buildtools/linux64/gn' if 'linux' in sys.platform else \
|
|
|
|
'buildtools/mac/gn' if 'darwin' in sys.platform else \
|
|
|
|
'buildtools/win/gn.exe'
|
|
|
|
if os.path.isdir(os.path.dirname(copy_path)):
|
|
|
|
shutil.copy(dst, copy_path)
|