]> git.proxmox.com Git - ceph.git/blob - ceph/src/script/run_tox.sh
import ceph 16.2.7
[ceph.git] / ceph / src / script / run_tox.sh
1 #!/usr/bin/env bash
2
3 set -e
4
5 if [ `uname` = FreeBSD ]; then
6 GETOPT=/usr/local/bin/getopt
7 else
8 GETOPT=getopt
9 fi
10
11 function usage() {
12 local prog_name=$(basename $1)
13 shift
14 cat <<EOF
15 $prog_name [options] ... [test_name]
16
17 options:
18
19 [-h|--help] display this help message
20 [--source-dir dir] root source directory of Ceph. deduced by the path of this script by default.
21 [--build-dir dir] build directory of Ceph. "\$source_dir/build" by default.
22 [--tox-path dir] directory in which "tox.ini" is located. if "test_name" is not specified, it is the current directory by default, otherwise the script will try to find a directory with the name of specified \$test_name with a "tox.ini" under it.
23 <--tox-envs envs> tox envlist. this option is required.
24 [--venv-path] the python virtualenv path. \$build_dir/\$test_name by default.
25
26 example:
27
28 following command will run tox with envlist of "py3,mypy" using the "tox.ini" in current directory.
29
30 $prog_name --tox-envs py3,mypy
31
32 following command will run tox with envlist of "py3" using "/ceph/src/python-common/tox.ini"
33
34 $prog_name --tox-envs py3 --tox-path /ceph/src/python-common
35 EOF
36 }
37
38 function get_cmake_variable() {
39 local cmake_cache=$1/CMakeCache.txt
40 shift
41 local variable=$1
42 shift
43 if [ -e $cmake_cache ]; then
44 grep "$variable" $cmake_cache | cut -d "=" -f 2
45 fi
46 }
47
48 function get_tox_path() {
49 local test_name=$1
50 if [ -n "$test_name" ]; then
51 local found=$(find $source_dir -path "*/$test_name/tox.ini")
52 echo $(dirname $found)
53 elif [ -e tox.ini ]; then
54 echo $(pwd)
55 fi
56 }
57
58 function main() {
59 local tox_path
60 local script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
61 local build_dir=$script_dir/../../build
62 local source_dir=$(get_cmake_variable $build_dir ceph_SOURCE_DIR)
63 local tox_envs
64 local options
65
66 options=$(${GETOPT} --name "$0" --options 'h' --longoptions "help,source-dir:,build-dir:,tox-path:,tox-envs:,venv-path:" -- "$@")
67 if [ $? -ne 0 ]; then
68 exit 2
69 fi
70 eval set -- "${options}"
71 while true; do
72 case "$1" in
73 -h|--help)
74 usage $0
75 exit 0;;
76 --source-dir)
77 source_dir=$2
78 shift 2;;
79 --build-dir)
80 build_dir=$2
81 shift 2;;
82 --tox-path)
83 tox_path=$2
84 shift 2;;
85 --tox-envs)
86 tox_envs=$2
87 shift 2;;
88 --venv-path)
89 venv_path=$2
90 shift 2;;
91 --)
92 shift
93 break;;
94 *)
95 echo "bad option $1" >& 2
96 exit 2;;
97 esac
98 done
99
100 local test_name
101 if [ -z "$tox_path" ]; then
102 # try harder
103 if [ $# -gt 0 ]; then
104 test_name=$1
105 shift
106 fi
107 tox_path=$(get_tox_path $test_name)
108 venv_path="$build_dir/$test_name"
109 else
110 test_name=$(basename $tox_path)
111 fi
112
113 if [ ! -f ${venv_path}/bin/activate ]; then
114 if [ -d "$venv_path" ]; then
115 cd $venv_path
116 echo "$PWD already exists, but it's not a virtualenv. test_name empty?"
117 exit 1
118 fi
119 $source_dir/src/tools/setup-virtualenv.sh ${venv_path}
120 fi
121 source ${venv_path}/bin/activate
122 pip install tox
123
124 # tox.ini will take care of this.
125 export CEPH_BUILD_DIR=$build_dir
126 # use the wheelhouse prepared by install-deps.sh
127 export PIP_FIND_LINKS="$tox_path/wheelhouse"
128 tox -c $tox_path/tox.ini -e "$tox_envs" "$@"
129 }
130
131 main "$@"