From ee3d2d1eace0b472a2f83322a48eb71e92b06f52 Mon Sep 17 00:00:00 2001 From: bruno <97033386+bruno-at-orange@users.noreply.github.com> Date: Tue, 17 Sep 2024 18:42:11 +0200 Subject: [PATCH] Add workflow to build deb packages Add cmake_format.py to improve cmake formatting in pre-commit: modify all cmake files --- .cmake-format.py | 7 +++ .github/workflows/pack-debian.yml | 57 ++++++++++++++++++ CMakeLists.txt | 76 ++++++++++-------------- cmake/modules/CodeCoverage.cmake | 96 +++++++++++-------------------- generate_tests.cmake | 13 +++-- test/CMakeLists.txt | 17 ++---- 6 files changed, 140 insertions(+), 126 deletions(-) create mode 100644 .cmake-format.py create mode 100644 .github/workflows/pack-debian.yml diff --git a/.cmake-format.py b/.cmake-format.py new file mode 100644 index 0000000..6082af2 --- /dev/null +++ b/.cmake-format.py @@ -0,0 +1,7 @@ +with section("format"): + line_width = 120 + tab_size = 2 + line_ending = "auto" + +with section("markup"): + bullet_char = "-" diff --git a/.github/workflows/pack-debian.yml b/.github/workflows/pack-debian.yml new file mode 100644 index 0000000..8f15789 --- /dev/null +++ b/.github/workflows/pack-debian.yml @@ -0,0 +1,57 @@ +--- +name: DEB Packages +on: + workflow_dispatch: + pull_request: + branches: + - v11 + - main + push: + tags: ['*'] + +jobs: + build: + runs-on: ubuntu-latest + defaults: + run: + shell: bash + strategy: + fail-fast: false + matrix: + image: ['debian:10', 'debian:11', 'debian:12', 'ubuntu:20.04', 'ubuntu:22.04', 'ubuntu:24.04'] + container: ${{ matrix.image }} + steps: + - name: Install packages + run: | + export DEBIAN_FRONTEND="noninteractive" + apt-get -y update + apt-get -y --no-install-recommends install build-essential coreutils debhelper git ca-certificates + - name: Checkout sources + uses: actions/checkout@v4 + with: + submodules: true + - name: Configure CMake + run: | + cmake -S . -B builds -D CMAKE_BUILD_TYPE=Release -D CMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake + - name: Build + run: | + cmake --build builds --target khiopsdriver_file_gcs + - name: Build package with CPack + run: cd builds/ && cpack -G DEB + - name: Rename the packages to include the ubuntu codename + run: | + source /etc/os-release + cd builds/packages/ + for filename in *.deb + do + mv -v $filename ${filename%_*}-${VERSION_CODENAME}.${filename##*_} + done + - name: Upload the packages as artifacts + uses: actions/upload-artifact@v4 + with: + # We add a `deb-` prefix so we can later recover all artifacts with the pattern `deb-*` + # Note: The more natural pattern `*-deb` or `*` does not work + name: deb-${{ env.ID }}-${{ env.VERSION_CODENAME }} + path: builds/packages/*.deb + if-no-files-found: error + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 82c6a52..d9dcf95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,8 @@ # CMakeLists.txt -# Ensure to pick up the default triplet from the environment if any. This helps -# driving the vcpkg triplet in the same way either when starting vcpkg directly, -# or when letting CMake start vcpkg at configure/generate time. Note: this logic -# must happen before PROJECT command. +# Ensure to pick up the default triplet from the environment if any. This helps driving the vcpkg triplet in the same +# way either when starting vcpkg directly, or when letting CMake start vcpkg at configure/generate time. Note: this +# logic must happen before PROJECT command. if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET) set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" @@ -40,11 +39,10 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) # Set the location of the built artifacts: # -# * Shared and static library target directory: lib -# * Executable target directory: bin -# * We must use these weird generator expressions to avoid the Debug and Release -# directories in VS -# * More info: https://stackoverflow.com/q/47175912 +# - Shared and static library target directory: lib +# - Executable target directory: bin +# - We must use these weird generator expressions to avoid the Debug and Release directories in VS +# - More info: https://stackoverflow.com/q/47175912 # set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY $<1:${CMAKE_BINARY_DIR}/lib/>) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY $<1:${CMAKE_BINARY_DIR}/lib/>) @@ -52,33 +50,23 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_BINARY_DIR}/bin/>) message(STATUS "Executables will be stored in ${CMAKE_BINARY_DIR}/bin/") message(STATUS "Libraries will be stored in ${CMAKE_BINARY_DIR}/lib/") -if((CMAKE_SYSTEM_NAME STREQUAL "Linux") AND NOT (CMAKE_BUILD_TYPE STREQUAL - "Release")) +if((CMAKE_SYSTEM_NAME STREQUAL "Linux") AND NOT (CMAKE_BUILD_TYPE STREQUAL "Release")) message("Build system == Linux, build with sanitizer tools") - add_compile_options(-fsanitize=undefined -fsanitize=address - -fno-sanitize-recover=all) - add_link_options(-fsanitize=undefined -fsanitize=address - -fno-sanitize-recover=all) + add_compile_options(-fsanitize=undefined -fsanitize=address -fno-sanitize-recover=all) + add_link_options(-fsanitize=undefined -fsanitize=address -fno-sanitize-recover=all) include(CodeCoverage) - set(CMAKE_CXX_FLAGS_DEBUG - "${CMAKE_CXX_FLAGS_COVERAGE} ${CMAKE_CXX_FLAGS_DEBUG}") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_COVERAGE} ${CMAKE_CXX_FLAGS_DEBUG}") setup_target_for_coverage(${PROJECT_NAME}_coverage basic_test coverage) - setup_target_for_coverage_cobertura( - ${PROJECT_NAME}_cobertura basic_test coverage - --gtest_output=xml:coverage.junit.xml) + setup_target_for_coverage_cobertura(${PROJECT_NAME}_cobertura basic_test coverage + --gtest_output=xml:coverage.junit.xml) endif() -add_library(khiopsdriver_file_gcs SHARED - src/gcsplugin.h src/gcsplugin_internal.h src/gcsplugin.cpp) +add_library(khiopsdriver_file_gcs SHARED src/gcsplugin.h src/gcsplugin_internal.h src/gcsplugin.cpp) -target_link_options(khiopsdriver_file_gcs PRIVATE $<$:-s> -)# stripping -target_link_libraries(khiopsdriver_file_gcs PRIVATE google-cloud-cpp::storage - spdlog::spdlog) +target_link_options(khiopsdriver_file_gcs PRIVATE $<$:-s>) # stripping +target_link_libraries(khiopsdriver_file_gcs PRIVATE google-cloud-cpp::storage spdlog::spdlog) -set_target_properties( - khiopsdriver_file_gcs PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} - VERSION ${PROJECT_VERSION}) +set_target_properties(khiopsdriver_file_gcs PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} VERSION ${PROJECT_VERSION}) target_compile_options( khiopsdriver_file_gcs @@ -91,8 +79,7 @@ if(BUILD_TESTS) add_executable(KhiopsPluginTest src/khiopsplugintest.cpp) target_link_libraries(KhiopsPluginTest PRIVATE fmt::fmt ${CMAKE_DL_LIBS}) add_executable(drivertest src/drivertest.cpp) - target_link_libraries(drivertest ${CMAKE_DL_LIBS} google-cloud-cpp::storage - )# Link to dl + target_link_libraries(drivertest ${CMAKE_DL_LIBS} google-cloud-cpp::storage) # Link to dl endif(BUILD_TESTS) add_subdirectory(test) @@ -111,8 +98,7 @@ set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE") set(CPACK_PACKAGE_VENDOR "Orange") set(CPACK_PACKAGE_CONTACT "Khiops Team ") set(CPACK_SOURCE_IGNORE_FILES .git) -set(CPACK_PACKAGE_DESCRIPTION - "This driver allows Khiops to access the Google Cloud storage.") +set(CPACK_PACKAGE_DESCRIPTION "This driver allows Khiops to access the Google Cloud storage.") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "GCS driver for the Khiops tool") set(CPACK_PACKAGE_NAME "khiops-driver-gcs") @@ -131,15 +117,15 @@ set(CPACK_ARCHIVE_FILE_NAME kkhiops-driver-gcs-${PROJECT_VERSION}) # ########### DEB Generator ############################# -# Package release ("This is the numbering of the DEB package itself, i.e. the -# version of the packaging and not the version of the content") +# Package release ("This is the numbering of the DEB package itself, i.e. the version of the packaging and not the +# version of the content") set(CPACK_DEBIAN_PACKAGE_RELEASE 1) # package name for deb. set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) -# Packages version: the full KHIOPS_VERSION (N.N.N_aN) instead of the -# PROJECT_VERSION (N.N.N) set(CPACK_DEBIAN_PACKAGE_VERSION ${KHIOPS_VERSION}) +# Packages version: the full KHIOPS_VERSION (N.N.N_aN) instead of the PROJECT_VERSION (N.N.N) +# set(CPACK_DEBIAN_PACKAGE_VERSION ${KHIOPS_VERSION}) set(CPACK_DEB_COMPONENT_INSTALL YES) set(CPACK_DEBIAN_PACKAGE_SECTION "math") @@ -147,17 +133,15 @@ set(CPACK_DEBIAN_PACKAGE_SECTION "math") # runtime path setting set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON) -# binaries in deb building will search shared library in the build tree. We -# should use directly CMAKE_LIBRARY_OUTPUT_DIRECTORY but it produces a bug in -# dpkg-shlibdeps +# binaries in deb building will search shared library in the build tree. We should use directly +# CMAKE_LIBRARY_OUTPUT_DIRECTORY but it produces a bug in dpkg-shlibdeps set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS_PRIVATE_DIRS ${CMAKE_BINARY_DIR}/lib/) # packages recommends set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "khiops") -# packages posinst and triggers -set(CPACK_DEBIAN_KNI_PACKAGE_CONTROL_EXTRA - "${PROJECT_SOURCE_DIR}/packaging/linux/debian/kni/triggers") +# packages posinst and triggers set(CPACK_DEBIAN_KNI_PACKAGE_CONTROL_EXTRA +# ${PROJECT_SOURCE_DIR}/packaging/linux/debian/kni/triggers") # set(CPACK_DEBIAN_PACKAGE_DEBUG ON) set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION TRUE) @@ -180,10 +164,8 @@ set(CPACK_RPM_FILE_NAME RPM-DEFAULT) # packages summary set(CPACK_RPM_PACKAGE_SUMMARY "Khiops tools") -# packages post/postun install scripts -# set(CPACK_RPM_KNI_POST_INSTALL_SCRIPT_FILE -# "${PROJECT_SOURCE_DIR}/packaging/linux/redhat/kni.post") -# set(CPACK_RPM_KNI_POSTUN_INSTALL_SCRIPT_FILE +# packages post/postun install scripts set(CPACK_RPM_KNI_POST_INSTALL_SCRIPT_FILE +# "${PROJECT_SOURCE_DIR}/packaging/linux/redhat/kni.post") set(CPACK_RPM_KNI_POSTUN_INSTALL_SCRIPT_FILE # "${PROJECT_SOURCE_DIR}/packaging/linux/redhat/kni.postun") include(CPack) diff --git a/cmake/modules/CodeCoverage.cmake b/cmake/modules/CodeCoverage.cmake index 0937143..9e9f419 100644 --- a/cmake/modules/CodeCoverage.cmake +++ b/cmake/modules/CodeCoverage.cmake @@ -1,32 +1,27 @@ # # 2012-01-31, Lars Bilke - Enable Code Coverage # -# 2013-09-17, Joakim Söderberg - Added support for Clang. - Some additional -# usage instructions. +# 2013-09-17, Joakim Söderberg - Added support for Clang. - Some additional usage instructions. # # USAGE: -# 1. (Mac only) If you use Xcode 5.1 make sure to patch geninfo as described -# here: http://stackoverflow.com/a/22404544/80480 +# 1. (Mac only) If you use Xcode 5.1 make sure to patch geninfo as described here: +# http://stackoverflow.com/a/22404544/80480 # # 1. Copy this file into your cmake modules path. # # 1. Add the following line to your CMakeLists.txt: INCLUDE(CodeCoverage) # -# 1. Set compiler flags to turn off optimization and enable coverage: -# SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") -# SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") +# 1. Set compiler flags to turn off optimization and enable coverage: SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs +# -ftest-coverage") SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") # -# 1. Use the function SETUP_TARGET_FOR_COVERAGE to create a custom make target -# which runs your test executable and produces a lcov code coverage report: -# Example: SETUP_TARGET_FOR_COVERAGE( my_coverage_target # Name for custom -# target. test_driver # Name of the test driver executable that runs -# the tests. # NOTE! This should always have a ZERO as exit code # otherwise -# the coverage generation will not complete. coverage # Name of -# output directory. ) +# 1. Use the function SETUP_TARGET_FOR_COVERAGE to create a custom make target which runs your test executable and +# produces a lcov code coverage report: Example: SETUP_TARGET_FOR_COVERAGE( my_coverage_target # Name for custom +# target. test_driver # Name of the test driver executable that runs the tests. # NOTE! This should always +# have a ZERO as exit code # otherwise the coverage generation will not complete. coverage # Name of output +# directory. ) # -# 1. Build a Debug build: cmake -DCMAKE_BUILD_TYPE=Debug .. make make -# my_coverage_target +# 1. Build a Debug build: cmake -DCMAKE_BUILD_TYPE=Debug .. make make my_coverage_target # # Check prereqs @@ -42,9 +37,7 @@ endif() # NOT GCOV_PATH if(NOT CMAKE_COMPILER_IS_GNUCXX) # Clang version 3.0.0 and greater now supports gcov as well. message( - WARNING - "Compiler is not GNU gcc! Clang Version 3.0.0 and greater supports gcov as well, but older versions don't." - ) + WARNING "Compiler is not GNU gcc! Clang Version 3.0.0 and greater supports gcov as well, but older versions don't.") if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") message(FATAL_ERROR "Compiler is not GNU gcc! Aborting...") @@ -59,31 +52,21 @@ set(CMAKE_C_FLAGS_COVERAGE CACHE STRING "Flags used by the C compiler during coverage builds." FORCE) set(CMAKE_EXE_LINKER_FLAGS_COVERAGE "" - CACHE STRING "Flags used for linking binaries during coverage builds." - FORCE) + CACHE STRING "Flags used for linking binaries during coverage builds." FORCE) set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "" - CACHE STRING - "Flags used by the shared libraries linker during coverage builds." - FORCE) -mark_as_advanced( - CMAKE_CXX_FLAGS_COVERAGE CMAKE_C_FLAGS_COVERAGE - CMAKE_EXE_LINKER_FLAGS_COVERAGE CMAKE_SHARED_LINKER_FLAGS_COVERAGE) - -if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL - "Coverage")) - message( - WARNING - "Code coverage results with an optimized (non-Debug) build may be misleading" - ) + CACHE STRING "Flags used by the shared libraries linker during coverage builds." FORCE) +mark_as_advanced(CMAKE_CXX_FLAGS_COVERAGE CMAKE_C_FLAGS_COVERAGE CMAKE_EXE_LINKER_FLAGS_COVERAGE + CMAKE_SHARED_LINKER_FLAGS_COVERAGE) + +if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Coverage")) + message(WARNING "Code coverage results with an optimized (non-Debug) build may be misleading") endif() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug" -# Param _targetname The name of new the custom make target Param _testrunner -# The name of the target which runs the tests. MUST return ZERO always, even on -# errors. If not, no coverage report will be created! Param _outputname lcov -# output is generated as _outputname.info HTML report is generated in -# _outputname/index.html Optional fourth parameter is passed as arguments to -# _testrunner Pass them in list form, e.g.: "-j;2" for -j 2 +# Param _targetname The name of new the custom make target Param _testrunner The name of the target which runs the +# tests. MUST return ZERO always, even on errors. If not, no coverage report will be created! Param _outputname lcov +# output is generated as _outputname.info HTML report is generated in _outputname/index.html Optional fourth parameter +# is passed as arguments to _testrunner Pass them in list form, e.g.: "-j;2" for -j 2 function(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname) if(NOT LCOV_PATH) @@ -102,37 +85,27 @@ function(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname) # Run tests COMMAND ${_testrunner} ${ARGV3} # Capturing lcov counters and generating report - COMMAND ${LCOV_PATH} --directory . --capture --output-file - ${_outputname}.info - COMMAND - ${LCOV_PATH} --remove ${_outputname}.info '*/build/*' '*/tests/*' '/usr/*' - '*/vcpkg_installed/*' '*/_deps/*' --output-file - ${_outputname}.info.cleaned + COMMAND ${LCOV_PATH} --directory . --capture --output-file ${_outputname}.info + COMMAND ${LCOV_PATH} --remove ${_outputname}.info '*/build/*' '*/tests/*' '/usr/*' '*/vcpkg_installed/*' '*/_deps/*' + --output-file ${_outputname}.info.cleaned COMMAND ${GENHTML_PATH} -o ${_outputname} ${_outputname}.info.cleaned - COMMAND ${CMAKE_COMMAND} -E remove ${_outputname}.info - ${_outputname}.info.cleaned + COMMAND ${CMAKE_COMMAND} -E remove ${_outputname}.info ${_outputname}.info.cleaned WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMENT - "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." - ) + COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report.") # Show info where to find the report add_custom_command( TARGET ${_targetname} POST_BUILD COMMAND ; - COMMENT - "Open ./${_outputname}/index.html in your browser to view the coverage report." - ) + COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report.") endfunction() # SETUP_TARGET_FOR_COVERAGE -# Param _targetname The name of new the custom make target Param _testrunner -# The name of the target which runs the tests Param _outputname cobertura -# output is generated as _outputname.xml Optional fourth parameter is passed as +# Param _targetname The name of new the custom make target Param _testrunner The name of the target which runs the +# tests Param _outputname cobertura output is generated as _outputname.xml Optional fourth parameter is passed as # arguments to _testrunner Pass them in list form, e.g.: "-j;2" for -j 2 -function(SETUP_TARGET_FOR_COVERAGE_COBERTURA _targetname _testrunner - _outputname) +function(SETUP_TARGET_FOR_COVERAGE_COBERTURA _targetname _testrunner _outputname) find_program(PYTHON_EXECUTABLE python) @@ -149,9 +122,8 @@ function(SETUP_TARGET_FOR_COVERAGE_COBERTURA _targetname _testrunner # Run tests ${_testrunner} ${ARGV3} # Running gcovr - COMMAND - ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} -e '${CMAKE_SOURCE_DIR}/tests/' -e - '${CMAKE_SOURCE_DIR}/build/' -o ${_outputname}.xml + COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} -e '${CMAKE_SOURCE_DIR}/tests/' -e '${CMAKE_SOURCE_DIR}/build/' -o + ${_outputname}.xml WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMENT "Running gcovr to produce Cobertura code coverage report.") diff --git a/generate_tests.cmake b/generate_tests.cmake index 1b6efc9..d1c4150 100644 --- a/generate_tests.cmake +++ b/generate_tests.cmake @@ -1,11 +1,12 @@ include(FetchContent) FetchContent_Declare( - googletest - GIT_REPOSITORY "https://github.com/google/googletest.git" - GIT_TAG "v1.14.0" -) + googletest + GIT_REPOSITORY "https://github.com/google/googletest.git" + GIT_TAG "v1.14.0") -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +set(gtest_force_shared_crt + ON + CACHE BOOL "" FORCE) #[==[ if(CMAKE_BUILD_TYPE STREQUAL "Release") set_property(TARGET gtest PROPERTY MSVC_RUNTIME_LIBRARY MultiThreaded) @@ -20,4 +21,4 @@ FetchContent_MakeAvailable(googletest) include(GoogleTest) enable_testing() -add_subdirectory(test) \ No newline at end of file +add_subdirectory(test) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a40cba0..bd48e0e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -22,14 +22,12 @@ target_compile_options( PRIVATE $<$:-Wall;-Wextra;-pedantic>) # MSVC requires /bigobj to build in debug config -target_compile_options( - basic_test PRIVATE $<$,$>:/bigobj>) +target_compile_options(basic_test PRIVATE $<$,$>:/bigobj>) target_include_directories(basic_test PRIVATE ${${PROJECT_NAME}_SOURCE_DIR}/src) -target_link_libraries( - basic_test PRIVATE GTest::gtest GTest::gmock GTest::gmock_main - google-cloud-cpp::storage khiopsdriver_file_gcs) +target_link_libraries(basic_test PRIVATE GTest::gtest GTest::gmock GTest::gmock_main google-cloud-cpp::storage + khiopsdriver_file_gcs) gtest_discover_tests(basic_test) @@ -40,15 +38,12 @@ target_compile_options( PRIVATE $<$:-Wall;-Wextra;-pedantic>) if(WIN32) # custom build and test execution for Windows - target_link_libraries(plugin_test PRIVATE gtest ${CMAKE_DL_LIBS} Shlwapi - )# Link to dl + target_link_libraries(plugin_test PRIVATE gtest ${CMAKE_DL_LIBS} Shlwapi) # Link to dl add_custom_command( TARGET plugin_test POST_BUILD - COMMAND - ${CMAKE_COMMAND} -E copy_if_different - $ - $ + COMMAND ${CMAKE_COMMAND} -E copy_if_different $ + $ COMMAND_EXPAND_LISTS) else() target_link_libraries(plugin_test PRIVATE gtest ${CMAKE_DL_LIBS}) # Link to dl