Skip to content

Commit

Permalink
Cherokee may use wrong Python interpreter
Browse files Browse the repository at this point in the history
On modern systems Python3 is now standard. Cherokee has been prepared for this
change. Users can use option --with-python to specify the correct path to
Python2 but some Makefiles ignore this directive (e. g. make test). Furthermore,
Python byte code files that are created during build process are not removed
by the clean target of some Makefiles.

This patch configures Autoconf to detect the correct path to a Python2
interpreter. Autoconf will terminate the build process with error if a Python2
interpreter cannot be found. This is required as Python is also used to compile
Cherokee's error header file.

Python byte code files are no cleaned by make clean.

Fixes: cherokee#1250

Signed-off-by: Thomas Reim <[email protected]>
  • Loading branch information
thor-sssd authored and skinkie committed Oct 22, 2021
1 parent e4d9675 commit c129fee
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 18 deletions.
5 changes: 4 additions & 1 deletion admin/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,7 @@ CLEANFILES = \
$(generated_DATA)

test:
python -m compileall .
$(PYTHON) -m compileall .

clean-local:
find . -type f -name "*.pyc" -exec rm -f {} \;
4 changes: 4 additions & 0 deletions cherokee/main_admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,11 @@ check_for_python (void)
int re;
pid_t pid;
int exitcode = -1;
#ifdef PATH_PYTHON2
char const *args[] = {"env", PATH_PYTHON2, "-c", "raise SystemExit", NULL};
#else
char const *args[] = {"env", "python2", "-c", "raise SystemExit", NULL};
#endif

pid = fork();
if (pid == -1) {
Expand Down
30 changes: 19 additions & 11 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1334,30 +1334,38 @@ have_python="yes"
AC_ARG_WITH([python], AS_HELP_STRING([--with-python=/path/to/python],[Path to Python interpreter]),
PYTHON="$withval",
[
AC_PATH_PROGS(PYTHON, python python2 python2.7 python2.6 python2.5 python2.4)
])
AC_CACHE_VAL([ac_cv_path_PYTHON],
[AC_PATH_PROGS_FEATURE_CHECK([PYTHON], [python2.4 python2.5 python2.6 python2.7 python2 python],
[v=$($ac_path_PYTHON -c "import sys; print (sys.version_info[[0]])")
if test "x$v" == "x2"; then
ac_cv_path_PYTHON=$ac_path_PYTHON aac_path_PYTHON_found=:
fi])])
if test "x$ac_cv_path_PYTHON" != "x"; then
AC_SUBST(PYTHON, [$ac_cv_path_PYTHON])
fi
]
)

if test "x$PYTHON" != "x"; then
AC_MSG_CHECKING([Python 2.x interpreter])
AC_MSG_CHECKING([for Python 2.x interpreter])
v=`$PYTHON -c 'import sys; print (sys.version_info[[0]])'`
if test "x$v" != "x2"; then
have_python="no"
wants_admin="no"
AC_MSG_RESULT([no])
AC_MSG_WARN([
*** Cherokee-admin requires Python 2.x. Please, use the --with-python
*** parameter to specify a Python 2.4, 2.5, 2.6 or 2.7 interpreter.
*** BEWARE: Cherokee-admin support has been disabled.])
AC_MSG_ERROR([
*** Cherokee requires Python 2.x. Please, use the --with-python
*** parameter to specify a Python 2.4, 2.5, 2.6 or 2.7 interpreter.])
else
AC_MSG_RESULT([yes])
AC_MSG_RESULT([$PYTHON])
AC_DEFINE_UNQUOTED(PATH_PYTHON2, ["$PYTHON"], [Define path to Python 2.x interpreter])
fi
else
have_python="no"
wants_admin="no"
AC_MSG_WARN([
AC_MSG_ERROR([
*** Python must be installed on your system but python interpreter couldn't
*** be found in path. Please check that python is in path, or install it.
*** BEWARE: Cherokee-admin support has been disabled.])
*** be found in path. Please check that python is in path, or install it.])
fi

dnl
Expand Down
11 changes: 7 additions & 4 deletions qa/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SUFFIXES = .py.pre .py

.py.pre.py:
sed -e "s|%sysconfdir%|${sysconfdir}|g; s|%sbindir%|${sbindir}|g; s|%docdir%|${docdir}|g; s|%prefix%|${prefix}|g; s|%localstatedir%|${localstatedir}|g; s|%libdir%|${libdir}|g; s|%wwwroot%|${WWW_ROOT}|g; s|%cgiroot%|${CGI_ROOT}|g; s|%version%|${PACKAGE_VERSION}|g; s|%phpcgi%|${PHPCGI}|g; s|%datadir%|${datadir}|g; s|%localedir%|${localedir}|g" $< > $@
sed -e "s|%sysconfdir%|${sysconfdir}|g; s|%sbindir%|${sbindir}|g; s|%docdir%|${docdir}|g; s|%prefix%|${prefix}|g; s|%localstatedir%|${localstatedir}|g; s|%libdir%|${libdir}|g; s|%wwwroot%|${WWW_ROOT}|g; s|%cgiroot%|${CGI_ROOT}|g; s|%version%|${PACKAGE_VERSION}|g; s|%pythonpath%|${PYTHON}|g; s|%phpcgi%|${PHPCGI}|g; s|%datadir%|${datadir}|g; s|%localedir%|${localedir}|g" $< > $@

PY_PRE = \
conf.py.pre
Expand Down Expand Up @@ -340,7 +340,7 @@ ssl-keys/set-1.key:
mkdir -p ssl-keys
@OPENSSL_BIN@ genrsa -out ssl-keys/set-1.key 2048
test-ssl: ssl-keys/set-1.pem
./run-tests.py -s
$(PYTHON) ./run-tests.py -s
test: test-non-ssl test-ssl

DISTCLEANFILES += ssl-keys/set-1.pem ssl-keys/set-1.key
Expand All @@ -350,5 +350,8 @@ test: test-non-ssl
endif

test-non-ssl:
python -m compileall .
./run-tests.py
$(PYTHON) -m compileall .
$(PYTHON) ./run-tests.py

clean-local:
find . -type f -name "*.pyc" -exec rm -f {} \;
2 changes: 1 addition & 1 deletion qa/conf.py.pre
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SSL_CERT_KEY_FILE = "ssl-keys/set-1.key"
SERVER_DELAY = 10

# Third party utilities
PYTHON_PATH = "auto"
PYTHON_PATH = "%pythonpath%"
PHPCGI_PATH = "%phpcgi%"
PHP_FCGI_PORT = 1980

Expand Down
2 changes: 1 addition & 1 deletion qa/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def look_for_python():
if __python_ref != None:
return __python_ref

if PYTHON_PATH != "auto":
if PYTHON_PATH != "%pythonpath%":
__python_ref = PYTHON_PATH
return __python_ref

Expand Down

0 comments on commit c129fee

Please sign in to comment.