8000 Simplify FreeType build. · matplotlib/matplotlib@98a0e36 · GitHub
[go: up one dir, main page]

Skip to content

Commit 98a0e36

Browse files
committed
Simplify FreeType build.
- Reformat a bunch of strings. - Rely on Python's tarfile module to extract the FreeType tarball, instead of the "tar" executable (because we need to use Python's tarfile on Windows anyways, so we may as well do it on all OSes). - For the Unix build, call `./configure` and `make` without `shell=True`, instead setting CFLAGS in the environment as needed.
1 parent 920295d commit 98a0e36

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
@@ -1045,6 +1046,8 @@ def add_flags(self, ext):
10451046
ext.define_macros.append(('FREETYPE_BUILD_TYPE', 'system'))
10461047

10471048
def do_custom_build(self):
1049+
from pathlib import Path
1050+
10481051
# We're using a system freetype
10491052
if not options.get('local_freetype'):
10501053
return
@@ -1097,45 +1100,45 @@ def do_custom_build(self):
10971100
tarball_url = url_fmt.format(
10981101
version=LOCAL_FREETYPE_VERSION, tarball=tarball)
10991102

1100-
print("Downloading {0}".format(tarball_url))
1103+
print("Downloading {}".format(tarball_url))
11011104
try:
11021105
urllib.request.urlretrieve(tarball_url, tarball_path)
11031106
except IOError: # URLError (a subclass) on Py3.
1104-
print("Failed to download {0}".format(tarball_url))
1107+
print("Failed to download {}".format(tarball_url))
11051108
else:
11061109
if get_file_hash(tarball_path) != LOCAL_FREETYPE_HASH:
11071110
print("Invalid hash.")
11081111
else:
11091112
break
11101113
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))
11151117
os.makedirs(tarball_cache_dir, exist_ok=True)
11161118
try:
11171119
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))
11191121
except OSError:
11201122
# If this fails, we can always re-download.
11211123
pass
11221124

11231125
if get_file_hash(tarball_path) != LOCAL_FREETYPE_HASH:
11241126
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")
11261132

1127-
print("Building {0}".format(tarball))
11281133
if sys.platform != 'win32':
11291134
# 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", ""))}
11371137
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)
11391142
else:
11401143
# compilation on windows
11411144
FREETYPE_BUILD_CMD = """\
@@ -1154,11 +1157,10 @@ def do_custom_build(self):
11541157
copy %FREETYPE%\\objs\\win32\\{vc20xx}\\freetype261.lib %FREETYPE%\\objs\\.libs\\libfreetype.lib
11551158
)
11561159
"""
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
11581161
# Note: freetype has no build profile for 2014, so we don't bother...
11591162
vc = 'vc2010' if VS2010 else 'vc2008'
11601163
WinXX = 'x64' if X64 else 'Win32'
1161-
tar_extract(tarball_path, "build")
11621164
# This is only false for py2.7, even on py3.5...
11631165
if not VS2010:
11641166
fixproj(os.path.join(src_path, 'builds', 'windows', vc, 'freetype.sln'), WinXX)

0 commit comments

Comments
 (0)
0