summaryrefslogtreecommitdiff
path: root/configure
diff options
context:
space:
mode:
Diffstat (limited to 'configure')
-rwxr-xr-xconfigure89
1 files changed, 79 insertions, 10 deletions
diff --git a/configure b/configure
index 5396376..6ca1a0f 100755
--- a/configure
+++ b/configure
@@ -1,11 +1,80 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
+
+from __future__ import with_statement, print_function, unicode_literals
import os
import re
import shlex
-import shutil
-import subprocess
-from sys import stderr
+try:
+ from shutil import which
+except ImportError:
+ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
+ """Given a command, mode, and a PATH string, return the path which
+ conforms to the given mode on the PATH, or None if there is no such
+ file.
+
+ `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
+ of os.environ.get("PATH"), or can be overridden with a custom search
+ path.
+
+ """
+ # Check that a given file can be accessed with the correct mode.
+ # Additionally check that `file` is not a directory, as on Windows
+ # directories pass the os.access check.
+ def _access_check(fn, mode):
+ return (os.path.exists(fn) and os.access(fn, mode)
+ and not os.path.isdir(fn))
+
+ # If we're given a path with a directory part, look it up directly rather
+ # than referring to PATH directories. This includes checking relative to the
+ # current directory, e.g. ./script
+ if os.path.dirname(cmd):
+ if _access_check(cmd, mode):
+ return cmd
+ return None
+
+ if path is None:
+ path = os.environ.get("PATH", os.defpath)
+ if not path:
+ return None
+ path = path.split(os.pathsep)
+
+ if platform == "win32":
+ # The current directory takes precedence on Windows.
+ if not os.curdir in path:
+ path.insert(0, os.curdir)
+
+ # PATHEXT is necessary to check on Windows.
+ pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
+ # See if the given file matches any of the expected path extensions.
+ # This will allow us to short circuit when given "python.exe".
+ # If it does match, only test that one, otherwise we have to try
+ # others.
+ if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
+ files = [cmd]
+ else:
+ files = [cmd + ext for ext in pathext]
+ else:
+ # On other platforms you don't have things like PATHEXT to tell you
+ # what file suffixes are executable, so just pass on cmd as-is.
+ files = [cmd]
+
+ seen = set()
+ for dir in path:
+ normdir = os.path.normcase(dir)
+ if not normdir in seen:
+ seen.add(normdir)
+ for thefile in files:
+ name = os.path.join(dir, thefile)
+ if _access_check(name, mode):
+ return name
+ return None
+from subprocess import CalledProcessError, STDOUT, check_call, check_output, list2cmdline
+try:
+ from subprocess import DEVNULL
+except ImportError:
+ DEVNULL = open(os.devnull, 'wb')
+from sys import platform, stderr
cmds = {}
warnings = []
@@ -34,7 +103,7 @@ def check(name, why, flags=[], optional=False, var=None, run=True):
elif varvalue is None:
varvalue = name
split = shlex.split(varvalue)
- exe = shutil.which(split[0])
+ exe = which(split[0])
if not exe:
stderr.write("not found\n")
if not optional:
@@ -47,16 +116,16 @@ def check(name, why, flags=[], optional=False, var=None, run=True):
if run:
checking("%s usability" % exe)
try:
- subprocess.check_call(cmd + ["-h"], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
+ check_call(cmd + ["-h"], stdout=DEVNULL, stderr=STDOUT)
stderr.write("yes\n")
- except subprocess.CalledProcessError as e:
- raise CheckError() from e
+ except CalledProcessError as e:
+ raise CheckError(e)
cmds[var] = cmd
return cmd
def run_ffmpeg(arg):
- return subprocess.check_output(ffmpeg + [arg], stderr=subprocess.STDOUT).decode('utf-8')
+ return check_output(ffmpeg + [arg], stderr=STDOUT).decode('utf-8')
def ffmpeg_check(name, regex, checks, output):
for check in checks:
@@ -92,7 +161,7 @@ if __name__ == "__main__":
stderr.write("creating Makefile.inc\n")
with open("Makefile.inc", "w") as f:
- f.write(''.join('%s := %s\n' % (k, subprocess.list2cmdline(cmds[k])) for k in cmds))
+ f.write(''.join('%s := %s\n' % (k, list2cmdline(cmds[k])) for k in cmds))
if len(warnings):
stderr.write("Warnings during configuration:\n")