From 9be297df6f46555948f63e4f3cbdb4649c4d64a8 Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Sat, 25 Feb 2023 15:41:45 +0800 Subject: [PATCH] Fix logging Ensure log directory base path is relative to the executable. --- 00-build-cache-debug-x64 | 4 ++-- 01-build-executable | 15 +++++++++++++++ 01-build-game | 3 --- 02-build-server | 3 --- 03-run-tests | 7 +++++++ CMakeLists.txt | 20 ++++++++++---------- src/packages/log/IZ_log.c | 11 ++++++----- src/packages/log/IZ_log.h | 1 + 8 files changed, 41 insertions(+), 23 deletions(-) create mode 100755 01-build-executable delete mode 100755 01-build-game delete mode 100755 02-build-server create mode 100644 03-run-tests diff --git a/00-build-cache-debug-x64 b/00-build-cache-debug-x64 index f708f79..14d7ec1 100755 --- a/00-build-cache-debug-x64 +++ b/00-build-cache-debug-x64 @@ -2,10 +2,10 @@ cmake \ -DCMAKE_SIZEOF_VOID_P=8 \ - -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ -DCMAKE_MAKE_PROGRAM=ninja \ -DCMAKE_C_COMPILER=cc \ -DCMAKE_C_FLAGS=-m64 \ -G Ninja \ -S . \ - -B ./build/Debug + -B ./build/$BUILD_TYPE diff --git a/01-build-executable b/01-build-executable new file mode 100755 index 0000000..de52b3c --- /dev/null +++ b/01-build-executable @@ -0,0 +1,15 @@ +#!/usr/bin/env sh + +if [ "$BUILD_TYPE" = "" ] +then + echo "No build type specified. Try Debug or Release." + exit +fi + +if [ "$EXECUTABLE" = "" ] +then + echo "No executable specified. Refer to CMakeLists.txt for available executables to build." + exit +fi + +cmake --build "./build/$BUILD_TYPE" -t "$EXECUTABLE" diff --git a/01-build-game b/01-build-game deleted file mode 100755 index e995a64..0000000 --- a/01-build-game +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env sh - -cmake --build build/Debug -t game diff --git a/02-build-server b/02-build-server deleted file mode 100755 index 0be2f80..0000000 --- a/02-build-server +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env sh - -cmake --build build/Debug -t server diff --git a/03-run-tests b/03-run-tests new file mode 100644 index 0000000..b8c2b5b --- /dev/null +++ b/03-run-tests @@ -0,0 +1,7 @@ +#!/usr/bin/env sh + +if [ "$BUILD_TYPE" = "" ] +then + return 1 +fi +cmake --build "./build/$BUILD_TYPE" -t server diff --git a/CMakeLists.txt b/CMakeLists.txt index 44dcf1e..6391978 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -217,7 +217,7 @@ target_link_libraries( ) add_executable( - game-test-geometry + test-game-geometry subprojects/bdd-for-c/bdd-for-c.h subprojects/bdd-for-c-mocks/bdd-for-c-mocks.h @@ -229,7 +229,7 @@ add_executable( ) add_executable( - game-test-input + test-game-input subprojects/bdd-for-c/bdd-for-c.h subprojects/bdd-for-c-mocks/bdd-for-c-mocks.h @@ -265,13 +265,13 @@ add_executable( ) target_link_libraries( - game-test-input + test-game-input SDL2main SDL2 ) add_executable( - game-test-output + test-game-output subprojects/bdd-for-c/bdd-for-c.h subprojects/bdd-for-c-mocks/bdd-for-c-mocks.h @@ -286,7 +286,7 @@ add_executable( ) add_executable( - game-test-memory + test-game-memory subprojects/bdd-for-c/bdd-for-c.h subprojects/bdd-for-c-mocks/bdd-for-c-mocks.h @@ -310,13 +310,13 @@ add_executable( ) target_link_libraries( - game-test-memory + test-game-memory SDL2main SDL2 ) add_executable( - game-test-data + test-game-data subprojects/bdd-for-c/bdd-for-c.h subprojects/bdd-for-c-mocks/bdd-for-c-mocks.h @@ -329,7 +329,7 @@ add_executable( ) target_link_libraries( - game-test-data + test-game-data SDL2main SDL2 ) @@ -443,10 +443,10 @@ if (IZ_PLATFORM STREQUAL "WINDOWS") "${CMAKE_HOME_DIRECTORY}/dependencies/openssl/${IZ_PROJECT_ARCH}/bin/libcrypto-1_1-${IZ_SDL_ARCH}.dll" $) - add_custom_command(TARGET game-test-input POST_BUILD + add_custom_command(TARGET test-game-input POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_HOME_DIRECTORY}/subprojects/SDL/VisualC/${IZ_SDL_ARCH}/${CMAKE_BUILD_TYPE}/SDL2.dll" - $) + $) endif () add_custom_command(TARGET game POST_BUILD diff --git a/src/packages/log/IZ_log.c b/src/packages/log/IZ_log.c index dae993d..70a81d1 100644 --- a/src/packages/log/IZ_log.c +++ b/src/packages/log/IZ_log.c @@ -48,16 +48,17 @@ void IZ_LogInitialize(const char* context, bool force_output) { stderr_dest = stderr; #else const char* log_dir = "logs"; - if (!IZ_isdir(log_dir)) { - IZ_mkdir(log_dir); + char base_log_dir[128]; + sprintf(base_log_dir, "%s/%s", SDL_GetBasePath(), log_dir); + if (!IZ_isdir(base_log_dir)) { + IZ_mkdir(base_log_dir); } char stdout_filename[128] = ""; char stderr_filename[128] = ""; char* now = IZ_TimerNowPathSafe(); - // fixme - sprintf(stdout_filename, "%s/%s-out-%s.log", log_dir, context, now); - sprintf(stderr_filename, "%s/%s-err-%s.log", log_dir, context, now); + sprintf(stdout_filename, "%s/%s-out-%s.log", base_log_dir, context, now); + sprintf(stderr_filename, "%s/%s-err-%s.log", base_log_dir, context, now); IZ_fopen(&stdout_dest, stdout_filename, "a"); IZ_fopen(&stderr_dest, stderr_filename, "a"); #endif diff --git a/src/packages/log/IZ_log.h b/src/packages/log/IZ_log.h index ee628d4..ebacf70 100644 --- a/src/packages/log/IZ_log.h +++ b/src/packages/log/IZ_log.h @@ -16,6 +16,7 @@ #define IZ_LOG_LEVEL_FLAG_WARN #define IZ_LOG_LEVEL_FLAG_ERROR +#include #if defined IZ_WINDOWS #include #include