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-12 18:20:38 +00:00
|
|
|
import os
|
2021-01-15 13:43:03 +00:00
|
|
|
import platform
|
2017-01-12 18:20:38 +00:00
|
|
|
import shutil
|
|
|
|
import stat
|
2016-07-22 10:34:25 +00:00
|
|
|
import sys
|
2020-03-31 20:23:58 +00:00
|
|
|
import tempfile
|
|
|
|
import zipfile
|
2020-01-09 17:35:22 +00:00
|
|
|
|
|
|
|
if sys.version_info[0] < 3:
|
|
|
|
from urllib2 import urlopen
|
|
|
|
else:
|
|
|
|
from urllib.request import urlopen
|
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
|
|
|
|
2020-03-31 20:23:58 +00:00
|
|
|
gnzip = os.path.join(tempfile.mkdtemp(), 'gn.zip')
|
|
|
|
with open(gnzip, 'wb') as f:
|
2021-01-15 13:43:03 +00:00
|
|
|
OS = {'darwin': 'mac', 'linux': 'linux', 'linux2': 'linux', 'win32': 'windows'}[sys.platform]
|
|
|
|
cpu = {'amd64': 'amd64', 'arm64': 'arm64', 'x86_64': 'amd64'}[platform.machine().lower()]
|
|
|
|
|
2021-01-15 13:20:33 +00:00
|
|
|
rev = 'd62642c920e6a0d1756316d225a90fd6faa9e21e'
|
2021-01-15 13:43:03 +00:00
|
|
|
url = 'https://chrome-infra-packages.appspot.com/dl/gn/gn/{}-{}/+/git_revision:{}'.format(
|
|
|
|
OS,cpu,rev)
|
2020-03-31 20:23:58 +00:00
|
|
|
f.write(urlopen(url).read())
|
2017-01-12 18:20:38 +00:00
|
|
|
|
2020-03-31 20:23:58 +00:00
|
|
|
gn = 'gn.exe' if 'win32' in sys.platform else 'gn'
|
|
|
|
with zipfile.ZipFile(gnzip, 'r') as f:
|
|
|
|
f.extract(gn, 'bin')
|
2017-01-13 18:49:18 +00:00
|
|
|
|
2020-03-31 20:23:58 +00:00
|
|
|
gn = os.path.join('bin', gn)
|
2017-01-13 18:49:18 +00:00
|
|
|
|
2020-03-31 20:23:58 +00:00
|
|
|
os.chmod(gn, 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)):
|
2020-03-31 20:23:58 +00:00
|
|
|
shutil.copy(gn, copy_path)
|