diff --git a/setupext.py b/setupext.py index d9a28ddee6d7..7b70197cdf07 100644 --- a/setupext.py +++ b/setupext.py @@ -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'): + 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,