-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Writing of the configuration and associated class hnz config Development of the HNZ class that encapsulates two HNZ servers and communicates with an HNZ and Fledge client Parsing of the hnz configuration by hnz_config Addition of a utility class to concentrate reusable functions in the plugin Addition of an HNZ server in enhanced_hnz_server Addition of CMAKE for building the plugin and tests Development of unit tests for the plugin and configuration information Signed-off-by: Ludovic Le Brun <[email protected]>
- Loading branch information
1 parent
e60204e
commit 59e5217
Showing
36 changed files
with
9,289 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,114 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
inputs: | ||
libhnz_branch: | ||
description: 'Branch to use for libhnz' | ||
required: true | ||
default: 'main' | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-20.04 | ||
env: | ||
SONAR_SCANNER_VERSION: 5.0.1.3006 # Find the latest version in the "Windows" link on this page: | ||
# https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/ | ||
SONAR_SERVER_URL: "https://sonarcloud.io" | ||
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'zulu' | ||
- name: Cache SonarQube packages | ||
uses: actions/cache@v1 | ||
with: | ||
path: ~/.sonar/cache | ||
key: ${{ runner.os }}-sonar | ||
restore-keys: ${{ runner.os }}-sonar | ||
- name: Download and set up sonar-scanner | ||
env: | ||
SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip | ||
run: | | ||
mkdir -p $HOME/.sonar | ||
curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }} | ||
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ | ||
echo "$HOME/.sonar/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin" >> $GITHUB_PATH | ||
- name: Download and set up build-wrapper | ||
env: | ||
BUILD_WRAPPER_DOWNLOAD_URL: ${{ env.SONAR_SERVER_URL }}/static/cpp/build-wrapper-linux-x86.zip | ||
run: | | ||
curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip ${{ env.BUILD_WRAPPER_DOWNLOAD_URL }} | ||
unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/ | ||
echo "$HOME/.sonar/build-wrapper-linux-x86" >> $GITHUB_PATH | ||
- name: Download and install Fledge | ||
env: | ||
FLEDGE_REPO_URL: "https://github.com/fledge-iot/fledge/archive/refs/heads/develop.zip" | ||
run: | | ||
curl -sSLo fledge-pkg.zip ${{ env.FLEDGE_REPO_URL }} | ||
unzip -o fledge-pkg.zip -d $HOME | ||
mv $HOME/fledge-develop $HOME/fledge | ||
cd $HOME/fledge | ||
sudo apt-get update | ||
sudo apt-get install libcurl4-openssl-dev | ||
sudo $HOME/fledge/requirements.sh | ||
sudo make install | ||
sudo mkdir -p /usr/include/fledge/rapidjson/ | ||
find $HOME/fledge/C/common/ -name '*.h' -exec sudo cp -prv '{}' '/usr/include/fledge/' ';' | ||
find $HOME/fledge/C/plugins/ -name '*.h' -exec sudo cp -prv '{}' '/usr/include/fledge/' ';' | ||
find $HOME/fledge/C/services/ -name '*.h' -exec sudo cp -prv '{}' '/usr/include/fledge/' ';' | ||
find $HOME/fledge/C/tasks/ -name '*.h' -exec sudo cp -prv '{}' '/usr/include/fledge/' ';' | ||
sudo cp -prv $HOME/fledge/C/thirdparty/rapidjson/include/rapidjson/* /usr/include/fledge/rapidjson/ | ||
sudo mkdir -p /usr/lib/fledge/ | ||
sudo cp -prv /usr/local/fledge/lib/* /usr/lib/fledge/ | ||
- name: Download and install libhnz | ||
env: | ||
LIBHNZ_REPO_URL: "https://github.com/fledge-power/libhnz.git" | ||
LIBHNZ_BRANCH: ${{ github.event.inputs.libhnz_branch || 'main' }} | ||
run: | | ||
cd $HOME | ||
git clone ${{ env.LIBHNZ_REPO_URL }} | ||
cd $HOME/libhnz | ||
git checkout ${{ env.LIBHNZ_BRANCH }} | ||
cd $HOME/libhnz/src/hnz | ||
./compilation.sh | ||
- name: Download and install Google Unit Test framework | ||
run: | | ||
sudo apt-get install libgtest-dev | ||
cd /usr/src/gtest | ||
sudo cmake CMakeLists.txt | ||
sudo make | ||
sudo apt-get install libgmock-dev | ||
- name: Download and install gcovr | ||
run: | | ||
sudo apt-get install gcovr | ||
- name: Run build-wrapper | ||
run: | | ||
chmod +x mkversion | ||
export LD_LIBRARY_PATH=/usr/lib:/usr/local/lib | ||
export LIB_HNZ=$HOME/libhnz | ||
mkdir build | ||
cmake -S . -B build -DCMAKE_BUILD_TYPE=Coverage | ||
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build/ --config Release | ||
cd build | ||
make | ||
make hnz_coverage_sonar | ||
- name: Run sonar-scanner | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
run: | | ||
sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" --define sonar.organization="fledge-power" --define sonar.projectKey="fledge-power_fledge-north-hnz" --define sonar.inclusions="src/*,include/*" --define sonar.coverageReportPaths="build/hnz_coverage_sonar-sonarqube.xml" | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,5 @@ | |
*.exe | ||
*.out | ||
*.app | ||
|
||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
cmake_minimum_required(VERSION 2.8) | ||
|
||
# Set the plugin name to build | ||
project(hnz) | ||
|
||
message("fledge root : ${FLEDGE_ROOT}") | ||
# Supported options: | ||
# -DFLEDGE_INCLUDE | ||
# -DFLEDGE_LIB | ||
# -DFLEDGE_SRC | ||
# -DFLEDGE_INSTALL | ||
# | ||
# If no -D options are given and FLEDGE_ROOT environment variable is set | ||
# then Fledge libraries and header files are pulled from FLEDGE_ROOT path. | ||
|
||
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") | ||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
|
||
if (${CMAKE_BUILD_TYPE} STREQUAL Coverage) | ||
message("Coverage is going to be generated") | ||
enable_testing() | ||
add_subdirectory(tests) | ||
include(CodeCoverage) | ||
append_coverage_compiler_flags() | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 --coverage") | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 --coverage") | ||
set(GCOVR_ADDITIONAL_ARGS "--exclude-unreachable-branches" "--exclude-throw-branches" ) | ||
|
||
setup_target_for_coverage_gcovr_sonar(NAME "${PROJECT_NAME}_coverage_sonar" | ||
EXECUTABLE RunTests | ||
DEPENDENCIES RunTests | ||
BASE_DIRECTORY "${PROJECT_SOURCE_DIR}" | ||
EXCLUDE "tests/*" | ||
) | ||
|
||
setup_target_for_coverage_gcovr_html(NAME "${PROJECT_NAME}_coverage_html" | ||
EXECUTABLE RunTests | ||
DEPENDENCIES RunTests | ||
BASE_DIRECTORY "${PROJECT_SOURCE_DIR}" | ||
EXCLUDE "tests/*" | ||
) | ||
message(STATUS "Using Fledge dev package includes2 " ${FLEDGE_INCLUDE}) | ||
else() | ||
message("Build without Coverage") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") | ||
endif() | ||
|
||
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -ggdb") | ||
|
||
# Generation version header file | ||
set_source_files_properties(version.h PROPERTIES GENERATED TRUE) | ||
add_custom_command( | ||
OUTPUT version.h | ||
DEPENDS ${CMAKE_SOURCE_DIR}/VERSION | ||
COMMAND ${CMAKE_SOURCE_DIR}/mkversion ${CMAKE_SOURCE_DIR} | ||
COMMENT "Generating version header" | ||
VERBATIM | ||
) | ||
include_directories(${CMAKE_BINARY_DIR}) | ||
|
||
|
||
# Set plugin type (south, north, filter) | ||
set(PLUGIN_TYPE "north") | ||
# Add here all needed Fledge libraries as list | ||
set(NEEDED_FLEDGE_LIBS common-lib) | ||
|
||
# Find source files | ||
file(GLOB SOURCES src/*.cpp) | ||
|
||
# Find Fledge includes and libs, by including FindFledge.cmake file | ||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}) | ||
find_package(Fledge) | ||
# If errors: make clean and remove Makefile | ||
if (NOT FLEDGE_FOUND) | ||
if (EXISTS "${CMAKE_BINARY_DIR}/Makefile") | ||
execute_process(COMMAND make clean WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) | ||
file(REMOVE "${CMAKE_BINARY_DIR}/Makefile") | ||
endif() | ||
# Stop the build process | ||
message(FATAL_ERROR "Fledge plugin '${PROJECT_NAME}' build error.") | ||
endif() | ||
# On success, FLEDGE_INCLUDE_DIRS and FLEDGE_LIB_DIRS variables are set | ||
|
||
|
||
# Check that HNZ lib environment var is set | ||
if (DEFINED ENV{LIB_HNZ}) | ||
set(LIB_HNZ "$ENV{LIB_HNZ}") | ||
else() | ||
message(FATAL_ERROR "The env var LIB_HNZ is not set. You must define it in order to compile the plugin.") | ||
return() | ||
endif() | ||
|
||
if (NOT EXISTS "${LIB_HNZ}/src/") | ||
message(FATAL_ERROR "LIB_HNZ $(LIB_HNZ)/src \n" | ||
"does not appear to be pointing at a valid libhnz source tree") | ||
return() | ||
endif() | ||
|
||
# Add ./include | ||
include_directories(include) | ||
# Add Fledge include dir(s) | ||
include_directories(${FLEDGE_INCLUDE_DIRS}) | ||
|
||
# Add Fledge lib path | ||
link_directories(${FLEDGE_LIB_DIRS}) | ||
# Create shared library | ||
link_directories(${LIB_HNZ}/src/hnz) | ||
|
||
# Add other include paths | ||
if (FLEDGE_SRC) | ||
message(STATUS "Using third-party includes " ${FLEDGE_SRC}/C/thirdparty) | ||
include_directories(${FLEDGE_SRC}/C/thirdparty/rapidjson/include) | ||
endif() | ||
message(STATUS "Using hnz lib " ${LIB_HNZ}/src/inc) | ||
include_directories(${LIB_HNZ}/src/inc) | ||
|
||
# Create shared library | ||
add_library(${PROJECT_NAME} SHARED ${SOURCES} version.h) | ||
|
||
# Add Fledge library names | ||
target_link_libraries(${PROJECT_NAME} ${NEEDED_FLEDGE_LIBS}) | ||
|
||
# Add the hnz lib | ||
find_library(LIBHNZ libhnz.so "${LIB_HNZ}/src/hnz/") | ||
if (LIBHNZ-NOTFOUND) | ||
message(FATAL_ERROR "The HNZ library libhnz was not found in ${LIB_HNZ}/src/hnz/\n" | ||
"Please build the library and set the environment variable LIB_HNZ to root of libhnz source tree") | ||
return() | ||
endif() | ||
target_link_libraries(${PROJECT_NAME} -L${LIB_HNZ}/src/hnz libhnz) | ||
|
||
# Add additional libraries | ||
target_link_libraries(${PROJECT_NAME} -lpthread -ldl) | ||
|
||
# Set the build version | ||
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION 1) | ||
|
||
set(FLEDGE_INSTALL "" CACHE INTERNAL "") | ||
# Install library | ||
if (FLEDGE_INSTALL) | ||
message(STATUS "Installing ${PROJECT_NAME} in ${FLEDGE_INSTALL}/plugins/${PLUGIN_TYPE}/${PROJECT_NAME}") | ||
install(TARGETS ${PROJECT_NAME} DESTINATION ${FLEDGE_INSTALL}/plugins/${PLUGIN_TYPE}/${PROJECT_NAME}) | ||
endif() |
Oops, something went wrong.