canonical paths

This commit is contained in:
2026-02-23 11:18:08 -06:00
parent f26b6e853d
commit 193991c532
3 changed files with 34 additions and 32 deletions

View File

@@ -255,31 +255,34 @@ function safe_canonicalize(pkg) {
// given a file, find the absolute path, package name, and import name
Shop.file_info = function(file) {
var info = {
path: file,
path: file,
is_module: false,
is_actor: false,
package: null,
name: null
}
if (ends_with(file, MOD_EXT))
info.is_module = true
else if (ends_with(file, ACTOR_EXT))
info.is_actor = true
// Find package directory and determine package name
// find_package_dir resolves symlinks internally, so we must use the
// resolved file path for substring math to get the correct name.
var pkg_dir = pkg_tools.find_package_dir(file)
var resolved_file = fd.realpath(file) || file
if (pkg_dir) {
info.package = abs_path_to_package(pkg_dir)
if (info.is_actor)
info.name = text(file, length(pkg_dir) + 1, length(file) - length(ACTOR_EXT))
info.name = text(resolved_file, length(pkg_dir) + 1, length(resolved_file) - length(ACTOR_EXT))
else if (info.is_module)
info.name = text(file, length(pkg_dir) + 1, length(file) - length(MOD_EXT))
info.name = text(resolved_file, length(pkg_dir) + 1, length(resolved_file) - length(MOD_EXT))
else
info.name = text(file, length(pkg_dir) + 1)
info.name = text(resolved_file, length(pkg_dir) + 1)
}
return info
}
@@ -525,7 +528,7 @@ function try_native_mod_dylib(pkg, stem) {
var sym = Shop.c_symbol_for_file(pkg, stem)
// Verify the symbol actually exists in the dylib before returning native descriptor
if (sym && !os.dylib_has_symbol(handle, sym) && !os.dylib_has_symbol(handle, 'cell_main')) {
log.shop('native dylib for ' + stem + ' missing symbol ' + sym + ' and cell_main, falling back to bytecode')
log.shop('native dylib for ' + stem + ' (dylib=' + build_path + ') missing symbol ' + sym + ' and cell_main, falling back to bytecode')
return null
}
return {_native: true, _handle: handle, _sym: sym}
@@ -768,6 +771,8 @@ function resolve_mod_fn(path, pkg) {
var dylib_path = null
var handle = null
var sym = null
var _fi = null
var _fi_pkg = null
policy = get_policy()
@@ -793,7 +798,10 @@ function resolve_mod_fn(path, pkg) {
if (dylib_path) {
handle = os.dylib_open(dylib_path)
if (handle) {
sym = pkg ? Shop.c_symbol_for_file(pkg, _stem || fd.basename(path)) : null
// Derive symbol from file_info (authoritative package), not caller's pkg
_fi = Shop.file_info(path)
_fi_pkg = _fi.package || pkg
sym = _fi_pkg ? Shop.c_symbol_for_file(_fi_pkg, (_fi.name ? _fi.name + (_fi.is_actor ? '.ce' : '.cm') : fd.basename(path))) : null
return {_native: true, _handle: handle, _sym: sym}
}
}
@@ -954,7 +962,7 @@ function resolve_path(path, ctx)
if (alias) {
alias_path = get_packages_dir() + '/' + fd.safe_package_path(alias.package) + '/' + alias.path
if (fd.is_file(alias_path))
return {path: alias_path, scope: SCOPE_PACKAGE, pkg: ctx}
return {path: alias_path, scope: SCOPE_PACKAGE, pkg: alias.package}
}
package_path = get_packages_dir() + '/' + fd.safe_package_path(path)
@@ -2360,17 +2368,12 @@ Shop.use_native = function(path, package_context) {
var file_info = Shop.file_info(src_path)
var pkg = file_info.package || (locator ? locator.pkg : package_context)
var sym_stem = fd.basename(src_path)
var pkg_dir = null
var sym_stem = file_info.name ? file_info.name + (file_info.is_actor ? '.ce' : '.cm') : fd.basename(src_path)
cache_key = 'native:' + text(pkg || '') + ':' + src_path
if (use_cache[cache_key]) return use_cache[cache_key]
var sym_name = null
if (pkg) {
pkg_dir = get_packages_dir() + '/' + fd.safe_package_path(pkg)
if (starts_with(src_path, pkg_dir + '/')) {
sym_stem = text(src_path, length(pkg_dir) + 1)
}
sym_name = Shop.c_symbol_for_file(pkg, sym_stem)
}