Skip to content

Commit

Permalink
feat: Windows mocked compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
ncvicchi committed Sep 18, 2024
1 parent da7a0eb commit 21640a3
Show file tree
Hide file tree
Showing 44 changed files with 443 additions and 359 deletions.
16 changes: 10 additions & 6 deletions src/common/cmdHelper/include/cmdHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@
* Foundation.
*/

#ifndef _CMD_HELPER_H
#define _CMD_HELPER_H
#pragma once

#include <string>
#include <iostream>
#include <cstdio>
#include <memory>
#include <vector>

#ifndef WIN32
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#else
FILE *popen(const char *command, const char *mode) { return NULL; }
int pclose(FILE *stream){ return 0; }
#endif

namespace Utils
{
Expand All @@ -32,14 +37,14 @@ namespace Utils
static std::string exec(const std::string& cmd, const size_t bufferSize = 128)
{
const std::unique_ptr<FILE, FileSmartDeleter> file{popen(cmd.c_str(), "r")};
char buffer[bufferSize];
std::vector<char> buffer(bufferSize);
std::string result;

if (file)
{
while (fgets(buffer, bufferSize, file.get()))
while (fgets(buffer.data(), bufferSize, file.get()))
{
result += buffer;
result += buffer.data();
}
}

Expand All @@ -49,4 +54,3 @@ namespace Utils

#pragma GCC diagnostic pop

#endif // _CMD_HELPER_H
26 changes: 20 additions & 6 deletions src/common/data_provider/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ include_directories(${SRC_FOLDER}/common/jsonHelper/include/)
include_directories(${SRC_FOLDER}/common/linuxHelper/include/)
include_directories(${SRC_FOLDER}/common/stringHelper/include/)
include_directories(${SRC_FOLDER}/common/timeHelper/include/)
include_directories(${SRC_FOLDER}/common/time_op/include/)
include_directories(${SRC_FOLDER}/common/file_op/include/)
include_directories(${SRC_FOLDER}/common/regex_op/include/)
include_directories(${SRC_FOLDER}/common/debug_op/include/)
include_directories(${SRC_FOLDER}/common/string_op/include/)
include_directories(${SRC_FOLDER}/common/bzip2_op/include/)
include_directories(${SRC_FOLDER}/common/validate_op/include/)
include_directories(${SRC_FOLDER}/common/binaries_op/include/)
include_directories(${SRC_FOLDER}/common/os_xml/include/)
include_directories(${SRC_FOLDER}/common/os_regex/include/)
include_directories(${SRC_FOLDER}/common/os_net/include/)
include_directories(${SRC_FOLDER}/common/expression/include/)
include_directories(${SRC_FOLDER}/common/randombytes/include/)
include_directories(${SRC_FOLDER}/common/error_messages/include/)
include_directories(${SRC_FOLDER}/shared_modules/common/)
include_directories(${SRC_FOLDER}/external/libdb/build_unix/)
if(LINUX)
Expand All @@ -104,9 +118,12 @@ if(LINUX)
include_directories(${SRC_FOLDER}/common/http-request/shared/)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
link_directories(${INSTALL_PREFIX}/lib)
endif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
if(WIN32)
include_directories(${SRC_FOLDER}/common/registryHelper/include/)
include_directories(${SRC_FOLDER}/common/windowsHelper/include/)
include_directories(${SRC_FOLDER}/common/encodingHelper/include/)
include_directories(${SRC_FOLDER}/common/mem_op/include/)
endif()

link_directories(${SRC_FOLDER})
link_directories(${SRC_FOLDER}/external/procps/)
Expand Down Expand Up @@ -196,9 +213,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set_target_properties(sysinfo PROPERTIES
PREFIX ""
SUFFIX ".dll"
LINK_FLAGS "-Wl,--add-stdcall-alias"
POSITION_INDEPENDENT_CODE 0 # this is to avoid MinGW warning;
# MinGW generates position-independent-code for DLL by default
)
elseif(UNIX AND NOT APPLE)
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,-rpath=$ORIGIN")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <netioapi.h>
#include "windowsHelper.h"
#include "inetworkWrapper.h"
#include "makeUnique.h"
#include "sharedDefs.h"

static const std::map<int, std::string> NETWORK_INTERFACE_TYPES =
Expand Down
2 changes: 2 additions & 0 deletions src/common/data_provider/src/ports/portWindowsWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "sharedDefs.h"
#include "stringHelper.h"
#include "windowsHelper.h"
#include "shared.h"
#include "cust_types.h"

static const std::map<int32_t, std::string> STATE_TYPE =
{
Expand Down
2 changes: 1 addition & 1 deletion src/common/dbsync/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS_DEBUG "-g -fsanitize=address,leak,undefined")
endif(FSANITIZE)
else()
set(CMAKE_CXX_FLAGS "/W4 /permissive- /std:c++14 /MT")
set(CMAKE_CXX_FLAGS "/W4 /permissive- /std:c++14 /MT /EHsc")
endif()

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
Expand Down
1 change: 0 additions & 1 deletion src/common/dbsync/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ add_executable(dbsync_example
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(dbsync_example
dbsync
pthread
-static-libgcc -static-libstdc++
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
Expand Down
10 changes: 8 additions & 2 deletions src/common/dbsync/include/db_exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
#include <stdexcept>
#include <string>

#if defined(__GNUC__) || defined(__clang__)
#define ATTR_RET_NONNULL __attribute__((__returns_nonnull__))
#else
#define ATTR_RET_NONNULL
#endif

using DBSyncExceptionType = const std::pair<int, std::string>;

DBSyncExceptionType FACTORY_INSTANTATION { std::make_pair(1, "Unspecified type during factory instantiation") };
Expand Down Expand Up @@ -48,7 +54,7 @@ namespace DbSync
class dbsync_error : public std::exception
{
public:
__attribute__((__returns_nonnull__))
ATTR_RET_NONNULL
const char* what() const noexcept override
{
return m_error.what();
Expand Down Expand Up @@ -82,7 +88,7 @@ namespace DbSync
class max_rows_error : public std::exception
{
public:
__attribute__((__returns_nonnull__))
ATTR_RET_NONNULL
const char* what() const noexcept override
{
return m_error.what();
Expand Down
1 change: 0 additions & 1 deletion src/common/dbsync/src/sqlite/sqlite_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "sqlite_wrapper.h"
#include "db_exception.h"
#include "makeUnique.h"
#include "customDeleter.hpp"
#include <iostream>
#include <chrono>
Expand Down
2 changes: 1 addition & 1 deletion src/common/dbsync/src/sqlite/sqlite_wrapper_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define _SQLITE_WRAPPER_FACTORY_H

#include "sqlite_wrapper.h"
#include "makeUnique.h"

class ISQLiteFactory
{
public:
Expand Down
2 changes: 1 addition & 1 deletion src/common/dbsync/testtool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ endif(COVERITY)
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "-Wall -Wextra -std=c++14 -pthread")
else()
set(CMAKE_CXX_FLAGS "/W4 /permissive- /std:c++14 /MT")
set(CMAKE_CXX_FLAGS "/W4 /permissive- /std:c++14 /MT /EHsc")
if(FSANITIZE)
set(CMAKE_CXX_FLAGS_DEBUG "-fsanitize=address,leak,undefined")
endif(FSANITIZE)
Expand Down
6 changes: 1 addition & 5 deletions src/common/dbsync/testtool/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
* License (version 2) as published by the FSF - Free Software
* Foundation.
*/
#ifndef _ACTION_H
#define _ACTION_H
#pragma once
#include <nlohmann/json.hpp>
#include <mutex>
#include "dbsync.h"
#include "makeUnique.h"
#include "cjsonSmartDeleter.hpp"

namespace TestDeleters
Expand Down Expand Up @@ -828,5 +826,3 @@ struct SelectRowsActionCPP final : public IAction
}
};


#endif //_ACTION_H
1 change: 0 additions & 1 deletion src/common/dbsync/testtool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <stdio.h>
#include <memory>
#include <nlohmann/json.hpp>
#include "makeUnique.h"
#include "dbsync.h"
#include "cmdArgsHelper.h"
#include "testContext.h"
Expand Down
62 changes: 38 additions & 24 deletions src/common/debug_op/include/debug_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ extern "C" {
#endif
#endif

#if defined(__GNUC__) || defined(__clang__)
#define ATTR_NONNULL __attribute__((nonnull))
#define ATTR_NORETURN __attribute__ ((noreturn))
#define ATTR_PRINTF_FIRST_SEC __attribute__((format(_PRINTF_FORMAT, 1, 2)))
#define ATTR_PRINTF_FOURTH_FIFTH __attribute__((format(_PRINTF_FORMAT, 4, 5)))
#define ATTR_PRINTF_FIFTH_SIXTH __attribute__((format(_PRINTF_FORMAT, 5, 6)))
#else
#define ATTR_NONNULL
#define ATTR_NORETURN
#define ATTR_PRINTF_FIRST_SEC
#define ATTR_PRINTF_FOURTH_FIFTH
#define ATTR_PRINTF_FIFTH_SIXTH
#endif

#define mdebug1(msg, ...) _mdebug1(__FILE__, __LINE__, __func__, msg, ##__VA_ARGS__)
#define plain_mdebug1(msg, ...) _plain_mdebug1(__FILE__, __LINE__, __func__, msg, ##__VA_ARGS__)
#define mtdebug1(tag, msg, ...) _mtdebug1(tag, __FILE__, __LINE__, __func__, msg, ##__VA_ARGS__)
Expand All @@ -63,30 +77,30 @@ extern "C" {
#define mterror_exit(tag, msg, ...) _mterror_exit(tag, __FILE__, __LINE__, __func__, msg, ##__VA_ARGS__)
#define mlerror_exit(level, msg, ...) _mlerror_exit(level, __FILE__, __LINE__, __func__, msg, ##__VA_ARGS__)

void _mdebug1(const char * file, int line, const char * func, const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 4, 5))) __attribute__((nonnull));
void _plain_mdebug1(const char * file, int line, const char * func, const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 4, 5))) __attribute__((nonnull));
void _mtdebug1(const char *tag, const char * file, int line, const char * func, const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 5, 6))) __attribute__((nonnull));
void _mdebug2(const char * file, int line, const char * func, const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 4, 5))) __attribute__((nonnull));
void _mtdebug2(const char *tag, const char * file, int line, const char * func, const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 5, 6))) __attribute__((nonnull));
void _merror(const char * file, int line, const char * func, const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 4, 5))) __attribute__((nonnull));
void _plain_merror(const char * file, int line, const char * func, const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 4, 5))) __attribute__((nonnull));
void _mterror(const char *tag, const char * file, int line, const char * func, const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 5, 6))) __attribute__((nonnull));
void _mverror(const char * file, int line, const char * func, const char *msg, va_list args) __attribute__((nonnull));
void _mwarn(const char * file, int line, const char * func, const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 4, 5))) __attribute__((nonnull));
void _plain_mwarn(const char * file, int line, const char * func, const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 4, 5))) __attribute__((nonnull));
void _mtwarn(const char *tag, const char * file, int line, const char * func, const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 5, 6))) __attribute__((nonnull));
void _mvwarn(const char * file, int line, const char * func, const char *msg, va_list args) __attribute__((nonnull));
void _minfo(const char * file, int line, const char * func, const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 4, 5))) __attribute__((nonnull));
void _plain_minfo(const char * file, int line, const char * func, const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 4, 5))) __attribute__((nonnull));
void _mtinfo(const char *tag, const char * file, int line, const char * func, const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 5, 6))) __attribute__((nonnull));
void _mvinfo(const char * file, int line, const char * func, const char *msg, va_list args) __attribute__((nonnull));
void print_out(const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 1, 2))) __attribute__((nonnull));
void _mferror(const char * file, int line, const char * func, const char *msg, ... ) __attribute__((format(_PRINTF_FORMAT, 4, 5))) __attribute__((nonnull));
void _mtferror(const char *tag, const char * file, int line, const char * func, const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 5, 6))) __attribute__((nonnull));
void _merror_exit(const char * file, int line, const char * func, const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 4, 5))) __attribute__((nonnull)) __attribute__ ((noreturn));
void _plain_merror_exit(const char * file, int line, const char * func, const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 4, 5))) __attribute__((nonnull)) __attribute__ ((noreturn));
void _mterror_exit(const char *tag, const char * file, int line, const char * func, const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 5, 6))) __attribute__((nonnull)) __attribute__ ((noreturn));
void _mlerror_exit(const int level, const char * file, int line, const char * func, const char *msg, ...) __attribute__((format(_PRINTF_FORMAT, 5, 6))) __attribute__((nonnull)) __attribute__ ((noreturn));
void _mdebug1(const char * file, int line, const char * func, const char *msg, ...) ATTR_PRINTF_FOURTH_FIFTH ATTR_NONNULL;
void _plain_mdebug1(const char * file, int line, const char * func, const char *msg, ...) ATTR_PRINTF_FOURTH_FIFTH ATTR_NONNULL;
void _mtdebug1(const char *tag, const char * file, int line, const char * func, const char *msg, ...) ATTR_PRINTF_FIFTH_SIXTH ATTR_NONNULL;
void _mdebug2(const char * file, int line, const char * func, const char *msg, ...) ATTR_PRINTF_FOURTH_FIFTH ATTR_NONNULL;
void _mtdebug2(const char *tag, const char * file, int line, const char * func, const char *msg, ...) ATTR_PRINTF_FIFTH_SIXTH ATTR_NONNULL;
void _merror(const char * file, int line, const char * func, const char *msg, ...) ATTR_PRINTF_FOURTH_FIFTH ATTR_NONNULL;
void _plain_merror(const char * file, int line, const char * func, const char *msg, ...) ATTR_PRINTF_FOURTH_FIFTH ATTR_NONNULL;
void _mterror(const char *tag, const char * file, int line, const char * func, const char *msg, ...) ATTR_PRINTF_FIFTH_SIXTH ATTR_NONNULL;
void _mverror(const char * file, int line, const char * func, const char *msg, va_list args) ATTR_NONNULL;
void _mwarn(const char * file, int line, const char * func, const char *msg, ...) ATTR_PRINTF_FOURTH_FIFTH ATTR_NONNULL;
void _plain_mwarn(const char * file, int line, const char * func, const char *msg, ...) ATTR_PRINTF_FOURTH_FIFTH ATTR_NONNULL;
void _mtwarn(const char *tag, const char * file, int line, const char * func, const char *msg, ...) ATTR_PRINTF_FIFTH_SIXTH ATTR_NONNULL;
void _mvwarn(const char * file, int line, const char * func, const char *msg, va_list args) ATTR_NONNULL;
void _minfo(const char * file, int line, const char * func, const char *msg, ...) ATTR_PRINTF_FOURTH_FIFTH ATTR_NONNULL;
void _plain_minfo(const char * file, int line, const char * func, const char *msg, ...) ATTR_PRINTF_FOURTH_FIFTH ATTR_NONNULL;
void _mtinfo(const char *tag, const char * file, int line, const char * func, const char *msg, ...) ATTR_PRINTF_FIFTH_SIXTH ATTR_NONNULL;
void _mvinfo(const char * file, int line, const char * func, const char *msg, va_list args) ATTR_NONNULL;
void print_out(const char *msg, ...) ATTR_PRINTF_FIRST_SEC ATTR_NONNULL;
void _mferror(const char * file, int line, const char * func, const char *msg, ... ) ATTR_PRINTF_FOURTH_FIFTH ATTR_NONNULL;
void _mtferror(const char *tag, const char * file, int line, const char * func, const char *msg, ...) ATTR_PRINTF_FIFTH_SIXTH ATTR_NONNULL;
void _merror_exit(const char * file, int line, const char * func, const char *msg, ...) ATTR_PRINTF_FOURTH_FIFTH ATTR_NONNULL ATTR_NORETURN;
void _plain_merror_exit(const char * file, int line, const char * func, const char *msg, ...) ATTR_PRINTF_FOURTH_FIFTH ATTR_NONNULL ATTR_NORETURN;
void _mterror_exit(const char *tag, const char * file, int line, const char * func, const char *msg, ...) ATTR_PRINTF_FIFTH_SIXTH ATTR_NONNULL ATTR_NORETURN;
void _mlerror_exit(const int level, const char * file, int line, const char * func, const char *msg, ...) ATTR_PRINTF_FIFTH_SIXTH ATTR_NONNULL ATTR_NORETURN;

/**
* @brief Logging module initializer
Expand Down
19 changes: 15 additions & 4 deletions src/common/debug_op/src/debug_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,19 @@
#include "shared.h"
#include <cjson/cJSON.h>

#ifdef WIN32
#if defined(__GNUC__) || defined(__clang__)
#define ATTR_NONNULL __attribute__((nonnull))
#define ATTR_PRINTF_FIFTH_ZERO __attribute__((format(_PRINTF_FORMAT, 5, 0)))
#else
#define localtime_r(x, y) localtime_s(y, x)
#define ATTR_NONNULL
#define ATTR_PRINTF_FIFTH_ZERO
static int pthread_mutex_init(pthread_mutex_t*m, void *p){ return 0; }
static void w_mutex_lock(pthread_mutex_t*m){}
static void w_mutex_unlock(pthread_mutex_t*m){}
static int pthread_mutex_lock(pthread_mutex_t*m){}
static int pthread_mutex_unlock(pthread_mutex_t*m){}
static void w_mutex_init(pthread_mutex_t*m, void *p){}
#endif

static int dbg_flag = 0;
Expand All @@ -29,17 +40,17 @@ static struct{

static pthread_mutex_t logging_mutex;

static void _log_function(int level, const char *tag, const char * file, int line, const char * func, const char *msg, bool plain_only, va_list args) __attribute__((format(printf, 5, 0))) __attribute__((nonnull));
static void _log_function(int level, const char *tag, const char * file, int line, const char * func, const char *msg, bool plain_only, va_list args) ATTR_PRINTF_FIFTH_ZERO ATTR_NONNULL;

// Wrapper for the real _log_function
static void _log(int level, const char *tag, const char * file, int line, const char * func, const char *msg, va_list args) __attribute__((format(printf, 5, 0))) __attribute__((nonnull));
static void _log(int level, const char *tag, const char * file, int line, const char * func, const char *msg, va_list args) ATTR_PRINTF_FIFTH_ZERO ATTR_NONNULL;
static void _log(int level, const char *tag, const char * file, int line, const char * func, const char *msg, va_list args) {
_log_function(level, tag, file, line, func, msg, true, args);
}


#ifdef WIN32
void WinSetError();
void WinSetError(){}
#endif

static void print_stderr_msg(char* timestamp, const char *tag, const char * file, int line, const char * func, const char* level, const char *msg, bool use_va_list, va_list args2) {
Expand Down
Loading

0 comments on commit 21640a3

Please sign in to comment.