Skip to content

Commit 558e2d9

Browse files
m-blahadmach
authored andcommitted
Ensure that correct python version is used for build - PYTHON_EXECUTABLE (RhBug:1598988) (rpm-software-management#1129)
* Ensure that correct python version is used for build (RhBug:1598988) * PYTHON_DESIRED can be either "2", "3" or a path to interpreter
1 parent 49ecbb8 commit 558e2d9

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

CMakeLists.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ CMAKE_MINIMUM_REQUIRED (VERSION 2.4)
33

44
INCLUDE (${CMAKE_SOURCE_DIR}/VERSION.cmake)
55

6-
if (NOT PYTHON_DESIRED)
7-
set (PYTHON_DESIRED "2")
8-
endif()
9-
106
SET( SYSCONFDIR /etc)
117
SET( SYSTEMD_DIR /usr/lib/systemd/system)
128

13-
if (${PYTHON_DESIRED} STREQUAL "2")
14-
FIND_PACKAGE (PythonInterp REQUIRED)
15-
else()
16-
SET(Python_ADDITIONAL_VERSIONS 3.3)
17-
FIND_PACKAGE(PythonLibs 3.0)
18-
FIND_PACKAGE(PythonInterp 3.0 REQUIRED)
19-
endif()
9+
IF (NOT PYTHON_DESIRED)
10+
FIND_PACKAGE (PythonInterp REQUIRED)
11+
ELSEIF (${PYTHON_DESIRED} STREQUAL "2")
12+
FIND_PACKAGE (PythonInterp 2 EXACT REQUIRED)
13+
ELSEIF (${PYTHON_DESIRED} STREQUAL "3")
14+
FIND_PACKAGE (PythonInterp 3 EXACT REQUIRED)
15+
ELSEIF (EXISTS ${PYTHON_DESIRED})
16+
SET (PYTHON_EXECUTABLE ${PYTHON_DESIRED})
17+
FIND_PACKAGE (PythonInterp REQUIRED)
18+
ELSE ()
19+
MESSAGE (FATAL_ERROR "Invalid PYTHON_DESIRED value: " ${PYTHON_DESIRED})
20+
ENDIF()
2021

2122
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)
22-
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)
2323
MESSAGE(STATUS "Python install dir is ${PYTHON_INSTALL_DIR}")
2424

2525
ADD_SUBDIRECTORY (dnf)
@@ -30,8 +30,8 @@ ADD_SUBDIRECTORY (po)
3030
ENABLE_TESTING()
3131
ADD_SUBDIRECTORY (tests)
3232

33-
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/bin/dnf.in ${CMAKE_SOURCE_DIR}/bin/dnf-${PYTHON_DESIRED} @ONLY)
34-
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/bin/dnf-automatic.in ${CMAKE_SOURCE_DIR}/bin/dnf-automatic-${PYTHON_DESIRED} @ONLY)
33+
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/bin/dnf.in ${CMAKE_SOURCE_DIR}/bin/dnf-${PYTHON_VERSION_MAJOR} @ONLY)
34+
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/bin/dnf-automatic.in ${CMAKE_SOURCE_DIR}/bin/dnf-automatic-${PYTHON_VERSION_MAJOR} @ONLY)
3535
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/dnf/const.py.in ${CMAKE_SOURCE_DIR}/dnf/const.py @ONLY)
3636
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)
3737
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/tests/modules/etc/dnf/dnf.conf.in ${CMAKE_SOURCE_DIR}/tests/modules/etc/dnf/dnf.conf @ONLY)

bin/CMakeLists.txt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
1-
if (${PYTHON_DESIRED} STREQUAL "2")
2-
INSTALL (PROGRAMS "dnf-2" DESTINATION bin)
3-
INSTALL (PROGRAMS "dnf-automatic-2" DESTINATION bin)
4-
else()
5-
INSTALL (PROGRAMS "dnf-3" DESTINATION bin)
6-
INSTALL (PROGRAMS "dnf-automatic-3" DESTINATION bin)
7-
endif()
1+
INSTALL (PROGRAMS "dnf-${PYTHON_VERSION_MAJOR}" DESTINATION bin)
2+
INSTALL (PROGRAMS "dnf-automatic-${PYTHON_VERSION_MAJOR}" DESTINATION bin)

dnf.spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,15 @@ mkdir build-py3
275275
%build
276276
%if %{with python2}
277277
pushd build-py2
278-
%cmake .. -DPYTHON_DESIRED:str=2
278+
%cmake .. -DPYTHON_DESIRED:FILEPATH=%{__python2}
279279
%make_build
280280
make doc-man
281281
popd
282282
%endif
283283

284284
%if %{with python3}
285285
pushd build-py3
286-
%cmake .. -DPYTHON_DESIRED:str=3
286+
%cmake .. -DPYTHON_DESIRED:FILEPATH=%{__python3}
287287
%make_build
288288
make doc-man
289289
popd

0 commit comments

Comments
 (0)