1#!/usr/bin/env python3 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 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 21def fetch(target): 22 target_path = 'buildtools/linux64/' + target if 'linux' in sys.platform else \ 23 'buildtools/mac/' + target if 'darwin' in sys.platform else \ 24 'buildtools/win/'+ target + '.exe' 25 26 sha1_path = target_path + '.sha1' 27 if not os.path.exists(sha1_path): 28 print(sha1_path, 'is missing. Did you run `tools/git-sync-deps`?') 29 exit(1) 30 sha1 = open(sha1_path).read().strip() 31 32 def sha1_of_file(path): 33 h = hashlib.sha1() 34 if os.path.isfile(path): 35 with open(path, 'rb') as f: 36 h.update(f.read()) 37 return h.hexdigest() 38 39 if sha1_of_file(target_path) != sha1: 40 with open(target_path, 'wb') as f: 41 url = 'https://chromium-%s.storage-download.googleapis.com/%s' % (target, sha1) 42 f.write(urlopen(url).read()) 43 44 os.chmod(target_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | 45 stat.S_IRGRP | stat.S_IXGRP | 46 stat.S_IROTH | stat.S_IXOTH ) 47 48 target_copy_path = os.path.join('bin', os.path.basename(target_path)) 49 if sha1_of_file(target_copy_path) != sha1: 50 shutil.copy(target_path, target_copy_path) 51 52fetch('clang-format') 53