mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-23 17:45:46 +00:00
Merge pull request #411 from diamante0018/debug-regression
fix: wrong "bin" directory when using executable from $PATH
This commit is contained in:
commit
e14f0743da
@ -5,6 +5,7 @@
|
|||||||
#include "ObjWriting.h"
|
#include "ObjWriting.h"
|
||||||
#include "Utils/Arguments/UsageInformation.h"
|
#include "Utils/Arguments/UsageInformation.h"
|
||||||
#include "Utils/FileUtils.h"
|
#include "Utils/FileUtils.h"
|
||||||
|
#include "Utils/PathUtils.h"
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <format>
|
#include <format>
|
||||||
@ -152,9 +153,9 @@ void LinkerArgs::PrintVersion()
|
|||||||
std::cout << std::format("OpenAssetTools Linker {}\n", GIT_VERSION);
|
std::cout << std::format("OpenAssetTools Linker {}\n", GIT_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinkerArgs::SetBinFolder(const char* argv0)
|
void LinkerArgs::SetBinFolder()
|
||||||
{
|
{
|
||||||
const fs::path path(argv0);
|
const fs::path path(utils::GetExecutablePath());
|
||||||
m_bin_folder = path.parent_path().string();
|
m_bin_folder = path.parent_path().string();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,7 +191,7 @@ bool LinkerArgs::ParseArgs(const int argc, const char** argv, bool& shouldContin
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetBinFolder(argv[0]);
|
SetBinFolder();
|
||||||
|
|
||||||
m_project_specifiers_to_build = m_argument_parser.GetArguments();
|
m_project_specifiers_to_build = m_argument_parser.GetArguments();
|
||||||
if (m_project_specifiers_to_build.empty())
|
if (m_project_specifiers_to_build.empty())
|
||||||
|
@ -37,7 +37,7 @@ private:
|
|||||||
void PrintUsage() const;
|
void PrintUsage() const;
|
||||||
static void PrintVersion();
|
static void PrintVersion();
|
||||||
|
|
||||||
void SetBinFolder(const char* argv0);
|
void SetBinFolder();
|
||||||
void SetVerbose(bool isVerbose);
|
void SetVerbose(bool isVerbose);
|
||||||
|
|
||||||
ArgumentParser m_argument_parser;
|
ArgumentParser m_argument_parser;
|
||||||
|
@ -314,8 +314,8 @@ namespace
|
|||||||
|
|
||||||
std::unique_ptr<ILinkerPaths> ILinkerPaths::FromArgs(const LinkerArgs& args)
|
std::unique_ptr<ILinkerPaths> ILinkerPaths::FromArgs(const LinkerArgs& args)
|
||||||
{
|
{
|
||||||
std::string normalizedBinPath = fs::canonical(args.m_bin_folder).make_preferred().string();
|
std::string normalizedBinPath = fs::weakly_canonical(args.m_bin_folder).make_preferred().string();
|
||||||
std::string normalizedBasePath = fs::canonical(args.m_base_folder).make_preferred().string();
|
std::string normalizedBasePath = fs::weakly_canonical(args.m_base_folder).make_preferred().string();
|
||||||
|
|
||||||
LinkerSearchPathBuilder assetSearchPaths("asset", normalizedBinPath, normalizedBasePath);
|
LinkerSearchPathBuilder assetSearchPaths("asset", normalizedBinPath, normalizedBasePath);
|
||||||
assetSearchPaths.BuildFromArgs(args.m_asset_search_paths);
|
assetSearchPaths.BuildFromArgs(args.m_asset_search_paths);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
27
src/Utils/Utils/PathUtils.cpp
Normal file
27
src/Utils/Utils/PathUtils.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include "PathUtils.h"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#elif defined(__linux__)
|
||||||
|
#include <limits.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace utils
|
||||||
|
{
|
||||||
|
std::string GetExecutablePath()
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
char result[MAX_PATH];
|
||||||
|
return std::string(result, GetModuleFileNameA(NULL, result, MAX_PATH));
|
||||||
|
#elif defined(__linux__)
|
||||||
|
char result[PATH_MAX];
|
||||||
|
const auto count = readlink("/proc/self/exe", result, PATH_MAX);
|
||||||
|
return std::string(result, (count > 0) ? count : 0);
|
||||||
|
#else
|
||||||
|
throw std::runtime_error("Unknown platform for executable path");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
} // namespace utils
|
8
src/Utils/Utils/PathUtils.h
Normal file
8
src/Utils/Utils/PathUtils.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace utils
|
||||||
|
{
|
||||||
|
std::string GetExecutablePath();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user