8000 Merge pull request #11249 from anntzer/freetype-tarball · matplotlib/matplotlib@6017a93 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6017a93

Browse files
authored
Merge pull request #11249 from anntzer/freetype-tarball
Simplify FreeType build.
2 parents 8168210 + cf84076 commit 6017a93

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

setupext.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import shutil
1515
import subprocess
1616
import sys
17+
import tarfile
1718
import textwrap
1819
import urllib.request
1920
import warnings
@@ -1025,6 +1026,8 @@ def add_flags(self, ext):
10251026
ext.define_macros.append(('FREETYPE_BUILD_TYPE', 'system'))
10261027

10271028
def do_custom_build(self):
1029+
from pathlib import Path
1030+
10281031
# We're using a system freetype
10291032
if not options.get('local_freetype'):
10301033
return
@@ -1077,45 +1080,45 @@ def do_custom_build(self):
10771080
tarball_url = url_fmt.format(
10781081
version=LOCAL_FREETYPE_VERSION, tarball=tarball)
10791082

1080-
print("Downloading {0}".format(tarball_url))
1083+
print("Downloading {}".format(tarball_url))
10811084
try:
10821085
urllib.request.urlretrieve(tarball_url, tarball_path)
10831086
except IOError: # URLError (a subclass) on Py3.
1084-
print("Failed to download {0}".format(tarball_url))
1087+
print("Failed to download {}".format(tarball_url))
10851088
else:
10861089
if get_file_hash(tarball_path) != LOCAL_FREETYPE_HASH:
10871090
print("Invalid hash.")
10881091
else:
10891092
break
10901093
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))
10951097
os.makedirs(tarball_cache_dir, exist_ok=True)
10961098
try:
10971099
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))
10991101
except OSError:
11001102
# If this fails, we can always re-download.
11011103
pass
11021104

11031105
if get_file_hash(tarball_path) != LOCAL_FREETYPE_HASH:
11041106
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")
11061112

1107-
print("Building {0}".format(tarball))
11081113
if sys.platform != 'win32':
11091114
# 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", ""))}
11171117
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)
11191122
else:
11201123
# compilation on windows
11211124
FREETYPE_BUILD_CMD = """\
@@ -1134,11 +1137,10 @@ def do_custom_build(self):
11341137
copy %FREETYPE%\\objs\\win32\\{vc20xx}\\freetype261.lib %FREETYPE%\\objs\\.libs\\libfreetype.lib
11351138
)
11361139
"""
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
11381141
# Note: freetype has no build profile for 2014, so we don't bother...
11391142
vc = 'vc2010' if VS2010 else 'vc2008'
11401143
WinXX = 'x64' if X64 else 'Win32'
1141-
tar_extract(tarball_path, "build")
11421144
# This is only false for py2.7, even on py3.5...
11431145
if not VS2010:
11441146
fixproj(os.path.join(src_path, 'builds', 'windows', vc, 'freetype.sln'), WinXX)

0 commit comments

Comments
 (0) 2F77
0