8000 Simplify FreeType build. by anntzer · Pull Request #11249 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Simplify FreeType build. #11249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import shutil
import subprocess
import sys
import tarfile
import textwrap
import urllib.request
import warnings
Expand Down Expand Up @@ -1029,6 +1030,8 @@ def add_flags(self, ext):
ext.define_macros.append(('FREETYPE_BUILD_TYPE', 'system'))

def do_custom_build(self):
from pathlib import Path

# We're using a system freetype
if not options.get('local_freetype'):
return
Expand Down Expand Up @@ -1081,45 +1084,45 @@ def do_custom_build(self):
tarball_url = url_fmt.format(
version=LOCAL_FREETYPE_VERSION, tarball=tarball)

print("Downloading {0}".format(tarball_url))
print("Downloading {}".format(tarball_url))
try:
urllib.request.urlretrieve(tarball_url, tarball_path)
except IOError: # URLError (a subclass) on Py3.
print("Failed to download {0}".format(tarball_url))
print("Failed to download {}".format(tarball_url))
else:
if get_file_hash(tarball_path) != LOCAL_FREETYPE_HASH:
print("Invalid hash.")
else:
break
else:
raise IOError("Failed to download freetype. "
"You can download the file by "
"alternative means and copy it "
" to '{0}'".format(tarball_path))
raise IOError("Failed to download FreeType. You can "
"download the file by alternative means and "
"copy it to {}".format(tarball_path))
os.makedirs(tarball_cache_dir, exist_ok=True)
try:
shutil.copy(tarball_path, tarball_cache_path)
print('Cached tarball at: {}'.format(tarball_cache_path))
print('Cached tarball at {}'.format(tarball_cache_path))
except OSError:
# If this fails, we can always re-download.
pass

if get_file_hash(tarball_path) != LOCAL_FREETYPE_HASH:
raise IOError(
"{0} does not match expected hash.".format(tarball))
"{} does not match expected hash.".format(tarball))

print("Building {}".format(tarball))
with tarfile.open(tarball_path, "r:gz") as tgz:
tgz.extractall("build")

print("Building {0}".format(tarball))
if sys.platform != 'win32':
# compilation on all other platforms than windows
cflags = 'CFLAGS="{0} -fPIC" '.format(os.environ.get('CFLAGS', ''))

subprocess.check_call(
['tar', 'zxf', tarball], cwd='build')
subprocess.check_call(
[cflags + './configure --with-zlib=no --with-bzip2=no '
'--with-png=no --with-harfbuzz=no'], shell=True, cwd=src_path)
env={**os.environ,
"CFLAGS": "{} -fPIC".format(os.environ.get("CFLAGS", ""))}
subprocess.check_call(
[cflags + 'make'], shell=True, cwd=src_path)
["./configure", "--with-zlib=no", "--with-bzip2=no",
"--with-png=no", "--with-harfbuzz=no"],
env=env, cwd=src_path)
subprocess.check_call(["make"], env=env, cwd=src_path)
else:
# compilation on windows
FREETYPE_BUILD_CMD = """\
Expand All @@ -1138,11 +1141,10 @@ def do_custom_build(self):
copy %FREETYPE%\\objs\\win32\\{vc20xx}\\freetype261.lib %FREETYPE%\\objs\\.libs\\libfreetype.lib
)
"""
from setup_external_compile import fixproj, prepare_build_cmd, VS2010, X64, tar_extract
from setup_external_compile import fixproj, prepare_build_cmd, VS2010, X64
# Note: freetype has no build profile for 2014, so we don't bother...
vc = 'vc2010' if VS2010 else 'vc2008'
WinXX = 'x64' if X64 else 'Win32'
tar_extract(tarball_path, "build")
# This is only false for py2.7, even on py3.5...
if not VS2010:
fixproj(os.path.join(src_path, 'builds', 'windows', vc, 'freetype.sln'), WinXX)
Expand Down
0