blob: d0c791d1c398b7c8a026505f9a01364de0bd6f56 [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
9import shutil
10import stat
mtklein6af0c952016-07-22 03:34:25 -070011import sys
Mike Kleinbfc09262020-03-31 15:23:58 -050012import tempfile
13import zipfile
Hal Canary70a4fd22020-01-09 12:35:22 -050014
15if sys.version_info[0] < 3:
16 from urllib2 import urlopen
17else:
18 from urllib.request import urlopen
mtklein6af0c952016-07-22 03:34:25 -070019
Hal Canary7f660e82017-01-13 13:49:18 -050020os.chdir(os.path.join(os.path.dirname(__file__), os.pardir))
mtklein6af0c952016-07-22 03:34:25 -070021
Mike Kleinbfc09262020-03-31 15:23:58 -050022gnzip = os.path.join(tempfile.mkdtemp(), 'gn.zip')
23with 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'
John Stiles3890d3d2020-06-18 14:41:25 -040027 rev = '9e993e3da82a9f4bc5c50c190afbcffd61e3d9e0'
Mike Kleinbfc09262020-03-31 15:23:58 -050028 url = 'https://chrome-infra-packages.appspot.com/dl/gn/gn/{}/+/git_revision:{}'.format(pkg,rev)
29 f.write(urlopen(url).read())
Mike Kleinb621a352017-01-12 13:20:38 -050030
Mike Kleinbfc09262020-03-31 15:23:58 -050031gn = 'gn.exe' if 'win32' in sys.platform else 'gn'
32with zipfile.ZipFile(gnzip, 'r') as f:
33 f.extract(gn, 'bin')
Hal Canary7f660e82017-01-13 13:49:18 -050034
Mike Kleinbfc09262020-03-31 15:23:58 -050035gn = os.path.join('bin', gn)
Hal Canary7f660e82017-01-13 13:49:18 -050036
Mike Kleinbfc09262020-03-31 15:23:58 -050037os.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 Canary7f660e82017-01-13 13:49:18 -050040
Mike Kleincdcadf72018-02-15 10:41:10 -050041# We'll also copy to a path that depot_tools' GN wrapper will expect to find the binary.
42copy_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'
45if os.path.isdir(os.path.dirname(copy_path)):
Mike Kleinbfc09262020-03-31 15:23:58 -050046 shutil.copy(gn, copy_path)