blob: be2cb1acecc1eaa99b2f42b43ecd9c81ce9c35c5 [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
Mike Kleinb621a352017-01-12 13:20:38 -050013import urllib2
mtklein6af0c952016-07-22 03:34:25 -070014
Hal Canary7f660e82017-01-13 13:49:18 -050015os.chdir(os.path.join(os.path.dirname(__file__), os.pardir))
mtklein6af0c952016-07-22 03:34:25 -070016
Mike Kleincdcadf72018-02-15 10:41:10 -050017dst = 'bin/gn.exe' if 'win32' in sys.platform else 'bin/gn'
Mike Kleinb621a352017-01-12 13:20:38 -050018
Mike Kleincdcadf72018-02-15 10:41:10 -050019sha1 = '113f5b30a7cfae72015600a119590d45d64c0d0d' if 'linux' in sys.platform else \
20 'b33a6d33c2b2f42762f902672ffdf4837fa1c662' if 'darwin' in sys.platform else \
21 'b1981c189f40c3ae42b965277ad1bc3449d26d2a' # Windows
Hal Canary7f660e82017-01-13 13:49:18 -050022
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
Mike Kleincdcadf72018-02-15 10:41:10 -050030if sha1_of_file(dst) != sha1:
31 with open(dst, 'wb') as f:
Mike Kleinb621a352017-01-12 13:20:38 -050032 f.write(urllib2.urlopen('https://chromium-gn.storage-download.googleapis.com/' + sha1).read())
33
Mike Kleincdcadf72018-02-15 10:41:10 -050034 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 )
Hal Canary7f660e82017-01-13 13:49:18 -050037
Mike Kleincdcadf72018-02-15 10:41:10 -050038# 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)