|
23 | 23 | # of freetype. It must match the value in
|
24 | 24 | # lib/matplotlib.__init__.py:validate_test_dependencies
|
25 | 25 | LOCAL_FREETYPE_VERSION = '2.5.2'
|
26 |
| - |
| 26 | +# md5 hash of the freetype tarball |
| 27 | +LOCAL_FREETYPE_HASH = '004320381043d275c4e28bbacf05a1b7' |
27 | 28 |
|
28 | 29 | try:
|
29 | 30 | from subprocess import check_output
|
@@ -247,6 +248,21 @@ def make_extension(name, files, *args, **kwargs):
|
247 | 248 | return ext
|
248 | 249 |
|
249 | 250 |
|
| 251 | +def get_file_hash(filename): |
| 252 | + """ |
| 253 | + Get the MD5 hash of a given filename. |
| 254 | + """ |
| 255 | + import hashlib |
| 256 | + BLOCKSIZE = 1 << 16 |
| 257 | + hasher = hashlib.md5() |
| 258 | + with open(filename, 'rb') as fd: |
| 259 | + buf = fd.read(BLOCKSIZE) |
| 260 | + while len(buf) > 0: |
| 261 | + hasher.update(buf) |
| 262 | + buf = fd.read(BLOCKSIZE) |
| 263 | + return hasher.hexdigest() |
| 264 | + |
| 265 | + |
250 | 266 | class PkgConfig(object):
|
251 | 267 | """
|
252 | 268 | This is a class for communicating with pkg-config.
|
@@ -991,15 +1007,18 @@ def do_custom_build(self):
|
991 | 1007 | tarball = 'freetype-{0}.tar.gz'.format(LOCAL_FREETYPE_VERSION)
|
992 | 1008 | tarball_path = os.path.join('build', tarball)
|
993 | 1009 | if not os.path.isfile(tarball_path):
|
994 |
| - print("Downloading {0}".format(tarball)) |
| 1010 | + tarball_url = 'http://download.savannah.gnu.org/releases/freetype/{0}'.format(tarball) |
| 1011 | + |
| 1012 | + print("Downloading {0}".format(tarball_url)) |
995 | 1013 | if sys.version_info[0] == 2:
|
996 | 1014 | from urllib import urlretrieve
|
997 | 1015 | else:
|
998 | 1016 | from urllib.request import urlretrieve
|
999 | 1017 |
|
1000 |
| - urlretrieve( |
1001 |
| - 'http://download.savannah.gnu.org/releases/freetype/{0}'.format(tarball), |
1002 |
| - tarball_path) |
| 1018 | + urlretrieve(tarball_url, tarball_path) |
| 1019 | + |
| 1020 | + if get_file_hash(tarball_path) != LOCAL_FREETYPE_HASH: |
| 1021 | + raise IOError("{0} does not match expected hash.".format(tarball)) |
1003 | 1022 |
|
1004 | 1023 | print("Building {0}".format(tarball))
|
1005 | 1024 | subprocess.check_call(
|
|
0 commit comments