refactor: eliminate all CARGO_MANIFEST_DIR compile-time dependencies (A-4)
- Add src/core/path_utils.rs with runtime path resolution helpers
- Replace all env!("CARGO_MANIFEST_DIR") with runtime resolution
- Priority: env var -> current_exe sibling -> dev fallback
Changes:
- executor.rs: scripts_dir(), cli_dir() (4 locations)
- face.rs: swift_processor_path()
- tool_selector.rs: swift_binary_path()
- thumbnail/mod.rs: script_path()
Issue: CARGO_MANIFEST_DIR expands to build machine path at compile time,
breaking on binary-only release hosts.
Solution: Resolve paths at runtime in this order:
1. Explicit environment variable (MOMENTRY_SCRIPTS_DIR, MOMENTRY_CLI_DIR)
2. Sibling of current_exe (same directory as running binary)
3. Relative path fallback (dev machine)
Verified: cargo check --lib passes
This commit is contained in:
+14
@@ -18,6 +18,20 @@ fn init_tracing() {
|
||||
}
|
||||
|
||||
fn load_env() {
|
||||
// Resolve .env at runtime so the binary is portable across machines.
|
||||
// Order: MOMENTRY_ENV_FILE -> ./.env -> <exe_dir>/../../.env -> legacy M5 path.
|
||||
if let Ok(p) = std::env::var("MOMENTRY_ENV_FILE") {
|
||||
let _ = dotenv::from_filename(p);
|
||||
return;
|
||||
}
|
||||
if dotenv::from_filename(".env").is_ok() {
|
||||
return;
|
||||
}
|
||||
if let Ok(exe) = std::env::current_exe() {
|
||||
if let Some(root) = exe.parent().and_then(|p| p.parent()).and_then(|p| p.parent()) {
|
||||
let _ = dotenv::from_filename(root.join(".env"));
|
||||
}
|
||||
}
|
||||
let _ = dotenv::from_filename("/Users/accusys/momentry_core/.env");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user