Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes an outrageous number of bugs and warnings #90

Merged
merged 23 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/clang-format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Run clang-format style check for C/C++ programs.
uses: jidicula/clang-format-action@v4.6.2
uses: jidicula/clang-format-action@v4.14.0
with:
clang-format-version: '14'
clang-format-version: '19'
check-path: 'src'

118 changes: 59 additions & 59 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ cmake_minimum_required(VERSION 3.26.5)

# Only set the cxx_standard if it is not set by someone else
if (NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 23)
endif()
set(CMAKE_CXX_STANDARD 23)
endif ()

# strongly encouraged to enable this globally to avoid conflicts between
# -Wpedantic being enabled and -std=c++20 and -std=gnu++20 for example
Expand All @@ -18,34 +18,34 @@ set(CMAKE_CXX_EXTENSIONS OFF)

# Enable Conan 2.0 support
option(cloysterhpc_ENABLE_CONAN "Use Conan 2 to manage dependencies" ON)
if(cloysterhpc_ENABLE_CONAN)
set(CMAKE_PROJECT_TOP_LEVEL_INCLUDES cmake/conan_provider.cmake)
endif()
if (cloysterhpc_ENABLE_CONAN)
set(CMAKE_PROJECT_TOP_LEVEL_INCLUDES cmake/conan_provider.cmake)
endif ()

# Set a default build type if none was specified
# This is required for Conan 2.0 to work properly
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE
Debug
CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui, ccmake
set_property(
CACHE CMAKE_BUILD_TYPE
PROPERTY STRINGS
"Debug"
"Release"
"MinSizeRel"
"RelWithDebInfo")
endif()
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Debug' as none was specified.")
set(CMAKE_BUILD_TYPE
Debug
CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui, ccmake
set_property(
CACHE CMAKE_BUILD_TYPE
PROPERTY STRINGS
"Debug"
"Release"
"MinSizeRel"
"RelWithDebInfo")
endif ()

# Set the project name and language
project(
CloysterHPC
VERSION 0.1.1
DESCRIPTION "Cloyster HPC is a turnkey HPC cluster solution with an user-friendly installer"
HOMEPAGE_URL "https://github.com/viniciusferrao/cloysterhpc"
LANGUAGES CXX C)
CloysterHPC
VERSION 0.1.1
DESCRIPTION "Cloyster HPC is a turnkey HPC cluster solution with an user-friendly installer"
HOMEPAGE_URL "https://github.com/viniciusferrao/cloysterhpc"
LANGUAGES CXX C)

include(cmake/PreventInSourceBuilds.cmake)
include(ProjectOptions.cmake)
Expand All @@ -71,16 +71,16 @@ execute_process(
)

# Check if GIT_SHA is empty and set to "Unknown" if it is
if("${GIT_SHA}" STREQUAL "")
set(GIT_SHA "Unknown")
endif()
if ("${GIT_SHA}" STREQUAL "")
set(GIT_SHA "Unknown")
endif ()

# Get the short SHA (first 8 characters) if GIT_SHA is not "Unknown"
if(NOT "${GIT_SHA}" STREQUAL "Unknown")
string(SUBSTRING "${GIT_SHA}" 0 8 GIT_SHORT_SHA)
else()
set(GIT_SHORT_SHA "Unknown")
endif()
if (NOT "${GIT_SHA}" STREQUAL "Unknown")
string(SUBSTRING "${GIT_SHA}" 0 8 GIT_SHORT_SHA)
else ()
set(GIT_SHORT_SHA "Unknown")
endif ()

# Cache the variables for future use
set(GIT_SHA "${GIT_SHA}" CACHE STRING "SHA this build was generated from")
Expand All @@ -105,51 +105,51 @@ add_subdirectory(configured_files)
add_subdirectory(src)

# Don't even look at tests if we're not top level
if(NOT PROJECT_IS_TOP_LEVEL)
return()
endif()
if (NOT PROJECT_IS_TOP_LEVEL)
return()
endif ()

# Adding the tests:
include(CTest)

if(BUILD_TESTING)
add_subdirectory(test)
endif()
if (BUILD_TESTING)
add_subdirectory(test)
endif ()


if(cloysterhpc_BUILD_FUZZ_TESTS)
message(AUTHOR_WARNING "Building Fuzz Tests, using fuzzing sanitizer https://www.llvm.org/docs/LibFuzzer.html")
if (NOT cloysterhpc_ENABLE_ADDRESS_SANITIZER AND NOT cloysterhpc_ENABLE_THREAD_SANITIZER)
message(WARNING "You need asan or tsan enabled for meaningful fuzz testing")
endif()
add_subdirectory(fuzz_test)
if (cloysterhpc_BUILD_FUZZ_TESTS)
message(AUTHOR_WARNING "Building Fuzz Tests, using fuzzing sanitizer https://www.llvm.org/docs/LibFuzzer.html")
if (NOT cloysterhpc_ENABLE_ADDRESS_SANITIZER AND NOT cloysterhpc_ENABLE_THREAD_SANITIZER)
message(WARNING "You need asan or tsan enabled for meaningful fuzz testing")
endif ()
add_subdirectory(fuzz_test)

endif()
endif ()

# If MSVC is being used, and ASAN is enabled, we need to set the debugger environment
# so that it behaves well with MSVC's debugger, and we can run the target from visual studio
if(MSVC)
get_all_installable_targets(all_targets)
message("all_targets=${all_targets}")
set_target_properties(${all_targets} PROPERTIES VS_DEBUGGER_ENVIRONMENT "PATH=$(VC_ExecutablePath_x64);%PATH%")
endif()
if (MSVC)
get_all_installable_targets(all_targets)
message("all_targets=${all_targets}")
set_target_properties(${all_targets} PROPERTIES VS_DEBUGGER_ENVIRONMENT "PATH=$(VC_ExecutablePath_x64);%PATH%")
endif ()

# set the startup project for the "play" button in MSVC
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT ${cloysterhpc_BINARY_NAME})

if(CMAKE_SKIP_INSTALL_RULES)
return()
endif()
if (CMAKE_SKIP_INSTALL_RULES)
return()
endif ()

include(cmake/PackageProject.cmake)

# Add other targets that you want installed here, by default we just package the one executable
# we know we want to ship
cloysterhpc_package_project(
TARGETS
${cloysterhpc_BINARY_NAME}
cloysterhpc_options
cloysterhpc_warnings
# FIXME: this does not work! CK
# PRIVATE_DEPENDENCIES_CONFIGURED project_options project_warnings
TARGETS
${cloysterhpc_BINARY_NAME}
cloysterhpc_options
cloysterhpc_warnings
# FIXME: this does not work! CK
# PRIVATE_DEPENDENCIES_CONFIGURED project_options project_warnings
)
4 changes: 3 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"condition": {
"type": "inList",
"string": "${hostSystemName}",
"list": ["Linux"]
"list": [
"Linux"
]
},
"vendor": {
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
Expand Down
4 changes: 4 additions & 0 deletions cmake/CompilerWarnings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ function(
-Wduplicated-branches # warn if if / else branches have duplicated code
-Wlogical-op # warn about logical operations being used where bitwise were probably wanted
-Wuseless-cast # warn if you perform a cast to the same type
-Wno-unused-variable
-Wno-unused-function
-Wno-unused-parameter
-Wno-shadow
)
endif()

Expand Down
16 changes: 16 additions & 0 deletions cmake/StaticAnalyzers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ macro(cloysterhpc_enable_cppcheck WARNINGS_AS_ERRORS CPPCHECK_OPTIONS)
# style should enable the other 3, but we'll be explicit just in case
set(CMAKE_CXX_CPPCHECK
${CPPCHECK}
--quiet
--template=${CPPCHECK_TEMPLATE}
--enable=style,performance,warning,portability
--inline-suppr
Expand All @@ -26,6 +27,21 @@ macro(cloysterhpc_enable_cppcheck WARNINGS_AS_ERRORS CPPCHECK_OPTIONS)
# ignores code that cppcheck thinks is invalid C++
--suppress=syntaxError
--suppress=preprocessorErrorDirective
# FIXME: The below warnings were disabled to underflow the devopment
# they should be enabled again
--suppress=functionStatic
--suppress=functionConst
--suppress=funcArgNamesDifferent
--suppress=unusedPrivateFunction
--suppress=constVariable
--suppress=missingOverride
--suppress=useStlAlgorithm
--suppress=constParameter
--suppress=noExplicitConstructor
--suppress=duplicateBreak
--suppress=variableScope
--suppress=unreadVariable
--suppress=shadowFunction
--inconclusive)
else()
# if the user provides a CPPCHECK_OPTIONS with a template specified, it will override this template
Expand Down
19 changes: 9 additions & 10 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
[requires]
cli11/2.3.2
# libfmt version will be automatically selected by spdlog
fmt/10.2.1
spdlog/[>=1.14.0]
boost/1.82.0
magic_enum/0.9.2
gsl-lite/0.40.0
doctest/2.4.11
cryptopp/8.9.0
sdbus-cpp/2.0.0
cli11/[>=2.4.0 <2.5.0]
spdlog/[>=1.14.0 <1.15.0]
fmt/[>=10.0.0 <12.0.0]
boost/[>=1.83.0 <1.84.0]
magic_enum/[>=0.9.0 <0.10.0]
gsl-lite/[>=0.41.0 <0.42.0]
doctest/[>=2.4.0 <2.5.0]
cryptopp/[>=8.9.0 <8.10.0]
sdbus-cpp/[>=2.0.0 <2.1.0]

[layout]
cmake_layout
16 changes: 8 additions & 8 deletions fuzz_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ find_package(fmt)

add_executable(fuzz_tester fuzz_tester.cpp)
target_link_libraries(
fuzz_tester
PRIVATE cmake_conan2_template_options
cmake_conan2_template_warnings
fmt::fmt
-coverage
-fsanitize=fuzzer)
fuzz_tester
PRIVATE cmake_conan2_template_options
cmake_conan2_template_warnings
fmt::fmt
-coverage
-fsanitize=fuzzer)
target_compile_options(fuzz_tester PRIVATE -fsanitize=fuzzer)

# Allow short runs during automated testing to see if something new breaks
set(FUZZ_RUNTIME
10
CACHE STRING "Number of seconds to run fuzz tests during ctest run") # Default of 10 seconds
10
CACHE STRING "Number of seconds to run fuzz tests during ctest run") # Default of 10 seconds

add_test(NAME fuzz_tester_run COMMAND fuzz_tester -max_total_time=${FUZZ_RUNTIME})
1 change: 0 additions & 1 deletion include/cloysterhpc/answerfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <cloysterhpc/inifile.h>
#include <cloysterhpc/mailsystem/postfix.h>
#include <optional>
#include <utility>
#include <vector>

using boost::asio::ip::address;
Expand Down
5 changes: 2 additions & 3 deletions include/cloysterhpc/dbus_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ class DBusClient : public MessageBus {
public:
DBusClient(std::string bus, std::string object)
: m_proxy(
sdbus::createProxy(std::move(sdbus::createSystemBusConnection()),
std::move(sdbus::ServiceName { bus }),
std::move(sdbus::ObjectPath { object })))
sdbus::createProxy(std::move(sdbus::createSystemBusConnection()),
sdbus::ServiceName { bus }, sdbus::ObjectPath { object }))
{
}

Expand Down
4 changes: 2 additions & 2 deletions include/cloysterhpc/diskImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class DiskImage {
* @param path Filesystem path to the disk image to check.
* @return True if the disk image is known, false otherwise.
*/
bool isKnownImage(const std::filesystem::path& path);
static bool isKnownImage(const std::filesystem::path& path);

/**
* @brief Checks if the given disk image has a verified checksum.
*
Expand Down
8 changes: 8 additions & 0 deletions include/cloysterhpc/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ std::string getCurrentTimestamp();
std::string findAndReplace(const std::string_view& source,
const std::string_view& find, const std::string_view& replace);

/**
* @brief Copies a file, skip copying if it exists
*
* @param source The source file to copy.
* @param destination The path where the source file will be copied.
*/
void copyFile(std::filesystem::path source, std::filesystem::path destination);

} /* namespace cloyster */

#endif // CLOYSTERHPC_FUNCTIONS_H_
6 changes: 3 additions & 3 deletions include/cloysterhpc/messagebus.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* tell this to the user
*/
template <typename T>
concept MessageReturnable = std::is_nothrow_default_constructible_v<
T> && std::is_nothrow_move_constructible_v<T>;
concept MessageReturnable = std::is_nothrow_default_constructible_v<T>
&& std::is_nothrow_move_constructible_v<T>;

/**
* A more or less "generic"-ish way to refer to a message reply
Expand Down Expand Up @@ -107,7 +107,7 @@ class MessageBusMethod {
virtual MessageReply callMethod() = 0;

public:
void addParams()
static void addParams()
{
// end case for the variadic template below
}
Expand Down
3 changes: 2 additions & 1 deletion include/cloysterhpc/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class Node : public Server {
const std::string& getMACAddress() const;
void setMACAddress(const std::string& macAddress);
const std::optional<std::string>& getNodeRootPassword() const;
void setNodeRootPassword(const std::optional<std::string>& ndeRootPassword);
void setNodeRootPassword(
const std::optional<std::string>& nodeRootPassword);
};

#endif // CLOYSTERHPC_NODE_H_
Loading
Loading