Skip to content

Commit

Permalink
Fix build-time Python configuration
Browse files Browse the repository at this point in the history
Apply various fixes and tweaks to Python configuration logic implemented
in the "configure" script:

  - Prevent PYTHON_INSTALL_DIR, which holds the value passed to the
    --with-python-install-dir option, from being set to "unspec" by
    default as this breaks installing Python modules when the
    --with-python-install-dir option is not used.

  - Make the --with-python-install-dir option also work when the Python
    interpreter is specified explicitly (using --with-python=<...>).

  - Remove dnspython dependency which was erroneously introduced in
    commit 31b0dc1: no installed Python
    module depends on dnspython, it is only used in system tests, for
    which dedicated scripts exist that check whether dnspython is
    available and act accordingly.

  - Improve contents and placement of error messages.

  - Reduce duplication of code checking Python dependencies.

  - Use Autoconf macros AS_CASE() and AS_IF() instead of plain shell
    code.

  - Update comments.  Capitalize the word "Python" when referring to the
    language itself rather than a specific executable.
  • Loading branch information
oerdnj authored and kempniu committed Nov 27, 2018
1 parent 2ecd280 commit d756024
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 300 deletions.
270 changes: 90 additions & 180 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,7 @@ Optional Packages:
--with-gnu-ld assume the C compiler uses GNU ld [default=no]
--with-sysroot[=DIR] Search for dependent libraries within DIR (or the
compiler's sysroot if not specified).
--with-python=PATH specify path to python interpreter
--with-python=PATH specify path to Python interpreter
--with-python-install-dir=PATH
installation directory for Python modules
--with-geoip=PATH Build with GeoIP support (yes|no|path)
Expand Down Expand Up @@ -12167,57 +12167,53 @@ done


#
# Python is also optional; it is used by the tools in bin/python.
# If python is unavailable, we simply don't build those.
# Python is also optional but required by default so that dnssec-keymgr gets
# installed unless explicitly prevented by the user using --without-python.
#
testminvers='import sys
if (sys.version_info < (2,7)) or (sys.version_info < (3,2) and sys.version_info >= (3,0)):
exit(1)'

testargparse='try: import argparse
except: exit(1)'

testply='try: import ply
except: exit(1)'


# Check whether --with-python was given.
if test "${with_python+set}" = set; then :
withval=$with_python; use_python="$withval"
withval=$with_python;
else
use_python="yes"
with_python="python python3 python3.7 python3.6 python3.5 python3.4 python3.3 python3.2 python2 python2.7"
fi


# Check whether --with-python-install-dir was given.
if test "${with_python_install_dir+set}" = set; then :
withval=$with_python_install_dir; use_python_install_dir="$withval"
withval=$with_python_install_dir;
else
use_python_install_dir="unspec"
with_python_install_dir=""
fi


python="python python3 python3.7 python3.6 python3.5 python3.4 python3.3 python3.2 python2 python2.7"

testargparse='try: import argparse
except: exit(1)'

testply='try: from ply import *
except: exit(1)'

testdnspython='try: import dns.message
except: exit(1)'

testminvers='import sys
if (sys.version_info < (2,7)) or (sys.version_info < (3,2) and sys.version_info >= (3,0)):
exit(1)'

case "$use_python" in
no)
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for python support" >&5
$as_echo_n "checking for python support... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: disabled" >&5
if test "$with_python" = "no"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Python support" >&5
$as_echo_n "checking for Python support... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: disabled" >&5
$as_echo "disabled" >&6; }
;;
yes|*)
case "$use_python" in
yes|'')
for p in $python
do
for ac_prog in $p
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
else
for p in $with_python
do
case $p in #(
/*) :
PYTHON="$p" ;; #(
*) :
;;
esac

# Extract the first word of "$p", so it can be a program name with args.
set dummy $p; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_path_PYTHON+:} false; then :
Expand Down Expand Up @@ -12256,166 +12252,80 @@ $as_echo "no" >&6; }
fi


test -n "$PYTHON" && break
done
# Do not cache the result of the check from the previous line. If the
# first found Python interpreter has missing module dependencies and
# the result of the above check is cached, subsequent module checks
# will erroneously keep on using the cached path to the first found
# Python interpreter instead of different ones.
unset ac_cv_path_PYTHON

if test "X$PYTHON" = "X"; then
continue;
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking python2 version >= 2.7 or python3 version >= 3.2" >&5
$as_echo_n "checking python2 version >= 2.7 or python3 version >= 3.2... " >&6; }
if ${PYTHON:-false} -c "$testminvers"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: found" >&5
$as_echo "found" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5
$as_echo "not found" >&6; }
unset ac_cv_path_PYTHON
unset PYTHON
continue
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking python module 'argparse'" >&5
$as_echo_n "checking python module 'argparse'... " >&6; }
if ${PYTHON:-false} -c "$testargparse"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: found" >&5
$as_echo "found" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5
$as_echo "not found" >&6; }
unset ac_cv_path_PYTHON
unset PYTHON
continue
fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking python module 'ply'" >&5
$as_echo_n "checking python module 'ply'... " >&6; }
if ${PYTHON:-false} -c "$testply"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: found" >&5
$as_echo "found" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5
$as_echo "not found" >&6; }
unset ac_cv_path_PYTHON
unset PYTHON
continue
fi
if test -z "$PYTHON"; then :
continue
fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking python module 'dnspython'" >&5
$as_echo_n "checking python module 'dnspython'... " >&6; }
if ${PYTHON:-false} -c "$testdnspython"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: found" >&5
$as_echo "found" >&6; }
break
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5
$as_echo "not found" >&6; }
unset ac_cv_path_PYTHON
unset PYTHON
fi
done
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for python support" >&5
$as_echo_n "checking for python support... " >&6; }
if test "X$PYTHON" != "X"
then
PYTHON_INSTALL_DIR="$use_python_install_dir"
PYTHON_INSTALL_LIB="--install-lib=$use_python_install_dir"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $PYTHON is python2 version >= 2.7 or python3 version >= 3.2" >&5
$as_echo_n "checking if $PYTHON is python2 version >= 2.7 or python3 version >= 3.2... " >&6; }
if "$PYTHON" -c "$testminvers" 2>/dev/null; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
as_fn_error $? "no; python required for dnssec-keymgr" "$LINENO" 5
fi
;;
*)
case "$use_python" in
/*)
PYTHON="$use_python"
;;
*)
for ac_prog in $use_python
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_path_PYTHON+:} false; then :
$as_echo_n "(cached) " >&6
else
case $PYTHON in
[\\/]* | ?:[\\/]*)
ac_cv_path_PYTHON="$PYTHON" # Let the user override the test with a path.
;;
*)
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_path_PYTHON="$as_dir/$ac_word$ac_exec_ext"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS

;;
esac
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
unset PYTHON
continue
fi
PYTHON=$ac_cv_path_PYTHON
if test -n "$PYTHON"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON" >&5
$as_echo "$PYTHON" >&6; }

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking Python module 'argparse'" >&5
$as_echo_n "checking Python module 'argparse'... " >&6; }
if "$PYTHON" -c "$testargparse" 2>/dev/null; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
unset PYTHON
continue
fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking Python module 'ply'" >&5
$as_echo_n "checking Python module 'ply'... " >&6; }
if "$PYTHON" -c "$testply" 2>/dev/null; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
unset PYTHON
continue
fi

test -n "$PYTHON" && break
done
# Stop looking any further once we find a Python interpreter
# satisfying all requirements.
break
done

;;
esac
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking python2 version >= 2.7 or python3 version >= 3.2" >&5
$as_echo_n "checking python2 version >= 2.7 or python3 version >= 3.2... " >&6; }
if ${PYTHON:-false} -c "$testminvers"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: found" >&5
$as_echo "found" >&6; }
else
as_fn_error $? "not found" "$LINENO" 5
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking python module 'argparse'" >&5
$as_echo_n "checking python module 'argparse'... " >&6; }
if ${PYTHON:-false} -c "$testargparse"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: found, using $PYTHON" >&5
$as_echo "found, using $PYTHON" >&6; }
else
as_fn_error $? "not found" "$LINENO" 5
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking python module 'ply'" >&5
$as_echo_n "checking python module 'ply'... " >&6; }
if ${PYTHON:-false} -c "$testply"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: found, using $PYTHON" >&5
$as_echo "found, using $PYTHON" >&6; }
else
as_fn_error $? "not found" "$LINENO" 5
fi
;;
esac
;;
esac
if test "X$PYTHON" = "X"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Python support" >&5
$as_echo_n "checking for Python support... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
as_fn_error $? "Python required for dnssec-keymgr" "$LINENO" 5
fi
fi

PYTHON_TOOLS=''
CHECKDS=''
COVERAGE=''
KEYMGR=''
if test "X$PYTHON" != "X"; then
PYTHON_TOOLS=python
CHECKDS=checkds
COVERAGE=coverage
KEYMGR=keymgr
if test "X$PYTHON" != "X"; then :
PYTHON_TOOLS=python
CHECKDS=checkds
COVERAGE=coverage
KEYMGR=keymgr
PYTHON_INSTALL_DIR="$with_python_install_dir"
if test -n "$with_python_install_dir"; then :
PYTHON_INSTALL_LIB="--install-lib=$with_python_install_dir"
fi
fi


Expand Down
Loading

0 comments on commit d756024

Please sign in to comment.