From d02862ab4161fe66b565729b3e8e1c3beec8c067 Mon Sep 17 00:00:00 2001 From: Omar Sandoval Date: Fri, 3 May 2019 10:14:27 -0700 Subject: [PATCH] setup.py: improve autotools glue autoreconf may successfully run autoconf but not automake, so we should check that Makefile.in exists, not configure. Additionally, there also seem to be some cases where configure fails but Makefile is still generated. Make sure we delete the potentially-broken output if autoreconf/configure failed. --- setup.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 06d8e6b6..8d14d4e5 100755 --- a/setup.py +++ b/setup.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import contextlib import re import os.path from distutils.dir_util import mkpath @@ -24,15 +25,28 @@ class my_build_ext(build_ext): help_options = [] def _run_autotools(self): - if not os.path.exists('libdrgn/configure'): - subprocess.check_call(['autoreconf', '-i', 'libdrgn']) + makefile_in = 'libdrgn/Makefile.in' + if not os.path.exists(makefile_in): + try: + subprocess.check_call(['autoreconf', '-i', 'libdrgn']) + except Exception: + with contextlib.suppress(FileNotFoundError): + os.remove(makefile_in) + raise + mkpath(self.build_temp) - if not os.path.exists(os.path.join(self.build_temp, 'Makefile')): + makefile = os.path.join(self.build_temp, 'Makefile') + if not os.path.exists(makefile): args = [ os.path.relpath('libdrgn/configure', self.build_temp), '--disable-static', '--with-python=' + sys.executable, ] - subprocess.check_call(args, cwd=self.build_temp) + try: + subprocess.check_call(args, cwd=self.build_temp) + except Exception: + with contextlib.suppress(FileNotFoundError): + os.remove(makefile) + raise def get_source_files(self): self._run_autotools()