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.
This commit is contained in:
Omar Sandoval 2019-05-03 10:14:27 -07:00
parent ce74f3fee1
commit d02862ab41

View File

@ -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'):
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,
]
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()