1
|
1
|
# FIND_PYTHON
|
2
|
2
|
# -----------
|
3
|
|
-# Find the version of `python` to use (for the testsuite driver)
|
|
3
|
+# Find a usable Python interpreter and enforce a minimum version.
|
|
4
|
+# Exports:
|
|
5
|
+# - PYTHON: Path to the interpreter for build/test scripts
|
|
6
|
+# - PythonCmd: Canonicalised path used by Hadrian and config files
|
|
7
|
+# - PythonVersion: Detected Python version (X.Y.Z)
|
4
|
8
|
#
|
5
|
9
|
AC_DEFUN([FIND_PYTHON],[
|
6
|
10
|
dnl Prefer the mingw64 distribution on Windows due to #17483.
|
7
|
11
|
AC_PATH_PROG([PYTHON], [python3], [], [/mingw64/bin $PATH])
|
|
12
|
+
|
|
13
|
+ dnl Fall back to "python" if python3 isn’t found (version checked below)
|
|
14
|
+ AS_IF([test -z "$PYTHON"], [
|
|
15
|
+ AC_PATH_PROG([PYTHON], [python], [], [/mingw64/bin $PATH])
|
|
16
|
+ ])
|
|
17
|
+
|
|
18
|
+ dnl If still not found, hard error: we require Python >= 3.7
|
|
19
|
+ AS_IF([test -z "$PYTHON"], [
|
|
20
|
+ AC_MSG_ERROR([Python 3.7 or later is required but no python interpreter was found. Please install Python >= 3.7 and re-run configure.])
|
|
21
|
+ ])
|
|
22
|
+
|
|
23
|
+ dnl Query the version string (X.Y.Z) of the selected interpreter
|
|
24
|
+ AC_CACHE_CHECK([for version of python], [fp_cv_python_version], [
|
|
25
|
+ changequote(, )dnl
|
|
26
|
+ fp_cv_python_version=`"$PYTHON" -c "import sys; sys.stdout.write('%d.%d.%d' % sys.version_info[:3])" 2>/dev/null`
|
|
27
|
+ changequote([, ])dnl
|
|
28
|
+ ])
|
|
29
|
+ PythonVersion=$fp_cv_python_version
|
|
30
|
+ AC_SUBST([PythonVersion])
|
|
31
|
+
|
|
32
|
+ dnl Enforce minimum version 3.7.0
|
|
33
|
+ AS_IF([test -z "$PythonVersion"], [
|
|
34
|
+ AC_MSG_ERROR([Failed to determine Python version for $PYTHON])
|
|
35
|
+ ])
|
|
36
|
+ FP_COMPARE_VERSIONS([$PythonVersion], [-lt], [3.7.0], [
|
|
37
|
+ AC_MSG_ERROR([Python 3.7 or later is required, but $PYTHON reports $PythonVersion])
|
|
38
|
+ ])
|
|
39
|
+
|
|
40
|
+ dnl Canonicalise path for Windows
|
8
|
41
|
if test "$HostOS" = "mingw32"
|
9
|
42
|
then
|
10
|
43
|
PythonCmd=$(cygpath -m "$PYTHON")
|