1 #!/usr/bin/env python 2 3 # Copyright 2017 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 8 import hashlib 9 import os 10 import shutil 11 import stat 12 import sys 13 import urllib2 14 15 os.chdir(os.path.join(os.path.dirname(__file__), os.pardir)) 16 17 def fetch(target): 18 target_path = 'buildtools/linux64/' + target if 'linux' in sys.platform else \ 19 'buildtools/mac/' + target if 'darwin' in sys.platform else \ 20 'buildtools/win/'+ target + '.exe' 21 22 sha1 = open(target_path + '.sha1').read().strip() 23 24 def sha1_of_file(path): 25 h = hashlib.sha1() 26 if os.path.isfile(path): 27 with open(path, 'rb') as f: 28 h.update(f.read()) 29 return h.hexdigest() 30 31 if sha1_of_file(target_path) != sha1: 32 with open(target_path, 'wb') as f: 33 url = 'https://chromium-%s.storage-download.googleapis.com/%s' % (target, sha1) 34 f.write(urllib2.urlopen(url).read()) 35 36 os.chmod(target_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | 37 stat.S_IRGRP | stat.S_IXGRP | 38 stat.S_IROTH | stat.S_IXOTH ) 39 40 target_copy_path = os.path.join('bin', os.path.basename(target_path)) 41 if sha1_of_file(target_copy_path) != sha1: 42 shutil.copy(target_path, target_copy_path) 43 44 fetch('clang-format') 45