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