Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cf84076

Browse filesBrowse 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 126113f commit cf84076
Copy full SHA for cf84076

File tree

Expand file treeCollapse file tree

1 file changed

+21
-19
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+21
-19
lines changed

‎setupext.py

Copy file name to clipboardExpand all lines: setupext.py
+21-19Lines 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
@@ -1029,6 +1030,8 @@ def add_flags(self, ext):
10291030
ext.define_macros.append(('FREETYPE_BUILD_TYPE', 'system'))
10301031

10311032
def do_custom_build(self):
1033+
from pathlib import Path
1034+
10321035
# We're using a system freetype
10331036
if not options.get('local_freetype'):
10341037
return
@@ -1081,45 +1084,45 @@ def do_custom_build(self):
10811084
tarball_url = url_fmt.format(
10821085
version=LOCAL_FREETYPE_VERSION, tarball=tarball)
10831086

1084-
print("Downloading {0}".format(tarball_url))
1087+
print("Downloading {}".format(tarball_url))
10851088
try:
10861089
urllib.request.urlretrieve(tarball_url, tarball_path)
10871090
except IOError: # URLError (a subclass) on Py3.
1088-
print("Failed to download {0}".format(tarball_url))
1091+
print("Failed to download {}".format(tarball_url))
10891092
else:
10901093
if get_file_hash(tarball_path) != LOCAL_FREETYPE_HASH:
10911094
print("Invalid hash.")
10921095
else:
10931096
break
10941097
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))
10991101
os.makedirs(tarball_cache_dir, exist_ok=True)
11001102
try:
11011103
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))
11031105
except OSError:
11041106
# If this fails, we can always re-download.
11051107
pass
11061108

11071109
if get_file_hash(tarball_path) != LOCAL_FREETYPE_HASH:
11081110
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")
11101116

1111-
print("Building {0}".format(tarball))
11121117
if sys.platform != 'win32':
11131118
# 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", ""))}
11211121
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)
11231126
else:
11241127
# compilation on windows
11251128
FREETYPE_BUILD_CMD = """\
@@ -1138,11 +1141,10 @@ def do_custom_build(self):
11381141
copy %FREETYPE%\\objs\\win32\\{vc20xx}\\freetype261.lib %FREETYPE%\\objs\\.libs\\libfreetype.lib
11391142
)
11401143
"""
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
11421145
# Note: freetype has no build profile for 2014, so we don't bother...
11431146
vc = 'vc2010' if VS2010 else 'vc2008'
11441147
WinXX = 'x64' if X64 else 'Win32'
1145-
tar_extract(tarball_path, "build")
11461148
# This is only false for py2.7, even on py3.5...
11471149
if not VS2010:
11481150
fixproj(os.path.join(src_path, 'builds', 'windows', vc, 'freetype.sln'), WinXX)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.