xref: /aosp_15_r20/external/skia/bin/fetch-gn (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 = 'gn.exe' if 'win32' in sys.platform else 'gn'
31with zipfile.ZipFile(gnzip, 'r') as f:
32  f.extract(gn, 'bin')
33
34gn = os.path.join('bin', gn)
35
36os.chmod(gn, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
37             stat.S_IRGRP                | stat.S_IXGRP |
38             stat.S_IROTH                | stat.S_IXOTH )
39
40# We'll also copy to a path that depot_tools' GN wrapper will expect to find the binary.
41copy_path = 'buildtools/linux64/gn' if 'linux'  in sys.platform else \
42            'buildtools/mac/gn'     if 'darwin' in sys.platform else \
43            'buildtools/win/gn.exe'
44if os.path.isdir(os.path.dirname(copy_path)):
45  shutil.copy(gn, copy_path)
46