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}")
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"
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