From 793308f82d997260e013938121b1d231883e8801 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 5 Aug 2019 23:37:52 +0800 Subject: [PATCH] cmake: pass tox envs to run_tox.sh explicitly * add two optional keyword parameters to `add_tox_test()` * use the default `TOX_PATH` parameter instead passing it explicitly, as it is always `${CMAKE_CURRENT_SOURCE_DIR}` * drop the code to guess the tox envs in `run_tox.sh`, and always pass them explicitly in CMake script using the `--tox-envs` argument. Signed-off-by: Kefu Chai --- cmake/modules/AddCephTest.cmake | 21 +++++- src/pybind/mgr/ansible/CMakeLists.txt | 2 +- src/pybind/mgr/dashboard/CMakeLists.txt | 9 ++- src/pybind/mgr/insights/CMakeLists.txt | 2 +- .../mgr/orchestrator_cli/CMakeLists.txt | 2 +- src/python-common/CMakeLists.txt | 2 +- src/script/run_tox.sh | 64 ++----------------- src/tools/cephfs/CMakeLists.txt | 2 +- 8 files changed, 38 insertions(+), 66 deletions(-) diff --git a/cmake/modules/AddCephTest.cmake b/cmake/modules/AddCephTest.cmake index 0e94f3f20ce..bb5936cf8ba 100644 --- a/cmake/modules/AddCephTest.cmake +++ b/cmake/modules/AddCephTest.cmake @@ -53,9 +53,25 @@ function(add_ceph_unittest unittest_name) target_link_libraries(${unittest_name} ${UNITTEST_LIBS}) endfunction() -function(add_tox_test name tox_path) +function(add_tox_test name) set(test_name run-tox-${name}) set(venv_path ${CEPH_BUILD_VIRTUALENV}/${name}-virtualenv) + cmake_parse_arguments(TOXTEST "" "TOX_PATH" "TOX_ENVS" ${ARGN}) + if(DEFINED TOXTEST_TOX_PATH) + set(tox_path ${TOXTEST_TOX_PATH}) + 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() + if(DEFINED TOXTEST_TOX_ENVS) + set(tox_envs ${TOXTEST_TOX_ENVS}) + endif() + string(REPLACE ";" "," tox_envs "${tox_envs}") add_custom_command( OUTPUT ${venv_path}/bin/activate COMMAND ${CMAKE_SOURCE_DIR}/src/tools/setup-virtualenv.sh ${venv_path} @@ -69,9 +85,8 @@ function(add_tox_test name tox_path) COMMAND ${CMAKE_SOURCE_DIR}/src/script/run_tox.sh --source-dir ${CMAKE_SOURCE_DIR} --build-dir ${CMAKE_BINARY_DIR} - --with-python2 ${WITH_PYTHON2} - --with-python3 ${WITH_PYTHON3} --tox-path ${tox_path} + --tox-envs ${tox_envs} --venv-path ${venv_path}) set_property( TEST ${test_name} diff --git a/src/pybind/mgr/ansible/CMakeLists.txt b/src/pybind/mgr/ansible/CMakeLists.txt index 4ef18461942..476be7a98c8 100644 --- a/src/pybind/mgr/ansible/CMakeLists.txt +++ b/src/pybind/mgr/ansible/CMakeLists.txt @@ -1,4 +1,4 @@ if(WITH_TESTS) include(AddCephTest) - add_tox_test(mgr-ansible ${CMAKE_CURRENT_SOURCE_DIR}) + add_tox_test(mgr-ansible) endif() diff --git a/src/pybind/mgr/dashboard/CMakeLists.txt b/src/pybind/mgr/dashboard/CMakeLists.txt index 29ea53db092..ad5f59e15e8 100644 --- a/src/pybind/mgr/dashboard/CMakeLists.txt +++ b/src/pybind/mgr/dashboard/CMakeLists.txt @@ -98,5 +98,12 @@ endif(WITH_MGR_DASHBOARD_FRONTEND AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "aarch6 if(WITH_TESTS) include(AddCephTest) - add_tox_test(mgr-dashboard ${CMAKE_CURRENT_SOURCE_DIR}) + if(WITH_PYTHON2) + list(APPEND dashboard_tox_envs py27-cov py27-lint py27-check) + endif() + if(WITH_PYTHON3) + list(APPEND dashboard_tox_envs py3-cov py3-lint py3-check) + endif() + add_tox_test(mgr-dashboard + TOX_ENVS ${dashboard_tox_envs}) endif() diff --git a/src/pybind/mgr/insights/CMakeLists.txt b/src/pybind/mgr/insights/CMakeLists.txt index 6137c32b704..f105a7bc9ea 100644 --- a/src/pybind/mgr/insights/CMakeLists.txt +++ b/src/pybind/mgr/insights/CMakeLists.txt @@ -1,4 +1,4 @@ if(WITH_TESTS) include(AddCephTest) - add_tox_test(mgr-insights ${CMAKE_CURRENT_SOURCE_DIR}) + add_tox_test(mgr-insights) endif() diff --git a/src/pybind/mgr/orchestrator_cli/CMakeLists.txt b/src/pybind/mgr/orchestrator_cli/CMakeLists.txt index f2e2fefc28d..68c3346611a 100644 --- a/src/pybind/mgr/orchestrator_cli/CMakeLists.txt +++ b/src/pybind/mgr/orchestrator_cli/CMakeLists.txt @@ -1,4 +1,4 @@ if(WITH_TESTS) include(AddCephTest) - add_tox_test(mgr-orchestrator_cli ${CMAKE_CURRENT_SOURCE_DIR}) + add_tox_test(mgr-orchestrator_cli) endif() diff --git a/src/python-common/CMakeLists.txt b/src/python-common/CMakeLists.txt index 08729d520a2..0b178ae9c87 100644 --- a/src/python-common/CMakeLists.txt +++ b/src/python-common/CMakeLists.txt @@ -13,5 +13,5 @@ endforeach() if(WITH_TESTS) include(AddCephTest) - add_tox_test(python-common ${CMAKE_CURRENT_SOURCE_DIR}) + add_tox_test(python-common) endif() diff --git a/src/script/run_tox.sh b/src/script/run_tox.sh index ed4846ac585..8c297fe70fc 100755 --- a/src/script/run_tox.sh +++ b/src/script/run_tox.sh @@ -28,56 +28,15 @@ function get_tox_path() { fi } -function get_env_list_for_dashboard() { - local with_python2=$1 - shift - local with_python3=$1 - shift - local env_list - if $with_python2; then - if [ $# -gt 0 ]; then - env_list+="py27-run," - else - env_list+="py27-cov,py27-lint,py27-check," - fi - fi - if $with_python3; then - if [ $# -gt 0 ]; then - env_list+="py3-run," - else - env_list+="py3-cov,py3-lint,py3-check," - fi - fi - # use bash string manipulation to strip off any trailing comma - echo "${env_list%,}" -} - -function get_env_list() { - local with_python2=$1 - shift - local with_python3=$1 - shift - local env_list - if $with_python2; then - env_list+="py27," - fi - if $with_python3; then - env_list+="py3," - fi - # use bash string manipulation to strip off any trailing comma - echo "${env_list%,}" -} - function main() { local tox_path local script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" local build_dir=$script_dir/../../build local source_dir=$(get_cmake_variable $build_dir ceph_SOURCE_DIR) - local with_python2=$(get_cmake_variable $build_dir WITH_PYTHON2) - local with_python3=$(get_cmake_variable $build_dir WITH_PYTHON3) - local parsed + local tox_envs + local options - options=$(${GETOPT} --name "$0" --options '' --longoptions "source-dir:,build-dir:,with-python2:,with-python3:,tox-path:,venv-path:" -- "$@") + options=$(${GETOPT} --name "$0" --options '' --longoptions "source-dir:,build-dir:,tox-path:,tox-envs:,venv-path:" -- "$@") if [ $? -ne 0 ]; then exit 2 fi @@ -90,15 +49,12 @@ function main() { --build-dir) build_dir=$2 shift 2;; - --with-python2) - with_python2=$2 - shift 2;; - --with-python3) - with_python3=$2 - shift 2;; --tox-path) tox_path=$2 shift 2;; + --tox-envs) + tox_envs=$2 + shift 2;; --venv-path) venv_path=$2 shift 2;; @@ -139,13 +95,7 @@ function main() { # tox.ini will take care of this. export CEPH_BUILD_DIR=$build_dir - local env_list - if [ $test_name = "dashboard" ]; then - env_list=$(get_env_list_for_dashboard $with_python2 $with_python3 "$@") - else - env_list=$(get_env_list $with_python2 $with_python3) - fi - tox -c $tox_path/tox.ini -e "$env_list" "$@" + tox -c $tox_path/tox.ini -e "$tox_envs" "$@" } main "$@" diff --git a/src/tools/cephfs/CMakeLists.txt b/src/tools/cephfs/CMakeLists.txt index 41da8e3a7ac..d934ea41491 100644 --- a/src/tools/cephfs/CMakeLists.txt +++ b/src/tools/cephfs/CMakeLists.txt @@ -49,6 +49,6 @@ if(WITH_CEPHFS_SHELL) endif() if(WITH_TESTS) include(AddCephTest) - add_tox_test(cephfs-shell ${CMAKE_CURRENT_SOURCE_DIR}) + add_tox_test(cephfs-shell) endif() endif() -- 2.39.5