Skip to content

Commit

Permalink
Ensure that correct python version is used for build - PYTHON_EXECUTA…
Browse files Browse the repository at this point in the history
…BLE (RhBug:1598988) (#1129)

* Ensure that correct python version is used for build (RhBug:1598988)
* PYTHON_DESIRED can be either "2", "3" or a path to interpreter
  • Loading branch information
m-blaha authored and dmach committed Jul 12, 2018
1 parent 49ecbb8 commit 558e2d9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
28 changes: 14 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ CMAKE_MINIMUM_REQUIRED (VERSION 2.4)

INCLUDE (${CMAKE_SOURCE_DIR}/VERSION.cmake)

if (NOT PYTHON_DESIRED)
set (PYTHON_DESIRED "2")
endif()

SET( SYSCONFDIR /etc)
SET( SYSTEMD_DIR /usr/lib/systemd/system)

if (${PYTHON_DESIRED} STREQUAL "2")
FIND_PACKAGE (PythonInterp REQUIRED)
else()
SET(Python_ADDITIONAL_VERSIONS 3.3)
FIND_PACKAGE(PythonLibs 3.0)
FIND_PACKAGE(PythonInterp 3.0 REQUIRED)
endif()
IF (NOT PYTHON_DESIRED)
FIND_PACKAGE (PythonInterp REQUIRED)
ELSEIF (${PYTHON_DESIRED} STREQUAL "2")
FIND_PACKAGE (PythonInterp 2 EXACT REQUIRED)
ELSEIF (${PYTHON_DESIRED} STREQUAL "3")
FIND_PACKAGE (PythonInterp 3 EXACT REQUIRED)
ELSEIF (EXISTS ${PYTHON_DESIRED})
SET (PYTHON_EXECUTABLE ${PYTHON_DESIRED})
FIND_PACKAGE (PythonInterp REQUIRED)
ELSE ()
MESSAGE (FATAL_ERROR "Invalid PYTHON_DESIRED value: " ${PYTHON_DESIRED})
ENDIF()

EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "from sys import stdout; from distutils import sysconfig; stdout.write(sysconfig.get_python_lib())" OUTPUT_VARIABLE PYTHON_INSTALL_DIR)
EXECUTE_PROCESS(COMMAND ${PYTHON_EXECUTABLE} -c "import sys; sys.stdout.write('%s.%s' % (sys.version_info.major, sys.version_info.minor))" OUTPUT_VARIABLE PYTHON_MAJOR_DOT_MINOR_VERSION)
MESSAGE(STATUS "Python install dir is ${PYTHON_INSTALL_DIR}")

ADD_SUBDIRECTORY (dnf)
Expand All @@ -30,8 +30,8 @@ ADD_SUBDIRECTORY (po)
ENABLE_TESTING()
ADD_SUBDIRECTORY (tests)

CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/bin/dnf.in ${CMAKE_SOURCE_DIR}/bin/dnf-${PYTHON_DESIRED} @ONLY)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/bin/dnf-automatic.in ${CMAKE_SOURCE_DIR}/bin/dnf-automatic-${PYTHON_DESIRED} @ONLY)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/bin/dnf.in ${CMAKE_SOURCE_DIR}/bin/dnf-${PYTHON_VERSION_MAJOR} @ONLY)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/bin/dnf-automatic.in ${CMAKE_SOURCE_DIR}/bin/dnf-automatic-${PYTHON_VERSION_MAJOR} @ONLY)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/dnf/const.py.in ${CMAKE_SOURCE_DIR}/dnf/const.py @ONLY)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/tests/modules/etc/dnf/repos.d/test.repo.in ${CMAKE_SOURCE_DIR}/tests/modules/etc/dnf/repos.d/test.repo @ONLY)
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/tests/modules/etc/dnf/dnf.conf.in ${CMAKE_SOURCE_DIR}/tests/modules/etc/dnf/dnf.conf @ONLY)
9 changes: 2 additions & 7 deletions bin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
if (${PYTHON_DESIRED} STREQUAL "2")
INSTALL (PROGRAMS "dnf-2" DESTINATION bin)
INSTALL (PROGRAMS "dnf-automatic-2" DESTINATION bin)
else()
INSTALL (PROGRAMS "dnf-3" DESTINATION bin)
INSTALL (PROGRAMS "dnf-automatic-3" DESTINATION bin)
endif()
INSTALL (PROGRAMS "dnf-${PYTHON_VERSION_MAJOR}" DESTINATION bin)
INSTALL (PROGRAMS "dnf-automatic-${PYTHON_VERSION_MAJOR}" DESTINATION bin)
4 changes: 2 additions & 2 deletions dnf.spec
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,15 @@ mkdir build-py3
%build
%if %{with python2}
pushd build-py2
%cmake .. -DPYTHON_DESIRED:str=2
%cmake .. -DPYTHON_DESIRED:FILEPATH=%{__python2}
%make_build
make doc-man
popd
%endif

%if %{with python3}
pushd build-py3
%cmake .. -DPYTHON_DESIRED:str=3
%cmake .. -DPYTHON_DESIRED:FILEPATH=%{__python3}
%make_build
make doc-man
popd
Expand Down

0 comments on commit 558e2d9

Please sign in to comment.