blob: b4bb14c63031002ec0c04e27ba5b810bca9d413e [file] [log] [blame]
mtklein6af0c952016-07-22 03:34:25 -07001#!/usr/bin/env python
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
Mike Kleinb621a352017-01-12 13:20:38 -05008import os
Mike Klein7de307a2021-01-15 07:43:03 -06009import platform
Mike Kleinb621a352017-01-12 13:20:38 -050010import shutil
11import stat
mtklein6af0c952016-07-22 03:34:25 -070012import sys
Mike Kleinbfc09262020-03-31 15:23:58 -050013import tempfile
14import zipfile
Hal Canary70a4fd22020-01-09 12:35:22 -050015
16if sys.version_info[0] < 3:
17 from urllib2 import urlopen
18else:
19 from urllib.request import urlopen
mtklein6af0c952016-07-22 03:34:25 -070020
Hal Canary7f660e82017-01-13 13:49:18 -050021os.chdir(os.path.join(os.path.dirname(__file__), os.pardir))
mtklein6af0c952016-07-22 03:34:25 -070022
Mike Kleinbfc09262020-03-31 15:23:58 -050023gnzip = os.path.join(tempfile.mkdtemp(), 'gn.zip')
24with open(gnzip, 'wb') as f:
Mike Klein7de307a2021-01-15 07:43:03 -060025 OS = {'darwin': 'mac', 'linux': 'linux', 'linux2': 'linux', 'win32': 'windows'}[sys.platform]
26 cpu = {'amd64': 'amd64', 'arm64': 'arm64', 'x86_64': 'amd64'}[platform.machine().lower()]
27
Mike Klein4f4c0642021-01-15 07:20:33 -060028 rev = 'd62642c920e6a0d1756316d225a90fd6faa9e21e'
Mike Klein7de307a2021-01-15 07:43:03 -060029 url = 'https://chrome-infra-packages.appspot.com/dl/gn/gn/{}-{}/+/git_revision:{}'.format(
30 OS,cpu,rev)
Mike Kleinbfc09262020-03-31 15:23:58 -050031 f.write(urlopen(url).read())
Mike Kleinb621a352017-01-12 13:20:38 -050032
Mike Kleinbfc09262020-03-31 15:23:58 -050033gn = 'gn.exe' if 'win32' in sys.platform else 'gn'
34with zipfile.ZipFile(gnzip, 'r') as f:
35 f.extract(gn, 'bin')
Hal Canary7f660e82017-01-13 13:49:18 -050036
Mike Kleinbfc09262020-03-31 15:23:58 -050037gn = os.path.join('bin', gn)
Hal Canary7f660e82017-01-13 13:49:18 -050038
Mike Kleinbfc09262020-03-31 15:23:58 -050039os.chmod(gn, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
40 stat.S_IRGRP | stat.S_IXGRP |
41 stat.S_IROTH | stat.S_IXOTH )
Hal Canary7f660e82017-01-13 13:49:18 -050042
Mike Kleincdcadf72018-02-15 10:41:10 -050043# We'll also copy to a path that depot_tools' GN wrapper will expect to find the binary.
44copy_path = 'buildtools/linux64/gn' if 'linux' in sys.platform else \
45 'buildtools/mac/gn' if 'darwin' in sys.platform else \
46 'buildtools/win/gn.exe'
47if os.path.isdir(os.path.dirname(copy_path)):
Mike Kleinbfc09262020-03-31 15:23:58 -050048 shutil.copy(gn, copy_path)