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
@@ -1025,6 +1026,8 @@ def add_flags(self, ext):
1025
1026
ext .define_macros .append (('FREETYPE_BUILD_TYPE' , 'system' ))
1026
1027
1027
1028
def do_custom_build (self ):
1029
+ from pathlib import Path
1030
+
1028
1031
# We're using a system freetype
1029
1032
if not options .get ('local_freetype' ):
1030
1033
return
@@ -1077,45 +1080,45 @@ def do_custom_build(self):
1077
1080
tarball_url = url_fmt .format (
1078
1081
version = LOCAL_FREETYPE_VERSION , tarball = tarball )
1079
1082
1080
- print ("Downloading {0 }" .format (tarball_url ))
1083
+ print ("Downloading {}" .format (tarball_url ))
1081
1084
try :
1082
1085
urllib .request .urlretrieve (tarball_url , tarball_path )
1083
1086
except IOError : # URLError (a subclass) on Py3.
1084
- print ("Failed to download {0 }" .format (tarball_url ))
1087
+ print ("Failed to download {}" .format (tarball_url ))
1085
1088
else :
1086
1089
if get_file_hash (tarball_path ) != LOCAL_FREETYPE_HASH :
1087
1090
print ("Invalid hash." )
1088
1091
else :
1089
1092
break
1090
1093
else :
1091
- raise IOError ("Failed to download freetype. "
1092
- "You can download the file by "
1093
- "alternative means and copy it "
1094
- " to '{0}'" .format (tarball_path ))
1094
+ raise IOError ("Failed to download FreeType. You can "
1095
+ "download the file by alternative means and "
1096
+ "copy it to {}" .format (tarball_path ))
1095
1097
os .makedirs (tarball_cache_dir , exist_ok = True )
1096
1098
try :
1097
1099
shutil .copy (tarball_path , tarball_cache_path )
1098
- print ('Cached tarball at: {}' .format (tarball_cache_path ))
1100
+ print ('Cached tarball at {}' .format (tarball_cache_path ))
1099
1101
except OSError :
1100
1102
# If this fails, we can always re-download.
1101
1103
pass
1102
1104
1103
1105
if get_file_hash (tarball_path ) != LOCAL_FREETYPE_HASH :
1104
1106
raise IOError (
1105
- "{0} does not match expected hash." .format (tarball ))
1107
+ "{} does not match expected hash." .format (tarball ))
1108
+
1109
+ print ("Building {}" .format (tarball ))
1110
+ with tarfile .open (tarball_path , "r:gz" ) as tgz :
1111
+ tgz .extractall ("build" )
1106
1112
1107
- print ("Building {0}" .format (tarball ))
1108
1113
if sys .platform != 'win32' :
1109
1114
# compilation on all other platforms than windows
1110
- cflags = 'CFLAGS="{0} -fPIC" ' .format (os .environ .get ('CFLAGS' , '' ))
1111
-
1112
- subprocess .check_call (
1113
- ['tar' , 'zxf' , tarball ], cwd = 'build' )
1114
- subprocess .check_call (
1115
- [cflags + './configure --with-zlib=no --with-bzip2=no '
1116
- '--with-png=no --with-harfbuzz=no' ], shell = True , cwd = src_path )
1115
+ env = {** os .environ ,
1116
+ "CFLAGS" : "{} -fPIC" .format (os .environ .get ("CFLAGS" , "" ))}
1117
1117
subprocess .check_call (
1118
- [cflags + 'make' ], shell = True , cwd = src_path )
1118
+ ["./configure" , "--with-zlib=no" , "--with-bzip2=no" ,
1119
+ "--with-png=no" , "--with-harfbuzz=no" ],
1120
+ env = env , cwd = src_path )
1121
+ subprocess .check_call (["make" ], env = env , cwd = src_path )
1119
1122
else :
1120
1123
# compilation on windows
1121
1124
FREETYPE_BUILD_CMD = """\
@@ -1134,11 +1137,10 @@ def do_custom_build(self):
1134
1137
copy %FREETYPE%\\ objs\\ win32\\ {vc20xx}\\ freetype261.lib %FREETYPE%\\ objs\\ .libs\\ libfreetype.lib
1135
1138
)
1136
1139
"""
1137
- from setup_external_compile import fixproj , prepare_build_cmd , VS2010 , X64 , tar_extract
1140
+ from setup_external_compile import fixproj , prepare_build_cmd , VS2010 , X64
1138
1141
# Note: freetype has no build profile for 2014, so we don't bother...
1139
1142
vc = 'vc2010' if VS2010 else 'vc2008'
1140
1143
WinXX = 'x64' if X64 else 'Win32'
1141
- tar_extract (tarball_path , "build" )
1142
1144
# This is only false for py2.7, even on py3.5...
1143
1145
if not VS2010 :
1144
1146
fixproj (os .path .join (src_path , 'builds' , 'windows' , vc , 'freetype.sln' ), WinXX )
0 commit comments