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:
@@ -362,11 +362,24 @@ def get_fps_from_ffprobe(video_path):
|
||||
"-show_entries", "stream=r_frame_rate",
|
||||
"-of", "csv=p=0", video_path]
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
||||
fps_str = result.stdout.strip()
|
||||
if "/" in fps_str:
|
||||
num, den = fps_str.split("/")
|
||||
return float(num) / float(den)
|
||||
return float(fps_str)
|
||||
# ffprobe 的 csv 輸出可能帶多餘欄位或重複行(如 "60000/1001," 或
|
||||
# "60000/1001\n\n60000/1001"),需逐行取第一個可解析且 >0 的值。
|
||||
for line in result.stdout.splitlines():
|
||||
for token in line.split(","):
|
||||
token = token.strip()
|
||||
if not token:
|
||||
continue
|
||||
try:
|
||||
if "/" in token:
|
||||
num, den = token.split("/", 1)
|
||||
fps = float(num) / float(den)
|
||||
else:
|
||||
fps = float(token)
|
||||
except (ValueError, ZeroDivisionError):
|
||||
continue
|
||||
if fps > 0:
|
||||
return fps
|
||||
return None
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user