aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/fetch-clang-win
blob: 06ff07b12c70f8abda815b2a55063200269b26a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python

# Copyright 2017 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

VERSION = '308728-3'
MD5     = '8bec8c34da5d256e27638383667489e5'

import hashlib
import os
import shutil
import tarfile
import urllib2

os.chdir(os.path.dirname(__file__))

if (not os.path.exists('clang_win/md5.txt')
        or open('clang_win/md5.txt').read().strip() != MD5):

  # Clear out everything and start fresh.
  shutil.rmtree('clang_win', ignore_errors=True)
  os.mkdir('clang_win')
  os.chdir('clang_win')

  # Grab the current Clang package.
  with open(VERSION + '.tgz', 'wb') as tgz:
    url = 'https://commondatastorage.googleapis.com/chromium-browser-clang'
    tgz.write(urllib2.urlopen(url + '/Win/clang-' + VERSION + '.tgz').read())

  # Extract it.
  tarfile.open(VERSION + '.tgz').extractall()

  # Write out its hash to md5.txt so that next time is quicker.
  h = hashlib.md5()
  with open(VERSION + '.tgz', 'rb') as tgz:
    h.update(tgz.read())
  with open('md5.txt', 'w') as md5:
    md5.write(h.hexdigest())