From: Patrick Seidensal Date: Thu, 9 Sep 2021 09:16:33 +0000 (+0200) Subject: cephadm: Only compress cephadm on Python >= 3.7 X-Git-Tag: v18.0.0~7^2~21 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b80082fd13b6d3879fe73051cc1c402937f0e9bd;p=ceph.git cephadm: Only compress cephadm on Python >= 3.7 Signed-off-by: Patrick Seidensal --- diff --git a/src/cephadm/CMakeLists.txt b/src/cephadm/CMakeLists.txt index d56390dc6d8..9986169179e 100644 --- a/src/cephadm/CMakeLists.txt +++ b/src/cephadm/CMakeLists.txt @@ -8,9 +8,9 @@ set(bin_target_file ${CMAKE_BINARY_DIR}/bin/cephadm) add_custom_command( OUTPUT "${bin_target_file}" DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cephadm.py - COMMAND ${CMAKE_COMMAND} -E make_directory cephadm - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/cephadm.py cephadm/__main__.py - COMMAND ${Python3_EXECUTABLE} -m zipapp -p python3 cephadm --compress --output "${bin_target_file}" - COMMENT "compiling ${bin_target_file}") + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND bash build.sh ${bin_target_file} +) + add_custom_target(cephadm ALL DEPENDS "${bin_target_file}") diff --git a/src/cephadm/build.sh b/src/cephadm/build.sh index f39df49a23e..3aff16d354a 100755 --- a/src/cephadm/build.sh +++ b/src/cephadm/build.sh @@ -2,6 +2,14 @@ set -ex +clean_up() { + if [ -e ${buildir} ]; then + rm -rf ${builddir} + fi +} +trap clean_up EXIT + +# Create build directory and install required dependencies target_fpath="$(pwd)/cephadm" if [ -n "$1" ]; then target_fpath="$1" @@ -10,8 +18,24 @@ builddir=$(mktemp -d) if [ -e "requirements.txt" ]; then python3 -m pip install -r requirements.txt --target ${builddir} fi -# Make sure all newly created source files are added here as well! + +# Make sure all newly created source files are copied here as well! cp cephadm.py ${builddir}/__main__.py -python3 -m zipapp -p python3 ${builddir} --compress --output $target_fpath -echo written to ${target_fpath} -rm -rf ${builddir} + +version=$(python3 --version) +if [[ "$version" =~ ^Python[[:space:]]([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)$ ]]; then + major=${BASH_REMATCH[1]} + minor=${BASH_REMATCH[2]} + + compress="" + if [[ "$major" -ge 3 && "$minor" -ge 7 ]]; then + echo "Pyton version compatible with --compress, compressing cephadm binary" + compress="--compress" + fi + + python3 -mzipapp -p python3 ${builddir} ${compress} --output $target_fpath + echo written to ${target_fpath} +else + echo "Couldn't parse Python version" + exit 1 +fi