From ee9500e3b09b909416a871ed1a43cc77c957e4e7 Mon Sep 17 00:00:00 2001 From: Lukas Rothenberger Date: Wed, 13 Nov 2024 15:11:16 +0100 Subject: [PATCH] feat: utilities and restructuring to create .deb packages for releases --- .gitignore | 3 ++ CMakeLists.txt | 58 +++++++++++++++++++---------------- DEBIAN/control.raw | 6 ++++ DEBIAN/postinst | 35 +++++++++++++++++++++ DEBIAN/postrm | 2 ++ DEBIAN/preinst | 0 DEBIAN/prerm | 0 docs/How_to_contribute.md | 2 ++ scripts/CMakeLists.txt | 37 ++++++++++++---------- scripts/dev/create_package.sh | 34 ++++++++++++++++++++ 10 files changed, 134 insertions(+), 43 deletions(-) create mode 100755 DEBIAN/control.raw create mode 100755 DEBIAN/postinst create mode 100755 DEBIAN/postrm create mode 100755 DEBIAN/preinst create mode 100755 DEBIAN/prerm create mode 100755 scripts/dev/create_package.sh diff --git a/.gitignore b/.gitignore index 6ad66132a..85163fd72 100644 --- a/.gitignore +++ b/.gitignore @@ -136,6 +136,9 @@ venv.bak/ *.a *.lib +# Packages +packages/ + # Executables *.exe *.out diff --git a/CMakeLists.txt b/CMakeLists.txt index b798c087d..4aebc8c2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,32 +102,36 @@ file(APPEND "${DiscoPoP_SOURCE_DIR}/discopop_library/ConfigProvider/assets/build file(APPEND "${DiscoPoP_SOURCE_DIR}/discopop_library/ConfigProvider/assets/build_config.py" "DP_BRANCH_TRACKING=\"${DP_BRANCH_TRACKING}\"\n") -# print DiscoPoP configuration -file(READ ${DiscoPoP_SOURCE_DIR}/discopop_library/ConfigProvider/assets/build_config.py DiscoPoP_CONFIGURATION) -string(REGEX REPLACE "\n$" "" DiscoPoP_CONFIGURATION "${DiscoPoP_CONFIGURATION}") -string(REGEX REPLACE "\n" "\n " DiscoPoP_CONFIGURATION "${DiscoPoP_CONFIGURATION}") -message(STATUS "DiscoPoP configuration:\n ${DiscoPoP_CONFIGURATION}") - -# install DiscoPoP python modules -find_package(Python3 REQUIRED COMPONENTS Interpreter) - -# check if python tkinter module is available -execute_process( - COMMAND ${Python3_EXECUTABLE} -c "import tkinter" - RESULT_VARIABLE TKINTER_AVAILABLE_EXIT_CODE -) -if(${TKINTER_AVAILABLE_EXIT_CODE}) - message(FATAL_ERROR "Python module 'tkinter' not found. Please install the 'python3-tk' package via a package manager.") -endif() +if(NOT ${IS_DEB_INSTALL} STREQUAL "") + message(STATUS "performing installation from .deb package") +else() + # print DiscoPoP configuration + file(READ ${DiscoPoP_SOURCE_DIR}/discopop_library/ConfigProvider/assets/build_config.py DiscoPoP_CONFIGURATION) + string(REGEX REPLACE "\n$" "" DiscoPoP_CONFIGURATION "${DiscoPoP_CONFIGURATION}") + string(REGEX REPLACE "\n" "\n " DiscoPoP_CONFIGURATION "${DiscoPoP_CONFIGURATION}") + message(STATUS "DiscoPoP configuration:\n ${DiscoPoP_CONFIGURATION}") + + # install DiscoPoP python modules + find_package(Python3 REQUIRED COMPONENTS Interpreter) + + # check if python tkinter module is available + execute_process( + COMMAND ${Python3_EXECUTABLE} -c "import tkinter" + RESULT_VARIABLE TKINTER_AVAILABLE_EXIT_CODE + ) + if(${TKINTER_AVAILABLE_EXIT_CODE}) + message(FATAL_ERROR "Python module 'tkinter' not found. Please install the 'python3-tk' package via a package manager.") + endif() -# install DiscoPoP python modules -message(STATUS "Installing DiscoPoP python modules") -execute_process( - COMMAND ${Python3_EXECUTABLE} -m pip install ${DiscoPoP_SOURCE_DIR} - RESULT_VARIABLE DP_INSTALLATION_EXIT_CODE - OUTPUT_VARIABLE DP_INSTALLATION_OUTPUT -) -# check if installation of DiscoPoP Modules was successful -if(${DP_INSTALLATION_EXIT_CODE}) - message(FATAL_ERROR "${DP_INSTALLATION_OUTPUT}") + # install DiscoPoP python modules + message(STATUS "Installing DiscoPoP python modules") + execute_process( + COMMAND ${Python3_EXECUTABLE} -m pip install ${DiscoPoP_SOURCE_DIR} + RESULT_VARIABLE DP_INSTALLATION_EXIT_CODE + OUTPUT_VARIABLE DP_INSTALLATION_OUTPUT + ) + # check if installation of DiscoPoP Modules was successful + if(${DP_INSTALLATION_EXIT_CODE}) + message(FATAL_ERROR "${DP_INSTALLATION_OUTPUT}") + endif() endif() diff --git a/DEBIAN/control.raw b/DEBIAN/control.raw new file mode 100755 index 000000000..4916f9bfc --- /dev/null +++ b/DEBIAN/control.raw @@ -0,0 +1,6 @@ +Package: discopop +Maintainer: Lukas Rothenberger +Depends: libc6,python3-tk,python3,pipx +Architecture: amd64 +Homepage: http://example.com +Description: A program that prints hello \ No newline at end of file diff --git a/DEBIAN/postinst b/DEBIAN/postinst new file mode 100755 index 000000000..7326ac056 --- /dev/null +++ b/DEBIAN/postinst @@ -0,0 +1,35 @@ +DP_DIR=/opt/DiscoPoP +chmod 777 ${DP_DIR} +DP_BUILD_DIR=/opt/DiscoPoP/build +mkdir -p ${DP_BUILD_DIR} +chmod 777 ${DP_BUILD_DIR} +cd ${DP_BUILD_DIR} +echo "Created DiscoPoP build dir: ${DP_BUILD_DIR}" + +echo "Downloading llvm 11.1.0" +mkdir third_party +cd third_party +wget https://github.com/llvm/llvm-project/releases/download/llvmorg-11.1.0/clang+llvm-11.1.0-x86_64-linux-gnu-ubuntu-20.10.tar.xz +tar -xvf clang+llvm-11.1.0-x86_64-linux-gnu-ubuntu-20.10.tar.xz +mv clang+llvm-11.1.0-x86_64-linux-gnu-ubuntu-20.10 llvm-11.1.0 +rm clang+llvm-11.1.0-x86_64-linux-gnu-ubuntu-20.10.tar.xz +LLVM_DIR=${DP_BUILD_DIR}/third_party/llvm-11.1.0 + +echo "Building DiscoPoP" +cd ${DP_BUILD_DIR} +cmake -DLLVM_DIST_PATH=${LLVM_DIR} -DIS_DEB_INSTALL="TRUE" .. +make -j + +chmod -R 777 ${DP_DIR} + +echo "Installing DiscoPoP python modules" +cd ${DP_DIR} +su ${SUDO_USER} -c "python3 -m pipx install ." + +echo "Creating symlinks" +su ${SUDO_USER} -c "rm -f ~/.local/bin/disocpop_cc" +su ${SUDO_USER} -c "rm -f ~/.local/bin/disocpop_cxx" +su ${SUDO_USER} -c "rm -f ~/.local/bin/disocpop_cmake" +su ${SUDO_USER} -c "ln -sf ${DP_BUILD_DIR}/scripts/CC_wrapper.sh ~/.local/bin/discopop_cc" +su ${SUDO_USER} -c "ln -sf ${DP_BUILD_DIR}/scripts/CXX_wrapper.sh ~/.local/bin/discopop_cxx" +su ${SUDO_USER} -c "ln -sf ${DP_BUILD_DIR}/scripts/CMAKE_wrapper.sh ~/.local/bin/discopop_cmake" diff --git a/DEBIAN/postrm b/DEBIAN/postrm new file mode 100755 index 000000000..7d6fa117d --- /dev/null +++ b/DEBIAN/postrm @@ -0,0 +1,2 @@ +rm -rf /opt/DiscoPoP +su ${SUDO_USER} -c "python3 -m pipx uninstall discopop" \ No newline at end of file diff --git a/DEBIAN/preinst b/DEBIAN/preinst new file mode 100755 index 000000000..e69de29bb diff --git a/DEBIAN/prerm b/DEBIAN/prerm new file mode 100755 index 000000000..e69de29bb diff --git a/docs/How_to_contribute.md b/docs/How_to_contribute.md index 3c35cabb7..c44138358 100644 --- a/docs/How_to_contribute.md +++ b/docs/How_to_contribute.md @@ -43,6 +43,7 @@ Commit messages should follow the conventional commits format: [conventional com Execute the following steps in order to create a new DiscoPoP release: - Switch to the release branch (e.g. `release/1.2.3`) which shall be released - Update the version file in the repository (`discopop_library/global_data/version/VERSION`) +- Create a `.deb` package by executing `scripts/dev/create_package.sh`. The package will be created in `packages`. - Create a pull request to the `master` branch and validate the changes - Merge the pull request by rebasing and create a tag on the `master` branch with the name `v1.2.3` - Creating the tag triggers the automatic publication of the project to PyPi @@ -51,6 +52,7 @@ Execute the following steps in order to create a new DiscoPoP release: - Release tag: `v1.2.3` - Release title: `DiscoPoP Version 1.2.3` - Description should contain a summary of the most relevant changes + - Add the created `.deb` package to the list of files - If everything is fine, publish the new release ### Determining the Version Number diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index f0f49f6da..b077f7482 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -18,22 +18,27 @@ configure_file(MPI_CC_wrapper.sh MPI_CC_wrapper.sh COPYONLY) configure_file(MPI_CXX_wrapper.sh MPI_CXX_wrapper.sh COPYONLY) configure_file(MPI_LINKER_wrapper.sh MPI_LINKER_wrapper.sh COPYONLY) -# create symlinks to files -set(DP_LOCAL_BIN_DIR "$ENV{HOME}/.local/bin") -if(EXISTS ${DP_LOCAL_BIN_DIR}) - execute_process(COMMAND rm -f ${DP_LOCAL_BIN_DIR}/discopop_cc) - message(STATUS "Creating symlink ${DP_LOCAL_BIN_DIR}/discopop_cc to ${CMAKE_CURRENT_BINARY_DIR}/CC_wrapper.sh") - execute_process(COMMAND ln -sf ${CMAKE_CURRENT_BINARY_DIR}/CC_wrapper.sh ${DP_LOCAL_BIN_DIR}/discopop_cc) +if(NOT ${IS_DEB_INSTALL} STREQUAL "") + # create symlinks to files + message(STATUS "performing installation from .deb package") +else() + # create symlinks to files + set(DP_LOCAL_BIN_DIR "$ENV{HOME}/.local/bin") + if(EXISTS ${DP_LOCAL_BIN_DIR}) + execute_process(COMMAND rm -f ${DP_LOCAL_BIN_DIR}/discopop_cc) + message(STATUS "Creating symlink ${DP_LOCAL_BIN_DIR}/discopop_cc to ${CMAKE_CURRENT_BINARY_DIR}/CC_wrapper.sh") + execute_process(COMMAND ln -sf ${CMAKE_CURRENT_BINARY_DIR}/CC_wrapper.sh ${DP_LOCAL_BIN_DIR}/discopop_cc) - execute_process(COMMAND rm -f ${DP_LOCAL_BIN_DIR}/discopop_cxx) - message(STATUS "Creating symlink ${DP_LOCAL_BIN_DIR}/discopop_cxx to ${CMAKE_CURRENT_BINARY_DIR}/CXX_wrapper.sh") - execute_process(COMMAND ln -sf ${CMAKE_CURRENT_BINARY_DIR}/CXX_wrapper.sh ${DP_LOCAL_BIN_DIR}/discopop_cxx) + execute_process(COMMAND rm -f ${DP_LOCAL_BIN_DIR}/discopop_cxx) + message(STATUS "Creating symlink ${DP_LOCAL_BIN_DIR}/discopop_cxx to ${CMAKE_CURRENT_BINARY_DIR}/CXX_wrapper.sh") + execute_process(COMMAND ln -sf ${CMAKE_CURRENT_BINARY_DIR}/CXX_wrapper.sh ${DP_LOCAL_BIN_DIR}/discopop_cxx) - execute_process(COMMAND rm -f ${DP_LOCAL_BIN_DIR}/discopop_cmake) - message(STATUS "Creating symlink ${DP_LOCAL_BIN_DIR}/discopop_cmake to ${CMAKE_CURRENT_BINARY_DIR}/CMAKE_wrapper.sh") - execute_process(COMMAND ln -sf ${CMAKE_CURRENT_BINARY_DIR}/CMAKE_wrapper.sh ${DP_LOCAL_BIN_DIR}/discopop_cmake) -else() - message(WARNING "Creation of symlinks discopop_cc to ${CMAKE_CURRENT_BINARY_DIR}/CC_wrapper.sh not possible. Please create it manually.") - message(WARNING "Creation of symlinks discopop_cxx to ${CMAKE_CURRENT_BINARY_DIR}/CXX_wrapper.sh not possible. Please create it manually.") - message(WARNING "Creation of symlinks discopop_cmake to ${CMAKE_CURRENT_BINARY_DIR}/CMAKE_wrapper.sh not possible. Please create it manually.") + execute_process(COMMAND rm -f ${DP_LOCAL_BIN_DIR}/discopop_cmake) + message(STATUS "Creating symlink ${DP_LOCAL_BIN_DIR}/discopop_cmake to ${CMAKE_CURRENT_BINARY_DIR}/CMAKE_wrapper.sh") + execute_process(COMMAND ln -sf ${CMAKE_CURRENT_BINARY_DIR}/CMAKE_wrapper.sh ${DP_LOCAL_BIN_DIR}/discopop_cmake) + else() + message(WARNING "Creation of symlinks discopop_cc to ${CMAKE_CURRENT_BINARY_DIR}/CC_wrapper.sh not possible. Please create it manually.") + message(WARNING "Creation of symlinks discopop_cxx to ${CMAKE_CURRENT_BINARY_DIR}/CXX_wrapper.sh not possible. Please create it manually.") + message(WARNING "Creation of symlinks discopop_cmake to ${CMAKE_CURRENT_BINARY_DIR}/CMAKE_wrapper.sh not possible. Please create it manually.") + endif() endif() diff --git a/scripts/dev/create_package.sh b/scripts/dev/create_package.sh new file mode 100755 index 000000000..21f98b88f --- /dev/null +++ b/scripts/dev/create_package.sh @@ -0,0 +1,34 @@ +# create a temporary copy of the code to build the package +rm -rf tmp_package_build_dir +mkdir -p tmp_package_build_dir +cp -r * tmp_package_build_dir + +# modify folder structure to install DiscoPoP to /opt when installing the package +cd tmp_package_build_dir +mkdir opt +mkdir opt/DiscoPoP + +mv * opt/DiscoPoP +mv opt/DiscoPoP/DEBIAN . + +# add the Version tag to DEBIAN/control.raw to create DEBIAN/control +echo "$(cat DEBIAN/control.raw)" > DEBIAN/control +echo "Version: $(cat opt/DiscoPoP/discopop_library/global_data/version/VERSION)" >> DEBIAN/control +echo "" >> DEBIAN/control + +# delete build folder if exists +rm -rf opt/DiscoPoP/build +# delete packages folder if exists +rm -rf opt/DiscoPoP/packages +# cleanup +rm -rf opt/DiscoPoP/tmp_packages_build_dir + +# create packages folder +cd .. +mkdir -p packages +# build package +dpkg-deb --build tmp_package_build_dir packages/DiscoPoP.deb +chmod 775 packages/DiscoPoP.deb + +# cleanup +rm -rf tmp_package_build_dir \ No newline at end of file