fix issue where linked packages would not load dylibs correctly
This commit is contained in:
@@ -563,18 +563,27 @@ Shop.open_package_dylib = function(pkg) {
|
|||||||
if (cfg.dependencies) {
|
if (cfg.dependencies) {
|
||||||
for (var alias in cfg.dependencies) {
|
for (var alias in cfg.dependencies) {
|
||||||
var dep_pkg = cfg.dependencies[alias]
|
var dep_pkg = cfg.dependencies[alias]
|
||||||
Shop.open_package_dylib(dep_pkg)
|
try {
|
||||||
|
Shop.open_package_dylib(dep_pkg)
|
||||||
|
} catch (dep_e) {
|
||||||
|
// Dependency dylib load failed, continue with others
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Ignore errors reading cell.toml
|
// Error reading toml, continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var dl_path = get_lib_path(pkg)
|
var dl_path = get_lib_path(pkg)
|
||||||
if (fd.is_file(dl_path)) {
|
if (fd.is_file(dl_path)) {
|
||||||
if (!open_dls[dl_path]) {
|
if (!open_dls[dl_path]) {
|
||||||
open_dls[dl_path] = os.dylib_open(dl_path)
|
try {
|
||||||
|
open_dls[dl_path] = os.dylib_open(dl_path)
|
||||||
|
} catch (e) {
|
||||||
|
dylib_visited[pkg] = false
|
||||||
|
throw e
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -582,20 +591,19 @@ Shop.open_package_dylib = function(pkg) {
|
|||||||
// Resolve a C symbol by searching:
|
// Resolve a C symbol by searching:
|
||||||
// 1. If package_context is null, only check core internal symbols
|
// 1. If package_context is null, only check core internal symbols
|
||||||
// 2. Otherwise: own package (internal then dylib) -> other packages (internal then dylib) -> core (internal only)
|
// 2. Otherwise: own package (internal then dylib) -> other packages (internal then dylib) -> core (internal only)
|
||||||
// Core is never loaded as a dynamic library via dlopen
|
// Core is never loaded as a dynamic library via dlopen
|
||||||
function resolve_c_symbol(path, package_context)
|
function resolve_c_symbol(path, package_context) {
|
||||||
{
|
var explicit = split_explicit_package_import(path)
|
||||||
var explicit = split_explicit_package_import(path)
|
if (explicit) {
|
||||||
if (explicit) {
|
if (is_internal_path(explicit.path) && package_context && explicit.package != package_context)
|
||||||
if (is_internal_path(explicit.path) && package_context && explicit.package != package_context)
|
explicit = null
|
||||||
explicit = null
|
}
|
||||||
}
|
if (explicit) {
|
||||||
if (explicit) {
|
var sym = make_c_symbol(explicit.package, explicit.path)
|
||||||
var sym = make_c_symbol(explicit.package, explicit.path)
|
if (os.internal_exists(sym)) {
|
||||||
if (os.internal_exists(sym)) {
|
return {
|
||||||
return {
|
symbol: function() { return os.load_internal(sym) },
|
||||||
symbol: function() { return os.load_internal(sym) },
|
scope: SCOPE_PACKAGE,
|
||||||
scope: SCOPE_PACKAGE,
|
|
||||||
package: explicit.package,
|
package: explicit.package,
|
||||||
path: sym
|
path: sym
|
||||||
}
|
}
|
||||||
|
|||||||
37
package.cm
37
package.cm
@@ -3,6 +3,7 @@ var package = {}
|
|||||||
var fd = use('fd')
|
var fd = use('fd')
|
||||||
var toml = use('toml')
|
var toml = use('toml')
|
||||||
var os = use('os')
|
var os = use('os')
|
||||||
|
var link = use('link')
|
||||||
|
|
||||||
// Convert package name to a safe directory name
|
// Convert package name to a safe directory name
|
||||||
// For absolute paths (local packages), replace / with _
|
// For absolute paths (local packages), replace / with _
|
||||||
@@ -22,6 +23,18 @@ function get_path(name)
|
|||||||
// If name is already an absolute path, use it directly
|
// If name is already an absolute path, use it directly
|
||||||
if (name.startsWith('/'))
|
if (name.startsWith('/'))
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
// Check if this package is linked - if so, use the link target directly
|
||||||
|
// This avoids symlink-related issues with file reading
|
||||||
|
var link_target = link.get_target(name)
|
||||||
|
if (link_target) {
|
||||||
|
// If link target is a local path, use it directly
|
||||||
|
if (link_target.startsWith('/'))
|
||||||
|
return link_target
|
||||||
|
// Otherwise it's another package name, resolve that
|
||||||
|
return os.global_shop_path + '/packages/' + link_target.replaceAll('@', '_')
|
||||||
|
}
|
||||||
|
|
||||||
// Remote packages use nested directories, so don't transform slashes
|
// Remote packages use nested directories, so don't transform slashes
|
||||||
return os.global_shop_path + '/packages/' + name.replaceAll('@', '_')
|
return os.global_shop_path + '/packages/' + name.replaceAll('@', '_')
|
||||||
}
|
}
|
||||||
@@ -36,7 +49,12 @@ package.load_config = function(name)
|
|||||||
if (!content || content.trim().length == 0)
|
if (!content || content.trim().length == 0)
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
return toml.decode(content)
|
var result = toml.decode(content)
|
||||||
|
if (!result) {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
package.save_config = function(name, config)
|
package.save_config = function(name, config)
|
||||||
@@ -131,11 +149,18 @@ package.split_alias = function(name, path)
|
|||||||
var parts = path.split('/')
|
var parts = path.split('/')
|
||||||
var first_part = parts[0]
|
var first_part = parts[0]
|
||||||
|
|
||||||
var config = package.load_config(name)
|
try {
|
||||||
if (config.dependencies && config.dependencies[first_part]) {
|
var config = package.load_config(name)
|
||||||
var dep_locator = config.dependencies[first_part]
|
if (!config) return null
|
||||||
var remaining_path = parts.slice(1).join('/')
|
|
||||||
return { package: dep_locator, path: remaining_path }
|
var deps = config.dependencies
|
||||||
|
if (deps && deps[first_part]) {
|
||||||
|
var dep_locator = deps[first_part]
|
||||||
|
var remaining_path = parts.slice(1).join('/')
|
||||||
|
return { package: dep_locator, path: remaining_path }
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Config doesn't exist or couldn't be loaded
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
return null
|
||||||
|
|||||||
Reference in New Issue
Block a user