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 | |
Hal Canary | 7f660e8 | 2017-01-13 13:49:18 -0500 | [diff] [blame] | 8 | import hashlib |
Mike Klein | b621a35 | 2017-01-12 13:20:38 -0500 | [diff] [blame] | 9 | import os |
| 10 | import shutil |
| 11 | import stat |
mtklein | 6af0c95 | 2016-07-22 03:34:25 -0700 | [diff] [blame] | 12 | import sys |
Mike Klein | b621a35 | 2017-01-12 13:20:38 -0500 | [diff] [blame] | 13 | import urllib2 |
mtklein | 6af0c95 | 2016-07-22 03:34:25 -0700 | [diff] [blame] | 14 | |
Hal Canary | 7f660e8 | 2017-01-13 13:49:18 -0500 | [diff] [blame] | 15 | os.chdir(os.path.join(os.path.dirname(__file__), os.pardir)) |
mtklein | 6af0c95 | 2016-07-22 03:34:25 -0700 | [diff] [blame] | 16 | |
Mike Klein | cdcadf7 | 2018-02-15 10:41:10 -0500 | [diff] [blame] | 17 | dst = 'bin/gn.exe' if 'win32' in sys.platform else 'bin/gn' |
Mike Klein | b621a35 | 2017-01-12 13:20:38 -0500 | [diff] [blame] | 18 | |
Ben Wagner | bb9cad0 | 2018-05-23 03:59:02 -0400 | [diff] [blame] | 19 | sha1 = '2f27ff0b6118e5886df976da5effa6003d19d1ce' if 'linux' in sys.platform else \ |
| 20 | '9be792dd9010ce303a9c3a497a67bcc5ac8c7666' if 'darwin' in sys.platform else \ |
| 21 | 'eb69be2d984b4df60a8c21f598135991f0ad1742' # Windows |
Hal Canary | 7f660e8 | 2017-01-13 13:49:18 -0500 | [diff] [blame] | 22 | |
| 23 | def 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 Klein | cdcadf7 | 2018-02-15 10:41:10 -0500 | [diff] [blame] | 30 | if sha1_of_file(dst) != sha1: |
| 31 | with open(dst, 'wb') as f: |
Mike Klein | b621a35 | 2017-01-12 13:20:38 -0500 | [diff] [blame] | 32 | f.write(urllib2.urlopen('https://chromium-gn.storage-download.googleapis.com/' + sha1).read()) |
| 33 | |
Mike Klein | cdcadf7 | 2018-02-15 10:41:10 -0500 | [diff] [blame] | 34 | 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 Canary | 7f660e8 | 2017-01-13 13:49:18 -0500 | [diff] [blame] | 37 | |
Mike Klein | cdcadf7 | 2018-02-15 10:41:10 -0500 | [diff] [blame] | 38 | # We'll also copy to a path that depot_tools' GN wrapper will expect to find the binary. |
| 39 | copy_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' |
| 42 | if os.path.isdir(os.path.dirname(copy_path)): |
| 43 | shutil.copy(dst, copy_path) |