Skip to content
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
28 changes: 19 additions & 9 deletions FlingEngine/Resources/src/FlingPaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ namespace Fling

void FlingPaths::GetCurrentWorkingDir(char* t_OutBuf, size_t t_BufSize)
{
// Normalize CWD to the directory that contains this executable.
// Shipping builds use relative paths (Config/, Assets/, Logs/), so
// loading must not depend on whichever directory the process was
// launched from (IDE vs shell vs CI).
#if FLING_WINDOWS
{
// Get the real, full path to this executable, end the string before
// the filename itself and then set that as the current directory
GetModuleFileName(0, t_OutBuf, t_BufSize);
GetModuleFileName(0, t_OutBuf, static_cast<DWORD>(t_BufSize));
char* lastSlash = strrchr(t_OutBuf, '\\');
if (lastSlash)
{
Expand All @@ -48,19 +50,27 @@ namespace Fling
}
#elif FLING_LINUX
{
if (getcwd(t_OutBuf, t_BufSize) != nullptr)
const ssize_t Len = readlink("/proc/self/exe", t_OutBuf, t_BufSize - 1);
if (Len == -1)
{
F_LOG_TRACE("Current working dir: {}\n", t_OutBuf);
F_LOG_FATAL("readlink(/proc/self/exe) error");
return;
}
else

t_OutBuf[Len] = '\0';
char* lastSlash = strrchr(t_OutBuf, '/');
if (lastSlash)
{
F_LOG_FATAL("getcwd() error");
*lastSlash = 0;
}

if (chdir(t_OutBuf) == -1)
if (chdir(t_OutBuf) == -1)
{
F_LOG_FATAL("chdir() error :");
F_LOG_FATAL("chdir() error");
return;
}

F_LOG_TRACE("Current working dir: {}", t_OutBuf);
}
#endif // FLING_LINUX
}
Expand Down
12 changes: 11 additions & 1 deletion FlingTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,14 @@ endif()
add_executable( ${PROJECT_NAME} ${_source_list} )

# Link Catch2 and everything else
target_link_libraries( ${PROJECT_NAME} LINK_PUBLIC ${LINK_LIBS} )
target_link_libraries( ${PROJECT_NAME} LINK_PUBLIC ${LINK_LIBS} )

# Shipping builds resolve EngineConfigDir() to a relative "Config" path, and
# ResourceManager::Init() chdirs to the executable directory. Keep TestConf.ini
# next to the binary so FlingTests pass regardless of launch CWD.
add_custom_command( TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${FLING_ROOT_DIR}/Config"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/Config"
COMMENT "Copying Config next to ${PROJECT_NAME}"
)
12 changes: 5 additions & 7 deletions FlingTests/src/ResourceTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ TEST_CASE("Engine Config File", "[resource]")
using namespace Fling;
// Logger HAS to be initalized first
Logger::Get().Init();
// Sets CWD to the executable directory so relative shipping paths resolve
ResourceManager::Get().Init();
FlingConfig::Get().Init();

SECTION("Valid Config")
{
// Load a test config
bool ConfigLoaded = FlingConfig::Get().LoadConfigFile(FlingPaths::EngineConfigDir() + "/TestConf.ini");
REQUIRE(ConfigLoaded);
}
// Load once for all sections (Catch re-runs this block per SECTION)
bool ConfigLoaded = FlingConfig::Get().LoadConfigFile(FlingPaths::EngineConfigDir() + "/TestConf.ini");
REQUIRE(ConfigLoaded);

SECTION("Read False Bool")
{
Expand Down Expand Up @@ -58,4 +56,4 @@ TEST_CASE("Engine Config File", "[resource]")
ResourceManager::Get().Shutdown();
Logger::Get().Shutdown();
FlingConfig::Get().Shutdown();
}
}
Loading