From: Kefu Chai Date: Thu, 18 Jul 2019 01:46:51 +0000 (+0800) Subject: cmake: pass PYTHON_VERSION explicitly X-Git-Tag: v15.1.0~2148^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=606b9c1822a1587448c5d12bff2b86e6e37b522a;p=ceph.git cmake: pass PYTHON_VERSION explicitly allow `distutils_*()` functions to choose the python according to this parameter, instead of implicitly using the variable of ${PYTHON_VERSION} inherited from the caller. Signed-off-by: Kefu Chai --- diff --git a/cmake/modules/Distutils.cmake b/cmake/modules/Distutils.cmake index 404c515c15bb..d664fa814bde 100644 --- a/cmake/modules/Distutils.cmake +++ b/cmake/modules/Distutils.cmake @@ -13,7 +13,12 @@ function(distutils_install_module name) endforeach() add_custom_target(${name}-clone ALL DEPENDS ${py_clone}) - cmake_parse_arguments(DU "" INSTALL_SCRIPT "" ${ARGN}) + cmake_parse_arguments(DU "" "INSTALL_SCRIPT;PYTHON_VERSION" "" ${ARGN}) + if(DU_PYTHON_VERSION) + set(python_version ${DU_PYTHON_VERSION}) + else() + set(python_version 3) + endif() install(CODE " set(options --prefix=${CMAKE_INSTALL_PREFIX}) if(DEFINED ENV{DESTDIR}) @@ -28,12 +33,12 @@ function(distutils_install_module name) endif() endif() execute_process( - COMMAND ${Python${PYTHON_VERSION}_EXECUTABLE} + COMMAND ${Python${python_version}_EXECUTABLE} setup.py install \${options} WORKING_DIRECTORY \"${CMAKE_CURRENT_BINARY_DIR}\")") endfunction(distutils_install_module) -function(distutils_add_cython_module target name src) +function(distutils_add_cython_module target name src python_version) get_property(compiler_launcher GLOBAL PROPERTY RULE_LAUNCH_COMPILE) get_property(link_launcher GLOBAL PROPERTY RULE_LAUNCH_LINK) # When using ccache, CMAKE_C_COMPILER is ccache executable absolute path @@ -57,12 +62,12 @@ function(distutils_add_cython_module target name src) set(PY_CXX ${compiler_launcher} ${CMAKE_CXX_COMPILER} ${cxx_compiler_arg1}) set(PY_LDSHARED ${link_launcher} ${CMAKE_C_COMPILER} ${c_compiler_arg1} "-shared") - if(${Python${PYTHON_VERSION}_VERSION_MAJOR} STREQUAL "2") + if(${Python${python_version}_VERSION_MAJOR} STREQUAL "2") set(suffix_var "SO") else() set(suffix_var "EXT_SUFFIX") endif() - execute_process(COMMAND "${Python${PYTHON_VERSION}_EXECUTABLE}" -c + execute_process(COMMAND "${Python${python_version}_EXECUTABLE}" -c "from distutils import sysconfig; print(sysconfig.get_config_var('${suffix_var}'))" RESULT_VARIABLE result OUTPUT_VARIABLE ext_suffix @@ -71,7 +76,7 @@ function(distutils_add_cython_module target name src) if(NOT result EQUAL 0) message(FATAL_ERROR "Unable to tell python extension's suffix: ${error}") endif() - set(output_dir "${CYTHON_MODULE_DIR}/lib.${Python${PYTHON_VERSION}_VERSION_MAJOR}") + set(output_dir "${CYTHON_MODULE_DIR}/lib.${Python${python_version}_VERSION_MAJOR}") set(setup_py ${CMAKE_CURRENT_SOURCE_DIR}/setup.py) add_custom_command( OUTPUT ${output_dir}/${name}${ext_suffix} @@ -84,7 +89,7 @@ function(distutils_add_cython_module target name src) LDFLAGS=-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY} CYTHON_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR} CEPH_LIBDIR=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} - ${Python${PYTHON_VERSION}_EXECUTABLE} ${setup_py} + ${Python${python_version}_EXECUTABLE} ${setup_py} build --verbose --build-base ${CYTHON_MODULE_DIR} --build-platlib ${output_dir} MAIN_DEPENDENCY ${src} @@ -94,7 +99,7 @@ function(distutils_add_cython_module target name src) DEPENDS ${output_dir}/${name}${ext_suffix}) endfunction(distutils_add_cython_module) -function(distutils_install_cython_module name) +function(distutils_install_cython_module name python_version) get_property(compiler_launcher GLOBAL PROPERTY RULE_LAUNCH_COMPILE) get_property(link_launcher GLOBAL PROPERTY RULE_LAUNCH_LINK) set(PY_CC "${compiler_launcher} ${CMAKE_C_COMPILER}") @@ -120,9 +125,9 @@ function(distutils_install_cython_module name) endif() execute_process( COMMAND - ${Python${PYTHON_VERSION}_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/setup.py + ${Python${python_version}_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/setup.py build --verbose --build-base ${CYTHON_MODULE_DIR} - --build-platlib ${CYTHON_MODULE_DIR}/lib.${Python${PYTHON_VERSION}_VERSION_MAJOR} + --build-platlib ${CYTHON_MODULE_DIR}/lib.${Python${python_version}_VERSION_MAJOR} build_ext --cython-c-in-temp --build-temp ${CMAKE_CURRENT_BINARY_DIR} --cython-include-dirs ${PROJECT_SOURCE_DIR}/src/pybind/rados install \${options} --single-version-externally-managed --record /dev/null egg_info --egg-base ${CMAKE_CURRENT_BINARY_DIR} diff --git a/src/ceph-volume/CMakeLists.txt b/src/ceph-volume/CMakeLists.txt index 5a9eb2ed064e..d1217a915c85 100644 --- a/src/ceph-volume/CMakeLists.txt +++ b/src/ceph-volume/CMakeLists.txt @@ -1,7 +1,15 @@ include(Distutils) + +if(WITH_PYTHON2) + set(python_version_major 2) +else() + set(python_version_major 3) +endif() + distutils_install_module(ceph_volume - INSTALL_SCRIPT ${CMAKE_INSTALL_FULL_SBINDIR}) + INSTALL_SCRIPT ${CMAKE_INSTALL_FULL_SBINDIR} + PYTHON_VERSION ${python_version_major}) if(FREEBSD) add_subdirectory(plugin/zfs) diff --git a/src/ceph-volume/plugin/zfs/CMakeLists.txt b/src/ceph-volume/plugin/zfs/CMakeLists.txt index da10f46fd09a..cafb7382e77a 100644 --- a/src/ceph-volume/plugin/zfs/CMakeLists.txt +++ b/src/ceph-volume/plugin/zfs/CMakeLists.txt @@ -1,3 +1,4 @@ distutils_install_module(ceph_volume_zfs - INSTALL_SCRIPT ${CMAKE_INSTALL_FULL_SBINDIR}) + INSTALL_SCRIPT ${CMAKE_INSTALL_FULL_SBINDIR} + PYTHON_VERSION ${python_version}) diff --git a/src/pybind/cephfs/CMakeLists.txt b/src/pybind/cephfs/CMakeLists.txt index 380ec21fc070..61cf8b4a9ff3 100644 --- a/src/pybind/cephfs/CMakeLists.txt +++ b/src/pybind/cephfs/CMakeLists.txt @@ -1,5 +1,7 @@ distutils_add_cython_module(cython${PYTHON_VERSION}_cephfs cephfs - ${CMAKE_CURRENT_SOURCE_DIR}/cephfs.pyx) + ${CMAKE_CURRENT_SOURCE_DIR}/cephfs.pyx + ${PYTHON_VERSION}) add_dependencies(cython${PYTHON_VERSION}_cephfs cephfs) -distutils_install_cython_module(cython${PYTHON_VERSION}_cephfs) +distutils_install_cython_module(cython${PYTHON_VERSION}_cephfs + ${PYTHON_VERSION}) diff --git a/src/pybind/rados/CMakeLists.txt b/src/pybind/rados/CMakeLists.txt index a8ed22550f96..b16d3513b55b 100644 --- a/src/pybind/rados/CMakeLists.txt +++ b/src/pybind/rados/CMakeLists.txt @@ -1,5 +1,7 @@ distutils_add_cython_module(cython${PYTHON_VERSION}_rados rados - ${CMAKE_CURRENT_SOURCE_DIR}/rados.pyx) + ${CMAKE_CURRENT_SOURCE_DIR}/rados.pyx + ${PYTHON_VERSION}) add_dependencies(cython${PYTHON_VERSION}_rados rados) -distutils_install_cython_module(cython${PYTHON_VERSION}_rados) +distutils_install_cython_module(cython${PYTHON_VERSION}_rados + ${PYTHON_VERSION}) diff --git a/src/pybind/rbd/CMakeLists.txt b/src/pybind/rbd/CMakeLists.txt index 4920e0ff1eee..f7d3bb4deb96 100644 --- a/src/pybind/rbd/CMakeLists.txt +++ b/src/pybind/rbd/CMakeLists.txt @@ -1,5 +1,7 @@ distutils_add_cython_module(cython${PYTHON_VERSION}_rbd rbd - ${CMAKE_CURRENT_SOURCE_DIR}/rbd.pyx) + ${CMAKE_CURRENT_SOURCE_DIR}/rbd.pyx + ${PYTHON_VERSION}) add_dependencies(cython${PYTHON_VERSION}_rbd librbd) -distutils_install_cython_module(cython${PYTHON_VERSION}_rbd) +distutils_install_cython_module(cython${PYTHON_VERSION}_rbd + ${PYTHON_VERSION}) diff --git a/src/pybind/rgw/CMakeLists.txt b/src/pybind/rgw/CMakeLists.txt index 811af61288dd..2c8309cdd351 100644 --- a/src/pybind/rgw/CMakeLists.txt +++ b/src/pybind/rgw/CMakeLists.txt @@ -1,5 +1,7 @@ distutils_add_cython_module(cython${PYTHON_VERSION}_rgw rgw - ${CMAKE_CURRENT_SOURCE_DIR}/rgw.pyx) + ${CMAKE_CURRENT_SOURCE_DIR}/rgw.pyx + ${PYTHON_VERSION}) add_dependencies(cython${PYTHON_VERSION}_rgw rgw) -distutils_install_cython_module(cython${PYTHON_VERSION}_rgw) +distutils_install_cython_module(cython${PYTHON_VERSION}_rgw + ${PYTHON_VERSION}) diff --git a/src/tools/cephfs/CMakeLists.txt b/src/tools/cephfs/CMakeLists.txt index 2cca8dc034c8..6ffa26628f1a 100644 --- a/src/tools/cephfs/CMakeLists.txt +++ b/src/tools/cephfs/CMakeLists.txt @@ -43,7 +43,7 @@ if(WITH_CEPHFS_SHELL) if(NOT WITH_PYTHON3) message(SEND_ERROR "Please enable WITH_PYTHON3 for cephfs-shell") endif() - set(PYTHON_VERSION 3) include(Distutils) - distutils_install_module(cephfs-shell) + distutils_install_module(cephfs-shell + PYTHON_VERSION 3) endif()