Skip to content

Commit

Permalink
Merge pull request #159 from jgaa/staging
Browse files Browse the repository at this point in the history
Fixing compiler warnings and static code analyzer warnings, macos and github actions
  • Loading branch information
jgaa authored Aug 17, 2024
2 parents b063b5a + c688196 commit b92b0ad
Show file tree
Hide file tree
Showing 41 changed files with 886 additions and 756 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: CI

on:
push:
pull_request:
schedule:
- cron: '0 0 1 * *' # This line schedules the workflow to run at 00:00 on the first day of every month

defaults:
run:
shell: bash

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
compiler: gcc
- os: ubuntu-latest
compiler: clang
- os: windows-latest
compiler: msvc
- os: macos-latest
compiler:

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: true

- name: Cache
uses: actions/cache@v4
with:
path: |
~/vcpkg
~/vcpkg_installed
${{ env.HOME }}/.cache/vcpkg/archives
${{ env.XDG_CACHE_HOME }}/vcpkg/archives
${{ env.LOCALAPPDATA }}\vcpkg\archives
${{ env.APPDATA }}\vcpkg\archives
key: ${{ runner.os }}-${{ matrix.compiler }}-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('./vcpkg.json')}}
restore-keys: |
${{ runner.os }}-${{ env.BUILD_TYPE }}-
- name: Setup Cpp
uses: aminya/setup-cpp@v1
with:
compiler: ${{ matrix.compiler }}
vcvarsall: ${{ contains(matrix.os, 'windows') }}
cmake: true
ninja: true
vcpkg: true
cppcheck: false

- name: Install compiler for Macos
if: startsWith(matrix.os, 'macos')
run: |
brew install llvm
- name: Prepare the PATH
run: |
if [[ "${{ runner.os }}" == "Windows" ]]; then
echo "$env:USERPROFILE\vcpkg" >> $GITHUB_PATH
echo "$env:USERPROFILE\ninja" >> $GITHUB_PATH
else
echo "$HOME/vcpkg" >> $GITHUB_PATH
echo "$HOME/ninja" >> $GITHUB_PATH
fi
- name: Install dependencies
run: |
cp -v ci/vcpkg/vcpkg.json .
vcpkg install
- name: Build project
run: |
pushd ~
if [ -d build ]; then
echo "Build dir exists"
ls -la build
else
mkdir -v build
fi
cd build
pwd
set -x
cmake -DVCPKG_INSTALLED_DIR=~/vcpkg_installed -DVCPKG_VERBOSE=ON -DRESTC_CPP_THREADED_CTX=ON -DCMAKE_BUILD_TYPE=Release -G "Ninja" -DCMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake ${GITHUB_WORKSPACE}
cmake --build .
popd
continue-on-error: true

- name: Dump diagnostics
if: failure()
run: |
cd ~/build
echo "---------------------------------"
cat build.ninja
echo "---------------------------------"
- name: Run Unit Tests
run: |
pushd ~/build
ctest -R UNITTESTS . -C Release
popd
32 changes: 11 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
cmake_minimum_required(VERSION 3.10)

# if (UNIX)
# # Ninja creates too many problems while maintaining
# # compatibility with old and new versions of Linux/Cmake
# set (CMAKE_GENERATOR "Unix Makefiles" CACHE INTERNAL "" FORCE)
# endif()

if (DEFINED ENV{RESTC_CPP_VERSION})
set(RESTC_CPP_VERSION $ENV{RESTC_CPP_VERSION})
endif()

if (NOT DEFINED RESTC_CPP_VERSION)
set(RESTC_CPP_VERSION 0.100.0)
set(RESTC_CPP_VERSION 0.101.0)
endif()

if(NOT DEFINED RESTC_BOOST_VERSION)
Expand All @@ -24,9 +18,15 @@ message(STATUS "Building restc-cpp version ${PROJECT_VERSION}")

include(CheckCXXCompilerFlag)

check_cxx_compiler_flag("-std=c++20" COMPILER_SUPPORTS_CXX20)
check_cxx_compiler_flag("-std=c++17" COMPILER_SUPPORTS_CXX17)

if (MSVC)
# Thank you Microsoft. Its so nice of you to give us all these meaningful reasons to stay up all night.
check_cxx_compiler_flag("/std:c++20" COMPILER_SUPPORTS_CXX20)
check_cxx_compiler_flag("/std:c++17" COMPILER_SUPPORTS_CXX17)
add_compile_options(/Zc:__cplusplus)
else()
check_cxx_compiler_flag("-std=c++20" COMPILER_SUPPORTS_CXX20)
check_cxx_compiler_flag("-std=c++17" COMPILER_SUPPORTS_CXX17)
endif()

if (NOT DEFINED INSTALL_RAPIDJSON_HEADERS)
option(INSTALL_RAPIDJSON_HEADERS "Install rapidjson headers when make install is executed" ON)
Expand Down Expand Up @@ -229,13 +229,7 @@ if (RESTC_CPP_WITH_ZLIB)
set(ACTUAL_SOURCES ${ACTUAL_SOURCES} src/ZipReaderImpl.cpp)
endif()

if (WIN32)
include(cmake_scripts/pch.cmake)
ADD_MSVC_PRECOMPILED_HEADER(restc-cpp/restc-cpp.h src/pch.cpp ACTUAL_SOURCES)
set(SOURCES ${ACTUAL_SOURCES} src/pch.cpp ${HEADERS} ${RESFILES})
else()
set(SOURCES ${ACTUAL_SOURCES})
endif()
set(SOURCES ${ACTUAL_SOURCES})

add_library(${PROJECT_NAME} ${SOURCES})
set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_OUTPUT_NAME restc-cppD)
Expand Down Expand Up @@ -304,10 +298,6 @@ if (NOT EMBEDDED_RESTC_CPP)
link_directories(${Boost_LIBRARY_DIRS})
endif()

include(cmake_scripts/pch.cmake)

set_property(TARGET PROPERTY CXX_STANDARD 17)

if(WIN32)
add_definitions(-D_WIN32_WINNT=0x0600)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![CI](https://github.com/jgaa/restc-cpp/actions/workflows/ci.yaml/badge.svg)](https://github.com/jgaa/restc-cpp/actions/workflows/ci.yaml)

# Introduction to the restc-cpp C++ library
<i>The magic that takes the pain out of accessing JSON API's from C++ </i>

Expand Down
62 changes: 31 additions & 31 deletions ci/jenkins/Jenkinsfile.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pipeline {
agent { label 'main' }

environment {
RESTC_CPP_VERSION = "0.100.0"
RESTC_CPP_VERSION = "0.101.0"

// It is not possible to get the current IP number when running in the sandbox, and
// Jenkinsfiles always runs in the sandbox.
Expand All @@ -24,6 +24,35 @@ pipeline {
stage('Build') {
parallel {

stage('macOS') {
agent {label 'macos'}

// environment {
// CPPFLAGS = "-I/usr/local/opt/openssl/include -I/usr/local/opt/zlib/include -I/usr/local/opt/boost/include/"
// LDFLAGS = "-L/usr/local/opt/openssl/lib -L/usr/local/opt/zlib/lib -L/usr/local/opt/boost/lib/"
// }

steps {
echo "Building on macos in ${WORKSPACE}"
sh 'brew install openssl boost zlib rapidjson googletest cmake ninja'
checkout scm
sh 'pwd; ls -la'
sh 'rm -rf build'
sh 'mkdir build'
sh 'cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make -j4'

echo 'Getting ready to run tests'
script {
try {
sh 'cd build && ctest --no-compress-output -T Test'
} catch (exc) {
echo 'Testing failed'
currentBuild.result = 'UNSTABLE'
}
}
}
}

stage('Ubuntu Noble') {
agent {
dockerfile {
Expand Down Expand Up @@ -530,36 +559,7 @@ pipeline {
sh 'rm -rf build-fedora'
}
}
//
// stage('Centos7') {
// agent {
// dockerfile {
// filename 'Dockerfile.centos7'
// dir 'ci/jenkins'
// label 'docker'
// }
// }
//
// steps {
// echo "Building on Centos7 in ${WORKSPACE}"
// checkout scm
// sh 'pwd; ls -la'
// sh 'rm -rf build'
// sh 'mkdir build'
// sh 'cd build && source scl_source enable devtoolset-7 && cmake -DCMAKE_BUILD_TYPE=Release -DBOOST_ROOT=/opt/boost .. && make'
//
// echo 'Getting ready to run tests'
// script {
// try {
// sh 'cd build && ctest --no-compress-output -T Test'
// } catch (exc) {
//
// unstable(message: "${STAGE_NAME} - Testing failed")
// }
// }
// }
// }


stage('Windows X64 with vcpkg') {

agent {label 'windows'}
Expand Down
22 changes: 22 additions & 0 deletions ci/vcpkg/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "restc-cpp",
"license": "MIT",
"dependencies": [
"boost-scope-exit",
"boost-system",
"boost-context",
"boost-coroutine",
"boost-filesystem",
"boost-asio",
"boost-chrono",
"boost-date-time",
"boost-log",
"boost-uuid",
"boost-program-options",
"boost-functional",
"zlib",
"openssl",
"gtest",
"rapidjson"
]
}
21 changes: 7 additions & 14 deletions examples/logip/logip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ BOOST_FUSION_ADAPT_STRUCT(

string now() {
char date[32] = {};
auto now = time(NULL);
auto now = time(nullptr);
strftime(date, sizeof(date), "%Y-%m-%d %H:%M", localtime(&now));
return date;
}

int main(int argc, char *argv[]) {
int main(int /*argc*/, char * /*argv*/[])
{
#ifdef RESTC_CPP_LOG_WITH_BOOST_LOG
namespace logging = boost::log;
logging::core::get()->set_filter
Expand All @@ -71,22 +72,14 @@ int main(int argc, char *argv[]) {
.Execute());
valid = true;
} catch (const boost::exception& ex) {
clog << now()
<< "Caught boost exception: "
<< boost::diagnostic_information(ex)
<< endl;
clog << now() << "Caught boost exception: " << boost::diagnostic_information(ex)
<< '\n';
} catch (const exception& ex) {
clog << now()
<< "Caught exception: "
<< ex.what()
<< endl;
clog << now() << "Caught exception: " << ex.what() << '\n';
}

if (valid && (current_ip != data.ip)) {
clog << now()
<< ' '
<< data.ip
<< endl;
clog << now() << ' ' << data.ip << '\n';
current_ip = data.ip;
}

Expand Down
19 changes: 10 additions & 9 deletions include/restc-cpp/IteratorFromJsonSerializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ class IteratorFromJsonSerializer
public:
using data_t = typename std::remove_const<typename std::remove_reference<objectT>::type>::type;

class Iterator : public std::iterator<
std::input_iterator_tag,
data_t,
std::ptrdiff_t,
const data_t *,
data_t&> {
class Iterator {
public:
using iterator_category = std::input_iterator_tag;
using value_type = data_t;
using difference_type = std::ptrdiff_t;
using pointer = value_type*;
using reference = value_type&;

public:
Iterator() {}
Expand All @@ -42,7 +43,7 @@ class IteratorFromJsonSerializer
}

Iterator(Iterator&& it)
: owner_{it.owner_}, data_{move(it.data_)} {}
: owner_{it.owner_}, data_{std::move(it.data_)} {}

Iterator(IteratorFromJsonSerializer *owner)
: owner_{owner} {}
Expand Down Expand Up @@ -70,7 +71,7 @@ class IteratorFromJsonSerializer

Iterator& operator = (Iterator&& it) {
owner_ = it.owner_;
it.data_ = move(it.data_);
it.data_ = std::move(it.data_);
}

bool operator == (const Iterator& other) const {
Expand Down Expand Up @@ -170,7 +171,7 @@ class IteratorFromJsonSerializer
RapidJsonDeserializer<objectT> handler(
*data, *properties_);
json_reader_.Parse(reply_stream_, handler);
return move(data);
return std::move(data);
} else if (ch == ']') {
reply_stream_.Take();
state_ = State::DONE;
Expand Down
Loading

0 comments on commit b92b0ad

Please sign in to comment.