mtklein | 6af0c95 | 2016-07-22 03:34:25 -0700 | [diff] [blame] | 1 | #!/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 Klein | b621a35 | 2017-01-12 13:20:38 -0500 | [diff] [blame] | 8 | import os |
| 9 | import shutil |
| 10 | import stat |
mtklein | 6af0c95 | 2016-07-22 03:34:25 -0700 | [diff] [blame] | 11 | import sys |
Mike Klein | bfc0926 | 2020-03-31 15:23:58 -0500 | [diff] [blame] | 12 | import tempfile |
| 13 | import zipfile |
Hal Canary | 70a4fd2 | 2020-01-09 12:35:22 -0500 | [diff] [blame] | 14 | |
| 15 | if sys.version_info[0] < 3: |
| 16 | from urllib2 import urlopen |
| 17 | else: |
| 18 | from urllib.request import urlopen |
mtklein | 6af0c95 | 2016-07-22 03:34:25 -0700 | [diff] [blame] | 19 | |
Hal Canary | 7f660e8 | 2017-01-13 13:49:18 -0500 | [diff] [blame] | 20 | os.chdir(os.path.join(os.path.dirname(__file__), os.pardir)) |
mtklein | 6af0c95 | 2016-07-22 03:34:25 -0700 | [diff] [blame] | 21 | |
Mike Klein | bfc0926 | 2020-03-31 15:23:58 -0500 | [diff] [blame] | 22 | gnzip = os.path.join(tempfile.mkdtemp(), 'gn.zip') |
| 23 | with open(gnzip, 'wb') as f: |
| 24 | pkg = 'linux-amd64' if 'linux' in sys.platform else \ |
| 25 | 'mac-amd64' if 'darwin' in sys.platform else \ |
| 26 | 'windows-amd64' |
| 27 | rev = '82d673acb802cee21534c796a59f8cdf26500f53' |
| 28 | url = 'https://chrome-infra-packages.appspot.com/dl/gn/gn/{}/+/git_revision:{}'.format(pkg,rev) |
| 29 | f.write(urlopen(url).read()) |
Mike Klein | b621a35 | 2017-01-12 13:20:38 -0500 | [diff] [blame] | 30 | |
Mike Klein | bfc0926 | 2020-03-31 15:23:58 -0500 | [diff] [blame] | 31 | gn = 'gn.exe' if 'win32' in sys.platform else 'gn' |
| 32 | with zipfile.ZipFile(gnzip, 'r') as f: |
| 33 | f.extract(gn, 'bin') |
Hal Canary | 7f660e8 | 2017-01-13 13:49:18 -0500 | [diff] [blame] | 34 | |
Mike Klein | bfc0926 | 2020-03-31 15:23:58 -0500 | [diff] [blame] | 35 | gn = os.path.join('bin', gn) |
Hal Canary | 7f660e8 | 2017-01-13 13:49:18 -0500 | [diff] [blame] | 36 | |
Mike Klein | bfc0926 | 2020-03-31 15:23:58 -0500 | [diff] [blame] | 37 | os.chmod(gn, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | |
| 38 | stat.S_IRGRP | stat.S_IXGRP | |
| 39 | stat.S_IROTH | stat.S_IXOTH ) |
Hal Canary | 7f660e8 | 2017-01-13 13:49:18 -0500 | [diff] [blame] | 40 | |
Mike Klein | cdcadf7 | 2018-02-15 10:41:10 -0500 | [diff] [blame] | 41 | # We'll also copy to a path that depot_tools' GN wrapper will expect to find the binary. |
| 42 | copy_path = 'buildtools/linux64/gn' if 'linux' in sys.platform else \ |
| 43 | 'buildtools/mac/gn' if 'darwin' in sys.platform else \ |
| 44 | 'buildtools/win/gn.exe' |
| 45 | if os.path.isdir(os.path.dirname(copy_path)): |
Mike Klein | bfc0926 | 2020-03-31 15:23:58 -0500 | [diff] [blame] | 46 | shutil.copy(gn, copy_path) |