Mercurial > irccd
changeset 700:91bc29e87399
Irccd: use Boost.Predef, closes #805 @1h
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 09 May 2018 22:34:47 +0200 |
parents | 808171f7bfa2 |
children | 2007a37d7e1a |
files | MIGRATING.md cmake/IrccdSystem.cmake cmake/function/IrccdDefineExecutable.cmake cmake/internal/sysconfig.hpp.in doc/src/api/module/Irccd.System/Irccd.System.name.md irccd/CMakeLists.txt irccdctl/main.cpp libcommon/CMakeLists.txt libcommon/irccd/ini.cpp libcommon/irccd/socket_acceptor.hpp libcommon/irccd/socket_connector.hpp libcommon/irccd/socket_stream.hpp libcommon/irccd/string_util.cpp libcommon/irccd/system.cpp libirccd-js/irccd/js/directory_jsapi.cpp libirccd/irccd/daemon/dynlib_plugin.cpp libirccd/irccd/daemon/irccd.cpp libirccd/irccd/daemon/server.cpp libirccd/irccd/daemon/transport_util.cpp tests/src/libcommon/io/main.cpp |
diffstat | 20 files changed, 96 insertions(+), 94 deletions(-) [+] |
line wrap: on
line diff
--- a/MIGRATING.md Wed May 09 20:11:50 2018 +0200 +++ b/MIGRATING.md Wed May 09 22:34:47 2018 +0200 @@ -58,7 +58,7 @@ - The property `Directory.count` has been removed. -### Module Plugin +#### Module Plugin The following properties in `Irccd.Plugin` has been renamed: @@ -69,3 +69,6 @@ Note: these paths are no more automatically detected and set with the new `[paths]` and `[paths.<name>]` sections. +#### Module System + + - The function `Irccd.System.name` has now well defined return value.
--- a/cmake/IrccdSystem.cmake Wed May 09 20:11:50 2018 +0200 +++ b/cmake/IrccdSystem.cmake Wed May 09 22:34:47 2018 +0200 @@ -73,27 +73,6 @@ endif () # -# System identification. -# ------------------------------------------------------------------- -# - -if (WIN32) - set(IRCCD_SYSTEM_WINDOWS TRUE) -elseif (APPLE) - set(IRCCD_SYSTEM_MAC TRUE) -elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") - set(IRCCD_SYSTEM_FREEBSD TRUE) -elseif (CMAKE_SYSTEM_NAME MATCHES "DragonFly") - set(IRCCD_SYSTEM_DRAGONFLYBSD TRUE) -elseif (CMAKE_SYSTEM_NAME MATCHES "NetBSD") - set(IRCCD_SYSTEM_NETBSD TRUE) -elseif (CMAKE_SYSTEM_NAME MATCHES "OpenBSD") - set(IRCCD_SYSTEM_OPENBSD TRUE) -elseif (CMAKE_SYSTEM_NAME MATCHES "Linux") - set(IRCCD_SYSTEM_LINUX TRUE) -endif () - -# # Portability requirements. # ------------------------------------------------------------------- # @@ -159,12 +138,10 @@ # If HAVE_GETLOGIN is defined, include: # # #include <unistd.h> -if (NOT IRCCD_SYSTEM_WINDOWS) - check_function_exists(getlogin HAVE_GETLOGIN) +check_function_exists(getlogin HAVE_GETLOGIN) - if (NOT HAVE_UNISTD_H) - set(HAVE_GETLOGIN FALSE) - endif () +if (NOT HAVE_UNISTD_H) + set(HAVE_GETLOGIN FALSE) endif () # getpid() function
--- a/cmake/function/IrccdDefineExecutable.cmake Wed May 09 20:11:50 2018 +0200 +++ b/cmake/function/IrccdDefineExecutable.cmake Wed May 09 22:34:47 2018 +0200 @@ -37,7 +37,7 @@ function(irccd_define_executable) set(options "") set(oneValueArgs DESCRIPTION TARGET) - set(multiValueArgs SOURCES FLAGS LIBRARIES INCLUDES) + set(multiValueArgs SOURCES FLAGS LIBRARIES INCLUDES OPTIONS) cmake_parse_arguments(EXE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) @@ -54,6 +54,7 @@ add_executable(${EXE_TARGET} ${EXE_SOURCES}) target_include_directories(${EXE_TARGET} PRIVATE ${EXE_INCLUDES}) target_compile_definitions(${EXE_TARGET} PRIVATE ${EXE_FLAGS}) + target_compile_options(${EXE_TARGET} PRIVATE ${EXE_OPTIONS}) target_link_libraries(${EXE_TARGET} ${EXE_LIBRARIES}) set_target_properties(
--- a/cmake/internal/sysconfig.hpp.in Wed May 09 20:11:50 2018 +0200 +++ b/cmake/internal/sysconfig.hpp.in Wed May 09 22:34:47 2018 +0200 @@ -47,20 +47,6 @@ #define IRCCD_VERSION "@IRCCD_VERSION@" /* - * System identification. - * ------------------------------------------------------------------ - */ - -#cmakedefine IRCCD_SYSTEM_WINDOWS -#cmakedefine IRCCD_SYSTEM_MAC -#cmakedefine IRCCD_SYSTEM_FREEBSD -#cmakedefine IRCCD_SYSTEM_DRAGONFLYBSD -#cmakedefine IRCCD_SYSTEM_NETBSD -#cmakedefine IRCCD_SYSTEM_OPENBSD -#cmakedefine IRCCD_SYSTEM_LINUX -#cmakedefine IRCCD_SYSTEM_UNKNOWN - -/* * User definable options. * ------------------------------------------------------------------ */
--- a/doc/src/api/module/Irccd.System/Irccd.System.name.md Wed May 09 20:11:50 2018 +0200 +++ b/doc/src/api/module/Irccd.System/Irccd.System.name.md Wed May 09 22:34:47 2018 +0200 @@ -1,6 +1,20 @@ # Function Irccd.System.name -Get the operating system name. Usually Windows, FreeBSD, Linux and such. +Get the operating system name. Returns one of: + +- Linux +- Windows +- FreeBSD +- DragonFlyBSD +- OpenBSD +- NetBSD +- macOS +- Android +- Aix +- Haiku +- iOS +- Solaris +- Unknown # Synopsis
--- a/irccd/CMakeLists.txt Wed May 09 20:11:50 2018 +0200 +++ b/irccd/CMakeLists.txt Wed May 09 22:34:47 2018 +0200 @@ -23,11 +23,9 @@ DESCRIPTION "The main irccd daemon." SOURCES CMakeLists.txt main.cpp INCLUDES ${irccd_SOURCE_DIR} + OPTIONS + $<$<BOOL:APPLE>:-Wno-deprecated-declarations> LIBRARIES libirccd $<$<BOOL:${HAVE_JS}>:libirccd-js> ) - -if (IRCCD_SYSTEM_MAC) - target_compile_options(irccd PRIVATE -Wno-deprecated-declarations) -endif ()
--- a/irccdctl/main.cpp Wed May 09 20:11:50 2018 +0200 +++ b/irccdctl/main.cpp Wed May 09 22:34:47 2018 +0200 @@ -21,6 +21,7 @@ #include <iostream> #include <unordered_map> +#include <boost/predef/os.h> #include <boost/filesystem.hpp> #include <irccd/config.hpp> @@ -72,7 +73,7 @@ using boost::asio::ip::tcp; -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS using boost::asio::local::stream_protocol; @@ -177,7 +178,7 @@ */ std::unique_ptr<io::connector> read_connect_local(const ini::section& sc) { -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS using boost::asio::local::stream_protocol; const auto it = sc.find("path"); @@ -342,7 +343,7 @@ */ std::unique_ptr<io::connector> parse_connect_local(const option::result& options) { -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS option::result::const_iterator it; if ((it = options.find("-P")) == options.end() && (it = options.find("--path")) == options.end())
--- a/libcommon/CMakeLists.txt Wed May 09 20:11:50 2018 +0200 +++ b/libcommon/CMakeLists.txt Wed May 09 22:34:47 2018 +0200 @@ -64,11 +64,11 @@ Boost::system $<$<BOOL:${HAVE_SSL}>:OpenSSL::Crypto> $<$<BOOL:${HAVE_SSL}>:OpenSSL::SSL> - $<$<BOOL:${IRCCD_SYSTEM_LINUX}>:dl> - $<$<BOOL:${IRCCD_SYSTEM_MAC}>:resolv> - $<$<BOOL:${IRCCD_SYSTEM_WINDOWS}>:mswsock> + $<$<BOOL:${APPLE}>:resolv> + $<$<BOOL:${WIN32}>:mswsock> $<$<BOOL:${WIN32}>:shlwapi> $<$<BOOL:${WIN32}>:ws2_32> + $<$<STREQUAL:${CMAKE_SYSTEM_NAME},Linux>:dl> PUBLIC_INCLUDES $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}> $<BUILD_INTERFACE:${libcommon_SOURCE_DIR}>
--- a/libcommon/irccd/ini.cpp Wed May 09 20:11:50 2018 +0200 +++ b/libcommon/irccd/ini.cpp Wed May 09 22:34:47 2018 +0200 @@ -26,8 +26,10 @@ #include <irccd/sysconfig.hpp> +#include <boost/predef.h> + // for PathIsRelative. -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS # include <shlwapi.h> #endif @@ -44,7 +46,7 @@ inline bool is_absolute(const std::string& path) noexcept { -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS return !PathIsRelative(path.c_str()); #else return path.size() > 0 && path[0] == '/'; @@ -288,7 +290,7 @@ std::string file; if (!is_absolute(value)) { -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS file = path + "\\" + value; #else file = path + "/" + value;
--- a/libcommon/irccd/socket_acceptor.hpp Wed May 09 20:11:50 2018 +0200 +++ b/libcommon/irccd/socket_acceptor.hpp Wed May 09 22:34:47 2018 +0200 @@ -26,8 +26,6 @@ #include <irccd/sysconfig.hpp> -#include <boost/asio.hpp> - #include "acceptor.hpp" #include "socket_stream.hpp" @@ -148,7 +146,7 @@ */ using ip_acceptor = socket_acceptor<boost::asio::ip::tcp>; -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS /** * Convenient Unix acceptor type.
--- a/libcommon/irccd/socket_connector.hpp Wed May 09 20:11:50 2018 +0200 +++ b/libcommon/irccd/socket_connector.hpp Wed May 09 22:34:47 2018 +0200 @@ -31,8 +31,6 @@ #include "connector.hpp" #include "socket_stream.hpp" -#include <boost/asio.hpp> - namespace irccd { namespace io { @@ -162,7 +160,7 @@ */ using ip_connector = socket_connector<boost::asio::ip::tcp>; -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS /** * Convenient Unix conncetor type.
--- a/libcommon/irccd/socket_stream.hpp Wed May 09 20:11:50 2018 +0200 +++ b/libcommon/irccd/socket_stream.hpp Wed May 09 22:34:47 2018 +0200 @@ -32,6 +32,7 @@ #include <utility> #include <boost/asio.hpp> +#include <boost/predef/os.h> #include "stream.hpp" @@ -229,7 +230,7 @@ */ using ip_stream = socket_stream<boost::asio::ip::tcp::socket>; -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS /** * Convenient Unix stream type.
--- a/libcommon/irccd/string_util.cpp Wed May 09 20:11:50 2018 +0200 +++ b/libcommon/irccd/string_util.cpp Wed May 09 22:34:47 2018 +0200 @@ -16,6 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <boost/predef/os.h> + #include "sysconfig.hpp" #if defined(HAVE_POPEN) @@ -183,7 +185,7 @@ std::string subst_shell_attrs(const std::string& content) { -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS auto list = split(content, ","); if (list.empty())
--- a/libcommon/irccd/system.cpp Wed May 09 20:11:50 2018 +0200 +++ b/libcommon/irccd/system.cpp Wed May 09 22:34:47 2018 +0200 @@ -26,10 +26,11 @@ #include <boost/dll.hpp> #include <boost/filesystem.hpp> +#include <boost/predef/os.h> #include "sysconfig.hpp" -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS # include <sys/timeb.h> # include <shlobj.h> #else @@ -40,11 +41,11 @@ # include <unistd.h> #endif -#if defined(IRCCD_SYSTEM_LINUX) +#if BOOST_OS_LINUX # include <sys/sysinfo.h> #endif -#if defined(IRCCD_SYSTEM_MAC) +#if BOOST_OS_MACOS # include <sys/sysctl.h> # include <libproc.h> #endif @@ -157,7 +158,7 @@ { boost::filesystem::path path; -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS char folder[MAX_PATH] = {0}; if (SHGetFolderPathA(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, folder) == S_OK) { @@ -198,7 +199,7 @@ { boost::filesystem::path path; -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS char folder[MAX_PATH] = {0}; if (SHGetFolderPathA(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, folder) == S_OK) { @@ -242,20 +243,30 @@ std::string name() { -#if defined(IRCCD_SYSTEM_LINUX) +#if BOOST_OS_LINUX return "Linux"; -#elif defined(IRCCD_SYSTEM_WINDOWS) +#elif BOOST_OS_WINDOWS return "Windows"; -#elif defined(IRCCD_SYSTEM_FREEBSD) +#elif BOOST_OS_BSD_FREE return "FreeBSD"; -#elif defined(IRCCD_SYSTEM_DRAGONFLYBSD) +#elif BOOST_OS_BSD_DRAGONFLY return "DragonFlyBSD"; -#elif defined(IRCCD_SYSTEM_OPENBSD) +#elif BOOST_OS_BSD_OPEN return "OpenBSD"; -#elif defined(IRCCD_SYSTEM_NETBSD) +#elif BOOST_OS_BSD_NET return "NetBSD"; -#elif defined(IRCCD_SYSTEM_MAC) - return "Mac"; +#elif BOOST_OS_MACOS + return "macOS"; +#elif BOOST_OS_ANDROID + return "Android"; +#elif BOOST_OS_AIX + return "Aix"; +#elif BOOST_OS_HAIKU + return "Haiku"; +#elif BOOST_OS_IOS + return "iOS"; +#elif BOOST_OS_SOLARIS + return "Solaris"; #else return "Unknown"; #endif @@ -274,7 +285,7 @@ */ std::string version() { -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS const auto version = GetVersion(); const auto major = (DWORD)(LOBYTE(LOWORD(version))); const auto minor = (DWORD)(HIBYTE(LOWORD(version))); @@ -308,16 +319,16 @@ */ std::uint64_t uptime() { -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS return ::GetTickCount64() / 1000; -#elif defined(IRCCD_SYSTEM_LINUX) +#elif BOOST_OS_LINUX struct sysinfo info; if (sysinfo(&info) < 0) throw std::runtime_error(std::strerror(errno)); return info.uptime; -#elif defined(IRCCD_SYSTEM_MAC) +#elif BOOST_OS_MACOS struct timeval boottime; size_t length = sizeof (boottime); int mib[2] = { CTL_KERN, KERN_BOOTTIME }; @@ -351,7 +362,7 @@ */ std::uint64_t ticks() { -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS _timeb tp; _ftime(&tp); @@ -377,7 +388,7 @@ */ std::string home() { -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS char path[MAX_PATH]; if (SHGetFolderPathA(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, path) != S_OK)
--- a/libirccd-js/irccd/js/directory_jsapi.cpp Wed May 09 20:11:50 2018 +0200 +++ b/libirccd-js/irccd/js/directory_jsapi.cpp Wed May 09 22:34:47 2018 +0200 @@ -16,6 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <boost/predef/os.h> + #include <irccd/sysconfig.hpp> #include <cerrno> @@ -356,7 +358,7 @@ duk_put_number_list(plugin->context(), -1, constants); duk_put_function_list(plugin->context(), -1, functions); -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS duk_push_string(plugin->context(), "\\"); #else duk_push_string(plugin->context(), "/");
--- a/libirccd/irccd/daemon/dynlib_plugin.cpp Wed May 09 20:11:50 2018 +0200 +++ b/libirccd/irccd/daemon/dynlib_plugin.cpp Wed May 09 22:34:47 2018 +0200 @@ -20,14 +20,15 @@ #include <boost/dll.hpp> #include <boost/filesystem.hpp> +#include <boost/predef/os.h> #include <irccd/string_util.hpp> #include "dynlib_plugin.hpp" -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS # define DYNLIB_EXTENSION ".dll" -#elif defined(IRCCD_SYSTEM_MAC) +#elif BOOST_OS_MACOS # define DYNLIB_EXTENSION ".dylib" #else # define DYNLIB_EXTENSION ".so"
--- a/libirccd/irccd/daemon/irccd.cpp Wed May 09 20:11:50 2018 +0200 +++ b/libirccd/irccd/daemon/irccd.cpp Wed May 09 22:34:47 2018 +0200 @@ -18,6 +18,8 @@ #include <fstream> +#include <boost/predef/os.h> + #include <irccd/string_util.hpp> #include <irccd/system.hpp> @@ -84,7 +86,7 @@ /* * TODO: improve that with CMake options. */ -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS std::string normal = "log.txt"; std::string errors = "errors.txt"; #else
--- a/libirccd/irccd/daemon/server.cpp Wed May 09 20:11:50 2018 +0200 +++ b/libirccd/irccd/daemon/server.cpp Wed May 09 22:34:47 2018 +0200 @@ -16,6 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <boost/predef/os.h> + #include <irccd/sysconfig.hpp> #include <algorithm> @@ -23,7 +25,7 @@ #include <cstring> #include <stdexcept> -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS # include <sys/types.h> # include <netinet/in.h> # include <arpa/nameser.h> @@ -504,7 +506,7 @@ * This is needed if irccd is started before DHCP or if DNS cache is * outdated. */ -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS (void)res_init(); #endif
--- a/libirccd/irccd/daemon/transport_util.cpp Wed May 09 20:11:50 2018 +0200 +++ b/libirccd/irccd/daemon/transport_util.cpp Wed May 09 22:34:47 2018 +0200 @@ -20,6 +20,8 @@ #include <cassert> +#include <boost/predef/os.h> + #include <irccd/ini_util.hpp> #include <irccd/string_util.hpp> #include <irccd/socket_acceptor.hpp> @@ -128,7 +130,7 @@ { assert(sc.key() == "transport"); -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS using boost::asio::local::stream_protocol; const auto path = sc.get("path").value();
--- a/tests/src/libcommon/io/main.cpp Wed May 09 20:11:50 2018 +0200 +++ b/tests/src/libcommon/io/main.cpp Wed May 09 22:34:47 2018 +0200 @@ -19,6 +19,7 @@ #define BOOST_TEST_MODULE "io" #include <boost/test/unit_test.hpp> #include <boost/mpl/list.hpp> +#include <boost/predef/os.h> #include <irccd/sysconfig.hpp> @@ -39,7 +40,7 @@ using boost::asio::ssl::context; #endif -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS using boost::asio::local::stream_protocol; #endif @@ -145,7 +146,7 @@ #endif // !HAVE_SSL -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS class local_io_test : public io_test { public: @@ -170,7 +171,7 @@ } }; -#endif // !IRCCD_SYSTEM_WINDOWS +#endif // !BOOST_OS_WINDOWS /** * List of fixtures to tests. @@ -180,7 +181,7 @@ #if defined(HAVE_SSL) , ssl_io_test #endif -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS , local_io_test #endif >;