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