Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Inline setup_external_build into setupext.#11235
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -14,6 +14,7 @@ | ||
import shutil | ||
import subprocess | ||
import sys | ||
import tarfile | ||
import textwrap | ||
import urllib.request | ||
import warnings | ||
@@ -1045,6 +1046,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 | ||
@@ -1058,7 +1061,7 @@ def do_custom_build(self): | ||
else: | ||
libfreetype = 'libfreetype.a' | ||
ifPath(src_path,"objs", ".libs", libfreetype).is_file(): | ||
return | ||
tarball = 'freetype-{0}.tar.gz'.format(LOCAL_FREETYPE_VERSION) | ||
@@ -1097,21 +1100,20 @@ def do_custom_build(self): | ||
tarball_url = url_fmt.format( | ||
version=LOCAL_FREETYPE_VERSION, tarball=tarball) | ||
print("Downloading {}".format(tarball_url)) | ||
try: | ||
urllib.request.urlretrieve(tarball_url, tarball_path) | ||
except IOError: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Changed in version 3.3: URLError has been made a subclass of OSError instead of IOError. We should check for the more specific There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. IOError is an alias of OSError since 3.3 (see just afterhttps://docs.python.org/3/library/exceptions.html#ZeroDivisionError). | ||
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 '{}'".format(tarball_path)) | ||
os.makedirs(tarball_cache_dir, exist_ok=True) | ||
try: | ||
shutil.copy(tarball_path, tarball_cache_path) | ||
@@ -1122,55 +1124,55 @@ def do_custom_build(self): | ||
if get_file_hash(tarball_path) != LOCAL_FREETYPE_HASH: | ||
raise IOError( | ||
"{} does not match expected hash".format(tarball)) | ||
print("Building {}".format(tarball)) | ||
with tarfile.open(tarball_path, "r:gz") as tgz: | ||
tgz.extractall("build") | ||
if sys.platform != 'win32': | ||
# compilation on all other platforms than windows | ||
env={**os.environ, | ||
"CFLAGS": "{} -fPIC".format(os.environ.get("CFLAGS", ""))} | ||
subprocess.check_call( | ||
["./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 = r""" | ||
call "%ProgramFiles%\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.Cmd" ^ | ||
/Release /{xXX} /xp | ||
call "{vcvarsall}" {xXX} | ||
set MSBUILD=C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe | ||
%MSBUILD% "builds\windows\{vc20xx}\freetype.sln" ^ | ||
/t:Clean;Build /p:Configuration="{config}";Platform={WinXX} | ||
""" | ||
import distutils.msvc9compiler as msvc | ||
# FreeType 2.6.1 has no build profile for 2014. | ||
vcvarsall = msvc.find_vcvarsall(10.0) | ||
if vcvarsall is None: | ||
raise RuntimeError("Microsoft VS 2010 required") | ||
X64 = sys.maxsize > 2 ** 32 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Seehttps://docs.python.org/3/library/platform.html#platform.architecture for why we check bitsize in this manner. | ||
vc20xx = "vc2010" | ||
WinXX="x64" if X64 else "Win32" | ||
xXX="x64" if X64 else "x86" | ||
cmd_file = Path("build", "build_freetype.cmd") | ||
cmd_file.write_text(FREETYPE_BUILD_CMD.format( | ||
vcvarsall=msvc.find_vcvarsall(10.0), | ||
vc20xx=vc20xx, WinXX=WinXX, xXX=xXX, config="Release")) | ||
shutil.rmtree(str(Path(src_path, "objs")), ignore_errors=True) | ||
subprocess.check_call(cmdfile, shell=True, cwd=src_path) | ||
# Move to the corresponding Unix build path. | ||
Path(src_path, "objs/.libs").mkdir() | ||
# Be robust against change of FreeType version. | ||
lib_path, = (Path(src_path, "objs", vc20xx, xXX).glob() | ||
.glob("freetype*.lib")) | ||
shutil.copy2( | ||
str(lib_path), | ||
str(Path(src_path, "objs", ".libs", "libfreetype.lib")) | ||
) | ||
class FT2Font(SetupPackage): | ||