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 8import hashlib 9import os 10import shutil 11import stat 12import sys 13 14if sys.version_info[0] < 3: 15 from urllib2 import urlopen 16else: 17 from urllib.request import urlopen 18 19os.chdir(os.path.join(os.path.dirname(__file__), os.pardir)) 20 21dst = 'bin/gn.exe' if 'win32' in sys.platform else 'bin/gn' 22 23sha1 = '3523d50538357829725d4ed74b777a572ce0ac74' if 'linux' in sys.platform else \ 24 'd43122f6140d0711518aa909980cb009c4fbce3d' if 'darwin' in sys.platform else \ 25 'e20768d93a6b4400de0d03bb8ceb46facdbe3883' # Windows 26 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 34if sha1_of_file(dst) != sha1: 35 with open(dst, 'wb') as f: 36 f.write(urlopen('https://chromium-gn.storage-download.googleapis.com/' + sha1).read()) 37 38 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 ) 41 42# 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) 48