Skip to content

Commit

Permalink
Add workflow to build deb packages
Browse files Browse the repository at this point in the history
Add cmake_format.py to improve cmake formatting in pre-commit: modify all cmake files
  • Loading branch information
bruno-at-orange committed Sep 18, 2024
1 parent 99179b8 commit 8db4984
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 126 deletions.
7 changes: 7 additions & 0 deletions .cmake-format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
with section("format"):
line_width = 120
tab_size = 2
line_ending = "auto"

with section("markup"):
bullet_char = "-"
62 changes: 62 additions & 0 deletions .github/workflows/pack-debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
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 curl
apt-get -y install ninja-build
apt-get -y install zip pkg-config # for vcpkkg
curl -LO "https://github.com/Kitware/CMake/releases/download/v3.30.3/cmake-3.30.3-linux-x86_64.sh"
bash cmake-3.30.3-linux-x86_64.sh --prefix=/usr/local/ --exclude-subdir
- name: Checkout sources
uses: actions/checkout@v4
with:
submodules: true
- name: Configure CMake
run: |
cmake -B builds -S . -G Ninja -D CMAKE_BUILD_TYPE=Release -D CMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake
cmake -S . -B builds -G Ninja -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

76 changes: 29 additions & 47 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down Expand Up @@ -40,45 +39,34 @@ 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/>)
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 $<$<CONFIG:RELEASE>:-s>
)# stripping
target_link_libraries(khiopsdriver_file_gcs PRIVATE google-cloud-cpp::storage
spdlog::spdlog)
target_link_options(khiopsdriver_file_gcs PRIVATE $<$<CONFIG:RELEASE>:-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
Expand All @@ -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)
Expand All @@ -111,8 +98,7 @@ set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_VENDOR "Orange")
set(CPACK_PACKAGE_CONTACT "Khiops Team <[email protected]>")
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")

Expand All @@ -131,33 +117,31 @@ 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")

# 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)
Expand All @@ -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)
96 changes: 34 additions & 62 deletions cmake/modules/CodeCoverage.cmake
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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...")
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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.")

Expand Down
Loading

0 comments on commit 8db4984

Please sign in to comment.