| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
# Copyright 2016 Google Inc. |
| 4 |
# |
| 5 |
# Use of this source code is governed by a BSD-style license that can be |
| 6 |
# found in the LICENSE file. |
| 7 |
|
| 8 |
import os |
| 9 |
import platform |
| 10 |
import shutil |
| 11 |
import stat |
| 12 |
import sys |
| 13 |
import tempfile |
| 14 |
import zipfile |
| 15 |
|
| 16 |
from urllib.request import urlopen |
| 17 |
|
| 18 |
os.chdir(os.path.join(os.path.dirname(__file__), os.pardir)) |
| 19 |
|
| 20 |
gnzip = os.path.join(tempfile.mkdtemp(), 'gn.zip') |
| 21 |
with open(gnzip, 'wb') as f: |
| 22 |
OS = {'darwin': 'mac', 'linux': 'linux', 'linux2': 'linux', 'win32': 'windows'}[sys.platform] |
| 23 |
cpu = {'aarch64': 'arm64', 'amd64': 'amd64', 'arm64': 'arm64', 'x86_64': 'amd64'}[platform.machine().lower()] |
| 24 |
|
| 25 |
rev = 'b2afae122eeb6ce09c52d63f67dc53fc517dbdc8' |
| 26 |
url = 'https://chrome-infra-packages.appspot.com/dl/gn/gn/{}-{}/+/git_revision:{}'.format( |
| 27 |
OS,cpu,rev) |
| 28 |
f.write(urlopen(url).read()) |
| 29 |
|
| 30 |
gn_filename = 'gn.exe' if 'win32' in sys.platform else 'gn' |
| 31 |
with zipfile.ZipFile(gnzip, 'r') as f: |
| 32 |
f.extract(gn_filename, 'bin') |
| 33 |
|
| 34 |
gn_path = os.path.join('bin', gn_filename) |
| 35 |
|
| 36 |
os.chmod(gn_path, |
| 37 |
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | |
| 38 |
stat.S_IRGRP | stat.S_IXGRP | |
| 39 |
stat.S_IROTH | stat.S_IXOTH ) |
| 40 |
|
| 41 |
# We'll also copy to a path that depot_tools' GN wrapper will expect to find the binary. |
| 42 |
depot_tools_gn_dir = os.path.join('third_party', 'gn') |
| 43 |
os.makedirs(depot_tools_gn_dir, exist_ok=True) |
| 44 |
shutil.copy(gn_path, os.path.join(depot_tools_gn_dir, gn_filename)) |