fix building
This commit is contained in:
62
build.cm
62
build.cm
@@ -26,9 +26,10 @@ function get_local_dir() {
|
||||
}
|
||||
|
||||
// Replace sigils in a string
|
||||
// Supports: $LOCAL -> .cell/local, $PACKAGE -> package dir (if provided)
|
||||
// Supports: $LOCAL -> absolute path to .cell/local, $PACKAGE -> package dir (if provided)
|
||||
function replace_sigils(str, pkg_dir) {
|
||||
var r = replace(str, '$LOCAL', get_local_dir())
|
||||
var local = fd.realpath('.') + '/' + get_local_dir()
|
||||
var r = replace(str, '$LOCAL', local)
|
||||
if (pkg_dir) r = replace(r, '$PACKAGE', pkg_dir)
|
||||
return r
|
||||
}
|
||||
@@ -138,6 +139,11 @@ Build.compile_file = function(pkg, file, target, opts) {
|
||||
push(cmd_parts, '-DCELL_USE_NAME=' + sym_name)
|
||||
push(cmd_parts, '-I"' + pkg_dir + '"')
|
||||
|
||||
// Auto-discover include/ directory
|
||||
if (fd.is_dir(pkg_dir + '/include')) {
|
||||
push(cmd_parts, '-I"' + pkg_dir + '/include"')
|
||||
}
|
||||
|
||||
// External packages need core's source dir for cell.h, quickjs.h, blob.h
|
||||
if (pkg != 'core') {
|
||||
core_dir = shop.get_package_dir('core')
|
||||
@@ -165,7 +171,7 @@ Build.compile_file = function(pkg, file, target, opts) {
|
||||
push(cmd_parts, '"' + src_path + '"')
|
||||
|
||||
var cmd_str = text(cmd_parts, ' ')
|
||||
|
||||
|
||||
// Content hash: command + file content
|
||||
var file_content = fd.slurp(src_path)
|
||||
var hash_input = cmd_str + '\n' + text(file_content)
|
||||
@@ -180,13 +186,32 @@ Build.compile_file = function(pkg, file, target, opts) {
|
||||
return obj_path
|
||||
}
|
||||
|
||||
// Compile
|
||||
var full_cmd = cmd_str + ' -o "' + obj_path + '"'
|
||||
// Compile — capture stderr to detect missing-header vs real errors
|
||||
var err_path = '/tmp/cell_build_err_' + hash + '.log'
|
||||
var full_cmd = cmd_str + ' -o "' + obj_path + '" 2>"' + err_path + '"'
|
||||
var err_text = null
|
||||
var missing = null
|
||||
var err_lines = null
|
||||
var first_err = null
|
||||
log.console('Compiling ' + file)
|
||||
var ret = os.system(full_cmd)
|
||||
if (ret != 0) {
|
||||
print('Compilation failed: ' + file)
|
||||
print('Command: ' + full_cmd)
|
||||
if (fd.is_file(err_path)) {
|
||||
err_text = text(fd.slurp(err_path))
|
||||
}
|
||||
if (err_text) {
|
||||
missing = search(err_text, /fatal error: [''].*[''] file not found/)
|
||||
if (missing == null) missing = search(err_text, /fatal error: .*: No such file or directory/)
|
||||
}
|
||||
if (missing != null) {
|
||||
err_lines = array(err_text, "\n")
|
||||
first_err = length(err_lines) > 0 ? err_lines[0] : err_text
|
||||
print(file + ': ' + first_err + ' (SDK not installed?)')
|
||||
} else {
|
||||
print('Compilation failed: ' + file)
|
||||
if (err_text) print(err_text)
|
||||
else print('Command: ' + full_cmd)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -353,8 +378,6 @@ Build.build_dynamic = function(pkg, target, buildtype) {
|
||||
var pkg_dir = shop.get_package_dir(pkg)
|
||||
var cached_cflags = replace_sigils_array(pkg_tools.get_flags(pkg, 'CFLAGS', _target), pkg_dir)
|
||||
|
||||
log.console(`CFLAGS ${pkg}: ${text(cached_cflags, '|')}`)
|
||||
|
||||
// Compile support sources to cached objects
|
||||
var sources = pkg_tools.get_sources(pkg)
|
||||
var support_objects = []
|
||||
@@ -785,6 +808,9 @@ Build.build_all_dynamic = function(target, buildtype) {
|
||||
var packages = shop.list_packages()
|
||||
var results = []
|
||||
var core_mods = null
|
||||
var total_files = 0
|
||||
var total_ok = 0
|
||||
var total_fail = 0
|
||||
|
||||
// Build core first
|
||||
if (find(packages, function(p) { return p == 'core' }) != null) {
|
||||
@@ -799,6 +825,24 @@ Build.build_all_dynamic = function(target, buildtype) {
|
||||
push(results, {package: pkg, modules: pkg_mods})
|
||||
})
|
||||
|
||||
// Print build report
|
||||
print('\n--- Build Report ---')
|
||||
arrfor(results, function(r) {
|
||||
var pkg_dir = shop.get_package_dir(r.package)
|
||||
var c_files = pkg_tools.get_c_files(r.package, _target, true)
|
||||
var file_count = length(c_files)
|
||||
var ok_count = length(r.modules)
|
||||
var fail_count = file_count - ok_count
|
||||
total_files = total_files + file_count
|
||||
total_ok = total_ok + ok_count
|
||||
total_fail = total_fail + fail_count
|
||||
if (file_count == 0) return
|
||||
var status = fail_count == 0 ? 'OK' : `${ok_count}/${file_count}`
|
||||
print(` ${r.package}: ${status}`)
|
||||
})
|
||||
print(`Total: ${total_ok}/${total_files} compiled, ${total_fail} failed`)
|
||||
print('--------------------\n')
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user