Skip to content

Commit

Permalink
cmake: drop WITH_PYTHON2 option
Browse files Browse the repository at this point in the history
* drop WITH_PYTHON2 option
* print warning message if WITH_PYTHON3 is disabled
* drop MGR_PYTHON_VERSION option, as we don't support use different
  python version for python binding and ceph-mgr embedded python
  interpreter anymore. as before switching to python3-only build,
  we can build python3 and python2 python bindings, and ceph-mgr
  can use either of them. but after switching to python3-only
  build, ceph-mgr has to use whatever python version used to
  build python binding.
* move WITH_PYTHON3 option to $top_srcdir/CMakeLists.txt, as ceph-mgr
  and python binding will share this option.
* hardware ${PYTHON_VERSION} to 3
* hardware ${Python${PYTHON_VERSION}_VERSION_MAJOR} to 3
* only build boost library with python3
* s/Python_EXECUTABLE/Python3_EXECUTABLE/
* update the build scripts and packagings accordingly
* rename all cython${PYTHON_VERSION}_* targets to cython_*
* update distutils_install_module() so it does not take python_version
  parameter anymore.

Signed-off-by: Kefu Chai <kchai@redhat.com>
  • Loading branch information
tchaikov committed Dec 19, 2019
1 parent 47d0e1e commit 5fc657b
Show file tree
Hide file tree
Showing 23 changed files with 101 additions and 194 deletions.
33 changes: 18 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -418,23 +418,26 @@ endif (WITH_RADOSGW)
#option for CephFS
option(WITH_CEPHFS "CephFS is enabled" ON)

#option for Mgr
# Please specify 3.[0-7] if you want to build with a certain version of python3.
set(WITH_PYTHON3 "3" CACHE STRING "build with specified python3 version")
if(NOT WITH_PYTHON3)
message(FATAL_ERROR "WITH_PYTHON3 should always be enabled")
elseif(WITH_PYTHON3 MATCHES "^(1|ON|YES|TRUE|Y)$")
set(WITH_PYTHON3 "3")
message(NOTICE "Please specify a Python3 version instead of a BOOLEAN")
elseif(NOT WITH_PYTHON3 STREQUAL "3")
set(find_python3_exact "EXACT")
endif()
find_package(Python3 ${WITH_PYTHON3} ${find_python3_exact} REQUIRED
COMPONENTS Interpreter Development)
unset(find_python3_exact)

option(WITH_MGR "ceph-mgr is enabled" ON)
if(WITH_MGR)
# Please specify 3 or 3.[0-7] if you want to build with python3 support.
# FindPython thinks they belong to different families.
set(MGR_PYTHON_VERSION "2.7" CACHE
STRING "required version of python runtime for running mgr plugins. ")
if(NOT MGR_PYTHON_VERSION MATCHES "^[23]$")
set(find_python_exact "EXACT")
endif()
find_package(Python ${MGR_PYTHON_VERSION} ${find_python_exact} REQUIRED
COMPONENTS Interpreter Development)
unset(find_python_exact)
set(MGR_PYTHON_EXECUTABLE ${Python_EXECUTABLE})
set(MGR_PYTHON_LIBRARIES ${Python_LIBRARIES})
set(MGR_PYTHON_VERSION_MAJOR ${Python_VERSION_MAJOR})
set(MGR_PYTHON_VERSION_MINOR ${Python_VERSION_MINOR})
set(MGR_PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
set(MGR_PYTHON_LIBRARIES ${Python3_LIBRARIES})
set(MGR_PYTHON_VERSION_MAJOR ${Python3_VERSION_MAJOR})
set(MGR_PYTHON_VERSION_MINOR ${Python3_VERSION_MINOR})
# Boost dependency check deferred to Boost section
endif(WITH_MGR)

Expand Down
2 changes: 0 additions & 2 deletions ceph.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -1128,8 +1128,6 @@ ${CMAKE} .. \
-DWITH_MANPAGE=ON \
-DWITH_PYTHON3=%{python3_version} \
-DWITH_MGR_DASHBOARD_FRONTEND=OFF \
-DWITH_PYTHON2=OFF \
-DMGR_PYTHON_VERSION=3 \
%if 0%{without ceph_test_package}
-DWITH_TESTS=OFF \
%endif
Expand Down
11 changes: 3 additions & 8 deletions cmake/modules/AddCephTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if(WITH_GTEST_PARALLEL)
add_dependencies(tests gtest-parallel_ext)
find_package(Python REQUIRED)
set(GTEST_PARALLEL_COMMAND
${Python_EXECUTABLE} ${gtest_parallel_source_dir}/gtest-parallel)
${Python3_EXECUTABLE} ${gtest_parallel_source_dir}/gtest-parallel)
endif()
endif()

Expand All @@ -62,20 +62,15 @@ function(add_tox_test name)
else()
set(tox_path ${CMAKE_CURRENT_SOURCE_DIR})
endif()
if(WITH_PYTHON2)
list(APPEND tox_envs py27)
endif()
if(WITH_PYTHON3)
list(APPEND tox_envs py3)
endif()
list(APPEND tox_envs py3)
if(DEFINED TOXTEST_TOX_ENVS)
list(APPEND tox_envs ${TOXTEST_TOX_ENVS})
endif()
string(REPLACE ";" "," tox_envs "${tox_envs}")
find_package(Python REQUIRED)
add_custom_command(
OUTPUT ${venv_path}/bin/activate
COMMAND ${CMAKE_SOURCE_DIR}/src/tools/setup-virtualenv.sh --python="${Python_EXECUTABLE}" ${venv_path}
COMMAND ${CMAKE_SOURCE_DIR}/src/tools/setup-virtualenv.sh --python="${Python3_EXECUTABLE}" ${venv_path}
WORKING_DIRECTORY ${tox_path}
COMMENT "preparing venv for ${name}")
add_custom_target(${name}-venv
Expand Down
10 changes: 5 additions & 5 deletions cmake/modules/BuildBoost.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ function(do_build_boost version)
" : ${CMAKE_CXX_COMPILER}"
" ;\n")
if(with_python_version)
find_package(Python ${with_python_version} QUIET REQUIRED
find_package(Python3 ${with_python_version} QUIET REQUIRED
COMPONENTS Development)
string(REPLACE ";" " " python_includes "${Python_INCLUDE_DIRS}")
string(REPLACE ";" " " python3_includes "${Python3_INCLUDE_DIRS}")
file(APPEND ${user_config}
"using python"
" : ${with_python_version}"
" : ${Python_EXECUTABLE}"
" : ${python_includes}"
" : ${Python_LIBRARIES}"
" : ${Python3_EXECUTABLE}"
" : ${python3_includes}"
" : ${Python3_LIBRARIES}"
" ;\n")
endif()
list(APPEND b2 --user-config=${user_config})
Expand Down
25 changes: 8 additions & 17 deletions cmake/modules/Distutils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ function(distutils_install_module name)
add_custom_target(${name}-clone ALL
DEPENDS ${py_clone})
endif()
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()
cmake_parse_arguments(DU "" "INSTALL_SCRIPT" "" ${ARGN})
install(CODE "
set(options --prefix=${CMAKE_INSTALL_PREFIX})
if(DEFINED ENV{DESTDIR})
Expand All @@ -35,12 +30,12 @@ function(distutils_install_module name)
endif()
endif()
execute_process(
COMMAND ${Python${python_version}_EXECUTABLE}
COMMAND ${Python3_EXECUTABLE}
setup.py install \${options}
WORKING_DIRECTORY \"${CMAKE_CURRENT_BINARY_DIR}\")")
endfunction(distutils_install_module)

function(distutils_add_cython_module target name src python_version)
function(distutils_add_cython_module target name src)
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
Expand All @@ -64,12 +59,8 @@ function(distutils_add_cython_module target name src python_version)
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")
set(suffix_var "SO")
else()
set(suffix_var "EXT_SUFFIX")
endif()
execute_process(COMMAND "${Python${python_version}_EXECUTABLE}" -c
set(suffix_var "EXT_SUFFIX")
execute_process(COMMAND "${Python3_EXECUTABLE}" -c
"from distutils import sysconfig; print(sysconfig.get_config_var('${suffix_var}'))"
RESULT_VARIABLE result
OUTPUT_VARIABLE ext_suffix
Expand All @@ -91,7 +82,7 @@ function(distutils_add_cython_module target name src python_version)
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}
${Python3_EXECUTABLE} ${setup_py}
build --verbose --build-base ${CYTHON_MODULE_DIR}
--build-platlib ${output_dir}
MAIN_DEPENDENCY ${src}
Expand All @@ -101,7 +92,7 @@ function(distutils_add_cython_module target name src python_version)
DEPENDS ${output_dir}/${name}${ext_suffix})
endfunction(distutils_add_cython_module)

function(distutils_install_cython_module name python_version)
function(distutils_install_cython_module name)
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}")
Expand All @@ -127,7 +118,7 @@ function(distutils_install_cython_module name python_version)
endif()
execute_process(
COMMAND
${Python${python_version}_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/setup.py
${Python3_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_ext --cython-c-in-temp --build-temp ${CMAKE_CURRENT_BINARY_DIR} --cython-include-dirs ${PROJECT_SOURCE_DIR}/src/pybind/rados
Expand Down
2 changes: 1 addition & 1 deletion cmake/modules/FindCython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Try to run Cython, to make sure it works:
execute_process(
COMMAND ${Python${PYTHON_VERSION}_EXECUTABLE} -m cython --version
COMMAND ${Python3_EXECUTABLE} -m cython --version
RESULT_VARIABLE cython_result
ERROR_VARIABLE cython_output)
if(cython_result EQUAL 0)
Expand Down
2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ endif

extraopts += -DWITH_OCF=ON -DWITH_LTTNG=ON
extraopts += -DWITH_MGR_DASHBOARD_FRONTEND=OFF
extraopts += -DWITH_PYTHON3=3 -DWITH_PYTHON2=OFF -DMGR_PYTHON_VERSION=3
extraopts += -DWITH_PYTHON3=3
extraopts += -DWITH_CEPHFS_JAVA=ON
extraopts += -DWITH_CEPHFS_SHELL=ON
extraopts += -DWITH_SYSTEMD=ON -DCEPH_SYSTEMD_ENV_DIR=/etc/default
Expand Down
2 changes: 1 addition & 1 deletion do_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ else
fi

if [[ "$PYBUILD" =~ ^3(\..*)?$ ]] ; then
ARGS+=" -DWITH_PYTHON2=OFF -DWITH_PYTHON3=${PYBUILD} -DMGR_PYTHON_VERSION=${PYBUILD}"
ARGS+=" -DWITH_PYTHON3=${PYBUILD}"
fi

if type ccache > /dev/null 2>&1 ; then
Expand Down
2 changes: 1 addition & 1 deletion run-make-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function main() {
fi
FOR_MAKE_CHECK=1 prepare
# Init defaults after deps are installed.
configure "-DWITH_GTEST_PARALLEL=ON -DWITH_FIO=ON -DWITH_SEASTAR=ON -DWITH_CEPHFS_SHELL=ON -DWITH_SPDK=ON -DENABLE_GIT_VERSION=OFF $@"
configure " -DWITH_PYTHON3=3 -DWITH_GTEST_PARALLEL=ON -DWITH_FIO=ON -DWITH_SEASTAR=ON -DWITH_CEPHFS_SHELL=ON -DWITH_SPDK=ON -DENABLE_GIT_VERSION=OFF $@"
build tests && echo "make check: successful run on $(git rev-parse HEAD)"
run
}
Expand Down
47 changes: 7 additions & 40 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,42 +218,9 @@ if(WITH_CEPHFS_JAVA)
endif()

# Python stuff
option(WITH_PYTHON2 "build python2 bindings" ON)
option(WITH_PYTHON2 "build python2 bindings" OFF)
if(WITH_PYTHON2)
find_package(Python2 REQUIRED
COMPONENTS Interpreter Development)
endif()

set(WITH_PYTHON3 "OFF" CACHE STRING "build python3 bindings with specified python3 version")
if(WITH_PYTHON3)
if(WITH_PYTHON3 MATCHES "^(1|ON|YES|TRUE|Y)$")
set(WITH_PYTHON3 "3")
endif()
if(NOT WITH_PYTHON3 STREQUAL "3")
set(find_python3_exact "EXACT")
endif()
find_package(Python3 ${WITH_PYTHON3} ${find_python3_exact} REQUIRED
COMPONENTS Interpreter Development)
unset(find_python3_exact)
endif()

# the major version of the python bindings as a dependency of other
# targets
if(WITH_PYTHON2)
set(PY_BINDING_INFIX 2)
else()
set(PY_BINDING_INFIX 3)
endif()
# use python2 by default for python bindings, tools and tests, before
# switching to python3
# Python_EXECUTABLE` can be set by `find_package(Python ...)` also. and we do
# call `find_package(Python ...)` in `ceph/CMakeLists.txt`. but we do so before
# `add_subdirectory(src)` where `Python_EXECUTABLE` is set. so it's safe to
# use this variable name and call `find_package(Python ...)`.
if(WITH_PYTHON2)
set(Python_EXECUTABLE ${Python2_EXECUTABLE})
else()
set(Python_EXECUTABLE ${Python3_EXECUTABLE})
message(FATAL_ERROR "Python 2 is not supported anymore")
endif()

# sort out which allocator to use
Expand Down Expand Up @@ -787,17 +754,17 @@ add_custom_target(vstart-base DEPENDS
monmaptool
crushtool
rados
cython${PY_BINDING_INFIX}_rados)
cython_rados)
if (WITH_MGR)
add_dependencies(vstart-base ceph-mgr)
endif()

add_custom_target(vstart DEPENDS vstart-base)
if (WITH_RBD)
add_dependencies(vstart cython${PY_BINDING_INFIX}_rbd)
if(WITH_RBD)
add_dependencies(vstart cython_rbd)
endif()
if (WITH_CEPHFS)
add_dependencies(vstart ceph-mds cephfs cython${PY_BINDING_INFIX}_cephfs)
add_dependencies(vstart ceph-mds cephfs cython_cephfs)
endif()
if(WITH_RADOSGW)
add_dependencies(vstart radosgw radosgw-admin)
Expand All @@ -819,7 +786,7 @@ endif()
add_custom_target(cephfs_testing DEPENDS
vstart
rados
cython${PY_BINDING_INFIX}_modules
cython_modules
cephfs
cls_cephfs
ceph-fuse
Expand Down
2 changes: 1 addition & 1 deletion src/ceph-crash.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!@Python_EXECUTABLE@
#!@Python3_EXECUTABLE@
# -*- mode:python -*-
# vim: ts=4 sw=4 smarttab expandtab

Expand Down
9 changes: 1 addition & 8 deletions src/ceph-volume/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@

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}
PYTHON_VERSION ${python_version_major})
INSTALL_SCRIPT ${CMAKE_INSTALL_FULL_SBINDIR})

if(FREEBSD)
add_subdirectory(plugin/zfs)
Expand Down
3 changes: 1 addition & 2 deletions src/ceph-volume/plugin/zfs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

distutils_install_module(ceph_volume_zfs
INSTALL_SCRIPT ${CMAKE_INSTALL_FULL_SBINDIR}
PYTHON_VERSION ${python_version})
INSTALL_SCRIPT ${CMAKE_INSTALL_FULL_SBINDIR})
4 changes: 2 additions & 2 deletions src/ceph.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!@Python_EXECUTABLE@
#!@Python3_EXECUTABLE@
# -*- mode:python -*-
# vim: ts=4 sw=4 smarttab expandtab
#
Expand Down Expand Up @@ -66,7 +66,7 @@ DEVMODEMSG = '*** DEVELOPER MODE: setting PATH, PYTHONPATH and LD_LIBRARY_PATH *
def respawn_in_path(lib_path, pybind_path, pythonlib_path, asan_lib_path):
execv_cmd = []
if 'CEPH_DBG' in os.environ:
execv_cmd += ['@Python_EXECUTABLE@', '-mpdb']
execv_cmd += ['@Python3_EXECUTABLE@', '-mpdb']

if platform.system() == "Darwin":
lib_path_var = "DYLD_LIBRARY_PATH"
Expand Down
3 changes: 1 addition & 2 deletions src/mgr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ if(WITH_MGR)
mgr_commands.cc
$<TARGET_OBJECTS:mgr_cap_obj>)
add_executable(ceph-mgr ${mgr_srcs})
target_include_directories(ceph-mgr SYSTEM PRIVATE "${Python_INCLUDE_DIRS}")
target_link_libraries(ceph-mgr
osdc client heap_profiler
global-static ceph-common
Boost::python${MGR_PYTHON_VERSION_MAJOR}${MGR_PYTHON_VERSION_MINOR}
${MGR_PYTHON_LIBRARIES} ${CMAKE_DL_LIBS} ${GSSAPI_LIBRARIES})
Python3::Python ${CMAKE_DL_LIBS} ${GSSAPI_LIBRARIES})
set_target_properties(ceph-mgr PROPERTIES
POSITION_INDEPENDENT_CODE ${EXE_LINKER_USE_PIE})
install(TARGETS ceph-mgr DESTINATION bin)
Expand Down
Loading

0 comments on commit 5fc657b

Please sign in to comment.