• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
8import os
9import platform
10import shutil
11import stat
12import sys
13import tempfile
14import zipfile
15
16from urllib.request import urlopen
17
18os.chdir(os.path.join(os.path.dirname(__file__), os.pardir))
19
20gnzip = os.path.join(tempfile.mkdtemp(), 'gn.zip')
21with 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
30gn_filename = 'gn.exe' if 'win32' in sys.platform else 'gn'
31with zipfile.ZipFile(gnzip, 'r') as f:
32  f.extract(gn_filename, 'bin')
33
34gn_path = os.path.join('bin', gn_filename)
35
36os.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.
42depot_tools_gn_dir = os.path.join('third_party', 'gn')
43os.makedirs(depot_tools_gn_dir, exist_ok=True)
44shutil.copy(gn_path, os.path.join(depot_tools_gn_dir, gn_filename))
45