Skip to content

Commit 00d2340

Browse files
authored
Merge pull request #13462 from tacaswell/auto-backport-of-pr-13455-on-v2.2.x
Merge pull request #13455 from tacaswell/fix_freetype_download_logic
2 parents a7b885c + cce4dac commit 00d2340

File tree

1 file changed

+42
-35
lines changed

1 file changed

+42
-35
lines changed

setupext.py

+42-35
Original file line numberDiff line numberDiff line change
@@ -1252,44 +1252,51 @@ def do_custom_build(self):
12521252
else:
12531253
libfreetype = 'libfreetype.a'
12541254

1255-
if os.path.isfile(os.path.join(src_path, 'objs', '.libs', libfreetype)):
1255+
# bailing because it is already built
1256+
if os.path.isfile(os.path.join(
1257+
src_path, 'objs', '.libs', libfreetype)):
12561258
return
1257-
if not os.path.exists('build'):
1258-
os.makedirs('build')
1259-
1260-
url_fmts = [
1261-
('https://downloads.sourceforge.net/project/freetype'
1262-
'/freetype2/{version}/{tarball}'),
1263-
('https://download.savannah.gnu.org/releases/freetype'
1264-
'/{tarball}')
1265-
]
1266-
tarball = 'freetype-{0}.tar.gz'.format(LOCAL_FREETYPE_VERSION)
12671259

1268-
target_urls = [
1269-
url_fmt.format(version=LOCAL_FREETYPE_VERSION,
1270-
tarball=tarball)
1271-
for url_fmt in url_fmts]
1260+
# do we need to download / load the source from cache?
1261+
if not os.path.exists(src_path):
1262+
if not os.path.exists('build'):
1263+
os.makedirs('build')
12721264

1273-
for tarball_url in target_urls:
1274-
try:
1275-
tar_contents = download_or_cache(tarball_url,
1276-
LOCAL_FREETYPE_HASH)
1277-
break
1278-
except Exception:
1279-
pass
1280-
else:
1281-
raise IOError("Failed to download FreeType. Please download " +
1282-
"one of {target_urls} ".format(
1283-
target_urls=target_urls) +
1284-
"and extract it into the build directory "
1285-
"at the top-level of the source repository")
1286-
1287-
print("Building {}".format(tarball))
1288-
tar_contents.seek(0)
1289-
with tarfile.open(tarball, mode="r:gz", fileobj=tar_contents) as tgz:
1290-
tgz.extractall("build")
1291-
1292-
print("Building {0}".format(tarball))
1265+
url_fmts = [
1266+
('https://downloads.sourceforge.net/project/freetype'
1267+
'/freetype2/{version}/{tarball}'),
1268+
('https://download.savannah.gnu.org/releases/freetype'
1269+
'/{tarball}')
1270+
]
1271+
tarball = 'freetype-{0}.tar.gz'.format(LOCAL_FREETYPE_VERSION)
1272+
1273+
target_urls = [
1274+
url_fmt.format(version=LOCAL_FREETYPE_VERSION,
1275+
tarball=tarball)
1276+
for url_fmt in url_fmts]
1277+
1278+
for tarball_url in target_urls:
1279+
try:
1280+
tar_contents = download_or_cache(tarball_url,
1281+
LOCAL_FREETYPE_HASH)
1282+
break
1283+
except Exception:
1284+
pass
1285+
else:
1286+
raise IOError("Failed to download FreeType. Please download "
1287+
"one of {target_urls} and extract it into "
1288+
"{src_path} at the top-level of the source "
1289+
"repository".format(
1290+
target_urls=target_urls, src_path=src_path))
1291+
1292+
print("Extracting {}".format(tarball))
1293+
# just to be sure
1294+
tar_contents.seek(0)
1295+
with tarfile.open(tarball, mode="r:gz",
1296+
fileobj=tar_contents) as tgz:
1297+
tgz.extractall("build")
1298+
1299+
print("Building freetype in {}".format(src_path))
12931300
if sys.platform != 'win32':
12941301
# compilation on all other platforms than windows
12951302
cflags = 'CFLAGS="{0} -fPIC" '.format(os.environ.get('CFLAGS', ''))

0 commit comments

Comments
 (0)