| #!/usr/bin/env python3 |
| |
| # Copyright 2016 Google Inc. |
| # |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import os |
| import platform |
| import shutil |
| import stat |
| import sys |
| import tempfile |
| import zipfile |
| |
| from urllib.request import urlopen |
| |
| os.chdir(os.path.join(os.path.dirname(__file__), os.pardir)) |
| |
| gnzip = os.path.join(tempfile.mkdtemp(), 'gn.zip') |
| with open(gnzip, 'wb') as f: |
| OS = {'darwin': 'mac', 'linux': 'linux', 'linux2': 'linux', 'win32': 'windows'}[sys.platform] |
| cpu = {'aarch64': 'arm64', 'amd64': 'amd64', 'arm64': 'arm64', 'x86_64': 'amd64'}[platform.machine().lower()] |
| |
| rev = 'b2afae122eeb6ce09c52d63f67dc53fc517dbdc8' |
| url = 'https://chrome-infra-packages.appspot.com/dl/gn/gn/{}-{}/+/git_revision:{}'.format( |
| OS,cpu,rev) |
| f.write(urlopen(url).read()) |
| |
| gn_filename = 'gn.exe' if 'win32' in sys.platform else 'gn' |
| with zipfile.ZipFile(gnzip, 'r') as f: |
| f.extract(gn_filename, 'bin') |
| |
| gn_path = os.path.join('bin', gn_filename) |
| |
| os.chmod(gn_path, |
| stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | |
| stat.S_IRGRP | stat.S_IXGRP | |
| stat.S_IROTH | stat.S_IXOTH ) |
| |
| # We'll also copy to a path that depot_tools' GN wrapper will expect to find the binary. |
| depot_tools_gn_dir = os.path.join('third_party', 'gn') |
| os.makedirs(depot_tools_gn_dir, exist_ok=True) |
| shutil.copy(gn_path, os.path.join(depot_tools_gn_dir, gn_filename)) |