Skip to content

BLD: only try to get freetype src if src does not exist #13455

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
Feb 18, 2019
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
76 changes: 42 additions & 34 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,43 +960,51 @@ def do_custom_build(self):
else:
libfreetype = 'libfreetype.a'

if os.path.isfile(os.path.join(src_path, 'objs', '.libs', libfreetype)):
# bailing because it is already built
if os.path.isfile(os.path.join(
src_path, 'objs', '.libs', libfreetype)):
return
if not os.path.exists('build'):
os.makedirs('build')

url_fmts = [
('https://downloads.sourceforge.net/project/freetype'
'/freetype2/{version}/{tarball}'),
('https://download.savannah.gnu.org/releases/freetype'
'/{tarball}')
]
tarball = 'freetype-{0}.tar.gz'.format(LOCAL_FREETYPE_VERSION)

target_urls = [
url_fmt.format(version=LOCAL_FREETYPE_VERSION,
tarball=tarball)
for url_fmt in url_fmts]

for tarball_url in target_urls:
try:
tar_contents = download_or_cache(tarball_url,
LOCAL_FREETYPE_HASH)
break
except Exception:
pass
else:
raise IOError("Failed to download FreeType. Please download " +
"one of {target_urls} ".format(
target_urls=target_urls) +
"and extract it into the build directory "
"at the top-level of the source repository")

print("Building {}".format(tarball))
tar_contents.seek(0)
with tarfile.open(tarball, mode="r:gz", fileobj=tar_contents) as tgz:
tgz.extractall("build")
# do we need to download / load the source from cache?
if not os.path.exists(src_path):
if not os.path.exists('build'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this belongs out of the main if? (if the source tree exists but not the buildddir, you still want to mkdir build)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The src path is in build (see L954) so if we have the source dir, build exists.

os.makedirs('build')

url_fmts = [
('https://downloads.sourceforge.net/project/freetype'
'/freetype2/{version}/{tarball}'),
('https://download.savannah.gnu.org/releases/freetype'
'/{tarball}')
]
tarball = 'freetype-{0}.tar.gz'.format(LOCAL_FREETYPE_VERSION)

target_urls = [
url_fmt.format(version=LOCAL_FREETYPE_VERSION,
tarball=tarball)
for url_fmt in url_fmts]

for tarball_url in target_urls:
try:
tar_contents = download_or_cache(tarball_url,
LOCAL_FREETYPE_HASH)
break
except Exception:
pass
else:
raise IOError("Failed to download FreeType. Please download "
"one of {target_urls} and extract it into "
"{src_path} at the top-level of the source "
"repository".format(
target_urls=target_urls, src_path=src_path))

print("Extracting {}".format(tarball))
# just to be sure
tar_contents.seek(0)
with tarfile.open(tarball, mode="r:gz",
fileobj=tar_contents) as tgz:
tgz.extractall("build")

print("Building freetype in {}".format(src_path))
if sys.platform != 'win32':
# compilation on all other platforms than windows
env = {**os.environ,
Expand Down