harn_vm/stdlib/asset_paths.rs
1//! Re-export of `harn_modules::asset_paths` plus a VM-side convenience
2//! that anchors the project-root walk at the *currently-executing*
3//! source file (via `VM_SOURCE_DIR`) and falls back to the existing
4//! source-relative resolver when the path is not an `@`-prefixed asset
5//! reference.
6//!
7//! See `harn_modules::asset_paths` for the resolver itself (issue #742).
8
9use std::path::{Path, PathBuf};
10
11pub use harn_modules::asset_paths::{
12 is_asset_path, parse, resolve, stdlib_prompt_asset_path, AssetRef,
13};
14
15/// Resolve an `@`-prefixed asset path against the project root, or fall
16/// back to the legacy source-relative resolver when `path` is plain.
17///
18/// `caller_file` is optional. When `None`, the resolver anchors at the
19/// VM's thread-local source dir — the file currently executing, which
20/// `set_thread_source_dir` keeps in lockstep with imported modules
21/// (see `docs/src/modules.md` "source-relative builtins" note).
22pub fn resolve_or_source_relative(
23 path: &str,
24 caller_file: Option<&Path>,
25) -> Result<PathBuf, String> {
26 let anchor = caller_file
27 .and_then(Path::parent)
28 .map(Path::to_path_buf)
29 .unwrap_or_else(super::process::source_root_path);
30 harn_modules::asset_paths::resolve_or(path, &anchor, |p| {
31 super::process::resolve_source_asset_path(p)
32 })
33}