home autodetect
This commit is contained in:
parent
af41ee5084
commit
307db7169d
1 changed files with 26 additions and 1 deletions
|
|
@ -49,7 +49,32 @@ fs::path Crafter::GetCrafterBuildHome() {
|
|||
#else
|
||||
fs::path hostExe = fs::read_symlink("/proc/self/exe");
|
||||
#endif
|
||||
return hostExe.parent_path().parent_path() / "share" / "crafter-build";
|
||||
|
||||
// Walk up from the exe's directory looking for share/crafter-build with
|
||||
// a known module source present as a sentinel. Handles:
|
||||
// <prefix>/bin/crafter-build -> <prefix>/share/crafter-build (FHS install)
|
||||
// <repo>/bin/crafter-build -> <repo>/share/crafter-build (build.sh)
|
||||
// <repo>/bin/<arch>/crafter-build -> <repo>/share/crafter-build (self-host)
|
||||
fs::path dir = hostExe.parent_path();
|
||||
std::vector<fs::path> tried;
|
||||
for (;;) {
|
||||
fs::path candidate = dir / "share" / "crafter-build";
|
||||
tried.push_back(candidate);
|
||||
std::error_code ec;
|
||||
if (fs::exists(candidate / "Crafter.Build.cppm", ec)) {
|
||||
return candidate;
|
||||
}
|
||||
fs::path parent = dir.parent_path();
|
||||
if (parent == dir) break;
|
||||
dir = parent;
|
||||
}
|
||||
std::string msg = std::format(
|
||||
"could not locate crafter-build runtime assets relative to {} (set CRAFTER_BUILD_HOME). Tried:",
|
||||
hostExe.string());
|
||||
for (const auto& p : tried) {
|
||||
msg += "\n " + p.string();
|
||||
}
|
||||
throw std::runtime_error(msg);
|
||||
}
|
||||
|
||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue