blob: 5d03fd3310486601c32dd8b0c08af40aff86d781 [file] [log] [blame]
Andrew Top200ce4b2018-01-29 13:43:50 -08001#!/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
8import hashlib
9import os
10import shutil
11import stat
12import sys
13import urllib2
14
15os.chdir(os.path.join(os.path.dirname(__file__), os.pardir))
16
Xiaoming Shi73dfa202020-03-12 11:31:35 -070017dst = 'bin/gn.exe' if 'win32' in sys.platform else 'bin/gn'
Andrew Top200ce4b2018-01-29 13:43:50 -080018
Xiaoming Shi73dfa202020-03-12 11:31:35 -070019sha1 = '3523d50538357829725d4ed74b777a572ce0ac74' if 'linux' in sys.platform else \
20 'd43122f6140d0711518aa909980cb009c4fbce3d' if 'darwin' in sys.platform else \
21 'e20768d93a6b4400de0d03bb8ceb46facdbe3883' # Windows
Andrew Top200ce4b2018-01-29 13:43:50 -080022
23def sha1_of_file(path):
24 h = hashlib.sha1()
25 if os.path.isfile(path):
26 with open(path, 'rb') as f:
27 h.update(f.read())
28 return h.hexdigest()
29
Xiaoming Shi73dfa202020-03-12 11:31:35 -070030if sha1_of_file(dst) != sha1:
31 with open(dst, 'wb') as f:
Andrew Top200ce4b2018-01-29 13:43:50 -080032 f.write(urllib2.urlopen('https://chromium-gn.storage-download.googleapis.com/' + sha1).read())
33
Xiaoming Shi73dfa202020-03-12 11:31:35 -070034 os.chmod(dst, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
35 stat.S_IRGRP | stat.S_IXGRP |
36 stat.S_IROTH | stat.S_IXOTH )
Andrew Top200ce4b2018-01-29 13:43:50 -080037
Xiaoming Shi73dfa202020-03-12 11:31:35 -070038# We'll also copy to a path that depot_tools' GN wrapper will expect to find the binary.
39copy_path = 'buildtools/linux64/gn' if 'linux' in sys.platform else \
40 'buildtools/mac/gn' if 'darwin' in sys.platform else \
41 'buildtools/win/gn.exe'
42if os.path.isdir(os.path.dirname(copy_path)):
43 shutil.copy(dst, copy_path)