]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: Only compress cephadm on Python >= 3.7
authorPatrick Seidensal <pseidensal@suse.com>
Thu, 9 Sep 2021 09:16:33 +0000 (11:16 +0200)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 13 Sep 2022 16:17:20 +0000 (12:17 -0400)
Signed-off-by: Patrick Seidensal <pseidensal@suse.com>
src/cephadm/CMakeLists.txt
src/cephadm/build.sh

index d56390dc6d8e197783651eb1a0aa91b1f7a0a6dc..9986169179e08a6014de8cc9238e378129dc9b79 100644 (file)
@@ -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}")
index f39df49a23ea3ef52c829cfdd908397dc3ae00ba..3aff16d354aee4ef614fae5b09427a7fa75d39a3 100755 (executable)
@@ -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