14
14
import shutil
15
15
import subprocess
16
16
import sys
17
+ import tarfile
17
18
import textwrap
18
19
import urllib .request
19
20
import warnings
@@ -1045,6 +1046,8 @@ def add_flags(self, ext):
1045
1046
ext .define_macros .append (('FREETYPE_BUILD_TYPE' , 'system' ))
1046
1047
1047
1048
def do_custom_build (self ):
1049
+ from pathlib import Path
1050
+
1048
1051
# We're using a system freetype
1049
1052
if not options .get ('local_freetype' ):
1050
1053
return
@@ -1097,45 +1100,45 @@ def do_custom_build(self):
1097
1100
tarball_url = url_fmt .format (
1098
1101
version = LOCAL_FREETYPE_VERSION , tarball = tarball )
1099
1102
1100
- print ("Downloading {0 }" .format (tarball_url ))
1103
+ print ("Downloading {}" .format (tarball_url ))
1101
1104
try :
1102
1105
urllib .request .urlretrieve (tarball_url , tarball_path )
1103
1106
except IOError : # URLError (a subclass) on Py3.
1104
- print ("Failed to download {0 }" .format (tarball_url ))
1107
+ print ("Failed to download {}" .format (tarball_url ))
1105
1108
else :
1106
1109
if get_file_hash (tarball_path ) != LOCAL_FREETYPE_HASH :
1107
1110
print ("Invalid hash." )
1108
1111
else :
1109
1112
break
1110
1113
else :
1111
- raise IOError ("Failed to download freetype. "
1112
- "You can download the file by "
1113
- "alternative means and copy it "
1114
- " to '{0}'" .format (tarball_path ))
1114
+ raise IOError ("Failed to download FreeType. You can "
1115
+ "download the file by alternative means and "
1116
+ "copy it to {}" .format (tarball_path ))
1115
1117
os .makedirs (tarball_cache_dir , exist_ok = True )
1116
1118
try :
1117
1119
shutil .copy (tarball_path , tarball_cache_path )
1118
- print ('Cached tarball at: {}' .format (tarball_cache_path ))
1120
+ print ('Cached tarball at {}' .format (tarball_cache_path ))
1119
1121
except OSError :
1120
1122
# If this fails, we can always re-download.
1121
1123
pass
1122
1124
1123
1125
if get_file_hash (tarball_path ) != LOCAL_FREETYPE_HASH :
1124
1126
raise IOError (
1125
- "{0} does not match expected hash." .format (tarball ))
1127
+ "{} does not match expected hash." .format (tarball ))
1128
+
1129
+ print ("Building {}" .format (tarball ))
1130
+ with tarfile .open (tarball_path , "r:gz" ) as tgz :
1131
+ tgz .extractall ("build" )
1126
1132
1127
- print ("Building {0}" .format (tarball ))
1128
1133
if sys .platform != 'win32' :
1129
1134
# compilation on all other platforms than windows
1130
- cflags = 'CFLAGS="{0} -fPIC" ' .format (os .environ .get ('CFLAGS' , '' ))
1131
-
1132
- subprocess .check_call (
1133
- ['tar' , 'zxf' , tarball ], cwd = 'build' )
1134
- subprocess .check_call (
1135
- [cflags + './configure --with-zlib=no --with-bzip2=no '
1136
- '--with-png=no --with-harfbuzz=no' ], shell = True , cwd = src_path )
1135
+ env = {** os .environ ,
1136
+ "CFLAGS" : "{} -fPIC" .format (os .environ .get ("CFLAGS" , "" ))}
1137
1137
subprocess .check_call (
1138
- [cflags + 'make' ], shell = True , cwd = src_path )
1138
+ ["./configure" , "--with-zlib=no" , "--with-bzip2=no" ,
1139
+ "--with-png=no" , "--with-harfbuzz=no" ],
1140
+ env = env , cwd = src_path )
1141
+ subprocess .check_call (["make" ], env = env , cwd = src_path )
1139
1142
else :
1140
1143
# compilation on windows
1141
1144
FREETYPE_BUILD_CMD = """\
@@ -1154,11 +1157,10 @@ def do_custom_build(self):
1154
1157
copy %FREETYPE%\\ objs\\ win32\\ {vc20xx}\\ freetype261.lib %FREETYPE%\\ objs\\ .libs\\ libfreetype.lib
1155
1158
)
1156
1159
"""
1157
- from setup_external_compile import fixproj , prepare_build_cmd , VS2010 , X64 , tar_extract
1160
+ from setup_external_compile import fixproj , prepare_build_cmd , VS2010 , X64
1158
1161
# Note: freetype has no build profile for 2014, so we don't bother...
1159
1162
vc = 'vc2010' if VS2010 else 'vc2008'
1160
1163
WinXX = 'x64' if X64 else 'Win32'
1161
- tar_extract (tarball_path , "build" )
1162
1164
# This is only false for py2.7, even on py3.5...
1163
1165
if not VS2010 :
1164
1166
fixproj (os .path .join (src_path , 'builds' , 'windows' , vc , 'freetype.sln' ), WinXX )
0 commit comments