import graph

This commit is contained in:
2026-02-19 03:19:24 -06:00
parent bab4d50b2a
commit 06ad466b1a
4 changed files with 258 additions and 8 deletions

View File

@@ -420,7 +420,7 @@ core_extras.native_mode = native_mode
// NOW load shop -- it receives all of the above via env
var shop = use_core('internal/shop')
if (native_mode) use_core('build')
use_core('build')
var time = use_core('time')
var toml = use_core('toml')
@@ -498,10 +498,8 @@ function pretty_format(rec) {
var out = null
var i = 0
var fr = null
if (rec.source && rec.source.file)
src = rec.source.file + ":" + text(rec.source.line)
ev = is_text(rec.event) ? rec.event : json.encode(rec.event, false)
out = `[${aid}] [${rec.channel}] ${src} ${ev}\n`
out = `[${aid}] [${rec.channel}] ${ev}\n`
if (rec.stack && length(rec.stack) > 0) {
for (i = 0; i < length(rec.stack); i = i + 1) {
fr = rec.stack[i]
@@ -1248,6 +1246,20 @@ $_.clock(_ => {
}
var pkg = file_info ? file_info.package : null
// Pre-build C modules for all transitive dependencies
var _deps = null
var _di = 0
if (pkg && shop.ensure_package_dylibs) {
_deps = package.gather_dependencies(pkg)
_di = 0
while (_di < length(_deps)) {
shop.ensure_package_dylibs(_deps[_di])
_di = _di + 1
}
shop.ensure_package_dylibs(pkg)
}
env.use = function(path) {
var ck = 'core/' + path
if (use_cache[ck]) return use_cache[ck]

View File

@@ -1220,7 +1220,7 @@ function execute_module(info)
// C only
used = call_c_module(c_resolve)
} else {
print(`Module ${info.path} could not be found`); disrupt
log.shop(`Module could not be found (c_resolve scope=${info.c_resolve.scope}, mod_resolve scope=${info.mod_resolve.scope}, cache_key=${info.cache_key})`); disrupt
}
if (!used) { print(`Module ${info} returned null`); disrupt }
@@ -1230,8 +1230,21 @@ function execute_module(info)
function get_module(path, package_context) {
var info = resolve_module_info(path, package_context)
var _ctx_dir = null
var _alias = null
if (!info) { print(`Module ${path} could not be found in ${package_context}`); disrupt }
if (!info) {
log.shop(`Module '${path}' could not be found in package '${package_context}'`)
_ctx_dir = package_context ? (starts_with(package_context, '/') ? package_context : get_packages_dir() + '/' + safe_package_path(package_context)) : null
if (_ctx_dir) {
if (fd.is_file(_ctx_dir + '/' + path + '.c') || fd.is_file(_ctx_dir + '/' + path + '.cpp'))
log.shop(`C source exists at ${_ctx_dir}/${path}.c but was not compiled - run 'cell build'`)
}
_alias = pkg_tools.split_alias(package_context, path)
if (_alias == null && search(path, '/') != null)
log.shop(`Alias '${array(path, '/')[0]}' could not be resolved in package '${package_context}'`)
disrupt
}
return execute_module(info)
}
@@ -1254,7 +1267,20 @@ Shop.use = function use(path, package_context) {
}
var info = resolve_module_info(path, package_context)
if (!info) { print(`Module ${path} could not be found in ${package_context}`); disrupt }
var _ctx_dir2 = null
var _alias2 = null
if (!info) {
log.shop(`Module '${path}' could not be found in package '${package_context}'`)
_ctx_dir2 = package_context ? (starts_with(package_context, '/') ? package_context : get_packages_dir() + '/' + safe_package_path(package_context)) : null
if (_ctx_dir2) {
if (fd.is_file(_ctx_dir2 + '/' + path + '.c') || fd.is_file(_ctx_dir2 + '/' + path + '.cpp'))
log.shop(`C source exists at ${_ctx_dir2}/${path}.c but was not compiled - run 'cell build'`)
}
_alias2 = pkg_tools.split_alias(package_context, path)
if (_alias2 == null && search(path, '/') != null)
log.shop(`Alias '${array(path, '/')[0]}' could not be resolved in package '${package_context}'`)
disrupt
}
if (use_cache[info.cache_key])
return use_cache[info.cache_key]
@@ -1272,6 +1298,28 @@ Shop.resolve_use_path = function(path, ctx) {
return info.path
}
// Resolve a use() module path to {resolved_path, package, type} without compiling.
// type is 'script', 'native', or null. Checks .cm files, C symbols, and aliases.
Shop.resolve_import_info = function(path, ctx) {
var mod_info = resolve_path(path + '.cm', ctx)
var c_info = null
var c_pkg = null
if (mod_info)
return {resolved_path: mod_info.path, package: mod_info.pkg, type: 'script'}
c_info = resolve_c_symbol(path, ctx)
if (c_info && c_info.scope < 900) {
c_pkg = c_info.package
if (!c_pkg) {
if (c_info.scope == SCOPE_CORE) c_pkg = 'core'
else c_pkg = ctx
}
return {resolved_path: null, package: c_pkg, type: 'native'}
}
return null
}
// Get cache path for a package and commit
function get_cache_path(pkg, commit) {
return global_shop_path + '/cache/' + replace(replace(pkg, '@','_'), '/','_') + '_' + commit + '.zip'
@@ -1710,6 +1758,7 @@ Shop.get_lib_dir = function() {
}
Shop.ensure_dir = ensure_dir
Shop.ensure_package_dylibs = ensure_package_dylibs
Shop.get_local_dir = function() {
return global_shop_path + "/local"