blob: 78b5c05221d5ca3d2e61717a6a19d6dea5883755 [file] [log] [blame]
Hal Canaryb357dea2017-03-08 10:54:09 -05001#!/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
8import hashlib
9import os
10import shutil
11import stat
12import sys
13import urllib2
14
15os.chdir(os.path.join(os.path.dirname(__file__), os.pardir))
16
17def 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
44fetch('clang-format')