blob: e7cc92345f96ea57f3ebc49f74b9c1e2f8ab7d9f [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
Hal Canary7f660e82017-01-13 13:49:18 -05008import hashlib
Mike Kleinb621a352017-01-12 13:20:38 -05009import os
10import shutil
11import stat
mtklein6af0c952016-07-22 03:34:25 -070012import sys
Hal Canary70a4fd22020-01-09 12:35:22 -050013
14if sys.version_info[0] < 3:
15 from urllib2 import urlopen
16else:
17 from urllib.request import urlopen
mtklein6af0c952016-07-22 03:34:25 -070018
Hal Canary7f660e82017-01-13 13:49:18 -050019os.chdir(os.path.join(os.path.dirname(__file__), os.pardir))
mtklein6af0c952016-07-22 03:34:25 -070020
Mike Kleincdcadf72018-02-15 10:41:10 -050021dst = 'bin/gn.exe' if 'win32' in sys.platform else 'bin/gn'
Mike Kleinb621a352017-01-12 13:20:38 -050022
Mike Klein3375a882019-09-26 14:52:47 -050023sha1 = '3523d50538357829725d4ed74b777a572ce0ac74' if 'linux' in sys.platform else \
24 'd43122f6140d0711518aa909980cb009c4fbce3d' if 'darwin' in sys.platform else \
25 'e20768d93a6b4400de0d03bb8ceb46facdbe3883' # Windows
Hal Canary7f660e82017-01-13 13:49:18 -050026
27def sha1_of_file(path):
28 h = hashlib.sha1()
29 if os.path.isfile(path):
30 with open(path, 'rb') as f:
31 h.update(f.read())
32 return h.hexdigest()
33
Mike Kleincdcadf72018-02-15 10:41:10 -050034if sha1_of_file(dst) != sha1:
35 with open(dst, 'wb') as f:
Hal Canary70a4fd22020-01-09 12:35:22 -050036 f.write(urlopen('https://chromium-gn.storage-download.googleapis.com/' + sha1).read())
Mike Kleinb621a352017-01-12 13:20:38 -050037
Mike Kleincdcadf72018-02-15 10:41:10 -050038 os.chmod(dst, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
39 stat.S_IRGRP | stat.S_IXGRP |
40 stat.S_IROTH | stat.S_IXOTH )
Hal Canary7f660e82017-01-13 13:49:18 -050041
Mike Kleincdcadf72018-02-15 10:41:10 -050042# We'll also copy to a path that depot_tools' GN wrapper will expect to find the binary.
43copy_path = 'buildtools/linux64/gn' if 'linux' in sys.platform else \
44 'buildtools/mac/gn' if 'darwin' in sys.platform else \
45 'buildtools/win/gn.exe'
46if os.path.isdir(os.path.dirname(copy_path)):
47 shutil.copy(dst, copy_path)