31 lines
997 B
Rust
31 lines
997 B
Rust
|
|
use std::path::PathBuf;
|
||
|
|
|
||
|
|
/// Resolve the project root from the executable path.
|
||
|
|
/// In dev mode, the binary lives at: <root>/src-tauri/target/debug/<bin>
|
||
|
|
/// So the project root is 4 levels above the binary.
|
||
|
|
pub fn project_root() -> PathBuf {
|
||
|
|
let exe = std::env::current_exe().expect("Failed to get executable path");
|
||
|
|
// exe -> debug/ -> target/ -> src-tauri/ -> root
|
||
|
|
exe.parent()
|
||
|
|
.and_then(|p| p.parent())
|
||
|
|
.and_then(|p| p.parent())
|
||
|
|
.and_then(|p| p.parent())
|
||
|
|
.map(|p| p.to_path_buf())
|
||
|
|
.unwrap_or_else(|| PathBuf::from("."))
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Absolute path to the venv Python 3.10 interpreter.
|
||
|
|
pub fn python_exe() -> PathBuf {
|
||
|
|
project_root().join(".venv/bin/python3.10")
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Absolute path to a script in the backend directory.
|
||
|
|
pub fn backend_script(name: &str) -> PathBuf {
|
||
|
|
project_root().join("backend").join(name)
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Absolute path to a script at the project root.
|
||
|
|
pub fn root_script(name: &str) -> PathBuf {
|
||
|
|
project_root().join(name)
|
||
|
|
}
|