Debug messages shall now only appear if you enable the debug option

main
Joca 2025-11-02 23:53:34 -03:00
parent 3aa51748bd
commit 397df566ae
Signed by: jocadbz
GPG Key ID: B1836DCE2F50BDF7
2 changed files with 64 additions and 24 deletions

View File

@ -127,13 +127,15 @@ pub fn build(mut build_config config.BuildConfig) ! {
mut shared_libs_built := []string{} mut shared_libs_built := []string{}
for mut lib_config in build_config.shared_libs { for mut lib_config in build_config.shared_libs {
if lib_config.sources.len == 0 { if lib_config.sources.len == 0 {
if build_config.verbose { if build_config.debug || build_config.verbose || lib_config.debug || lib_config.verbose {
println('Skipping empty shared library: ${lib_config.name}') println('Skipping empty shared library: ${lib_config.name}')
} }
continue continue
} }
if build_config.debug || build_config.verbose || lib_config.debug || lib_config.verbose {
println('Building shared library: ${lib_config.name}') println('Building shared library: ${lib_config.name}')
}
build_shared_library(mut lib_config, build_config) or { build_shared_library(mut lib_config, build_config) or {
return error('Failed to build shared library ${lib_config.name}: ${err}') return error('Failed to build shared library ${lib_config.name}: ${err}')
} }
@ -149,13 +151,15 @@ pub fn build(mut build_config config.BuildConfig) ! {
// Build tools/executables from config // Build tools/executables from config
for mut tool_config in build_config.tools { for mut tool_config in build_config.tools {
if tool_config.sources.len == 0 { if tool_config.sources.len == 0 {
if build_config.verbose { if build_config.debug || build_config.verbose || tool_config.debug || tool_config.verbose {
println('Skipping empty tool: ${tool_config.name}') println('Skipping empty tool: ${tool_config.name}')
} }
continue continue
} }
if build_config.debug || build_config.verbose || tool_config.debug || tool_config.verbose {
println('Building tool: ${tool_config.name}') println('Building tool: ${tool_config.name}')
}
build_tool(mut tool_config, build_config) or { build_tool(mut tool_config, build_config) or {
return error('Failed to build tool ${tool_config.name}: ${err}') return error('Failed to build tool ${tool_config.name}: ${err}')
} }
@ -209,7 +213,9 @@ fn build_from_directives(mut build_config config.BuildConfig, mut shared_libs_bu
for unit_name in build_order { for unit_name in build_order {
directive := dep_graph[unit_name] directive := dep_graph[unit_name]
if build_config.debug || build_config.verbose {
println('Building unit: ${unit_name}') println('Building unit: ${unit_name}')
}
// Find source file for this unit // Find source file for this unit
mut source_file := '' mut source_file := ''
@ -264,7 +270,9 @@ fn build_from_directives(mut build_config config.BuildConfig, mut shared_libs_bu
// Compile source file // Compile source file
if needs_recompile(source_file, obj_file) { if needs_recompile(source_file, obj_file) {
if build_config.debug || build_config.verbose {
println('Compiling ${unit_name}: ${source_file}...') println('Compiling ${unit_name}: ${source_file}...')
}
target_config := config.TargetConfig(config.ToolConfig{ target_config := config.TargetConfig(config.ToolConfig{
name: unit_name name: unit_name
sources: [source_file] sources: [source_file]
@ -290,7 +298,9 @@ fn build_from_directives(mut build_config config.BuildConfig, mut shared_libs_bu
lib_output_dir := os.join_path(build_config.bin_dir, 'lib') lib_output_dir := os.join_path(build_config.bin_dir, 'lib')
// ensure output directory exists // ensure output directory exists
os.mkdir_all(lib_output_dir) or { return error('Failed to create shared lib output directory: ${lib_output_dir}') } os.mkdir_all(lib_output_dir) or { return error('Failed to create shared lib output directory: ${lib_output_dir}') }
if build_config.debug || build_config.verbose {
println('Linking shared library: ${lib_output_dir}/${directive.unit_name.split('/').last()}.so') println('Linking shared library: ${lib_output_dir}/${directive.unit_name.split('/').last()}.so')
}
if build_config.verbose { if build_config.verbose {
// show contents of lib dir for debugging // show contents of lib dir for debugging
files := os.ls(lib_output_dir) or { []string{} } files := os.ls(lib_output_dir) or { []string{} }
@ -310,7 +320,9 @@ fn build_from_directives(mut build_config config.BuildConfig, mut shared_libs_bu
} else { } else {
// Link executable // Link executable
executable := os.join_path(build_config.bin_dir, directive.output_path) executable := os.join_path(build_config.bin_dir, directive.output_path)
if build_config.debug || build_config.verbose {
println('Linking executable: ${executable}') println('Linking executable: ${executable}')
}
link_tool([obj_file], executable, build_config, config.ToolConfig{ link_tool([obj_file], executable, build_config, config.ToolConfig{
name: directive.unit_name name: directive.unit_name
libraries: directive.link_libs libraries: directive.link_libs
@ -465,7 +477,7 @@ pub fn clean(build_config config.BuildConfig) {
fn build_shared_library(mut lib_config config.SharedLibConfig, build_config config.BuildConfig) ! { fn build_shared_library(mut lib_config config.SharedLibConfig, build_config config.BuildConfig) ! {
if lib_config.sources.len == 0 { if lib_config.sources.len == 0 {
if build_config.verbose { if build_config.debug || build_config.verbose || lib_config.debug || lib_config.verbose {
println('No sources specified for shared library ${lib_config.name}, skipping') println('No sources specified for shared library ${lib_config.name}, skipping')
} }
return return
@ -495,7 +507,9 @@ fn build_shared_library(mut lib_config config.SharedLibConfig, build_config conf
os.mkdir_all(obj_path) or { return error('Failed to create object directory: ${obj_path}') } os.mkdir_all(obj_path) or { return error('Failed to create object directory: ${obj_path}') }
if needs_recompile(src_file, obj_file) { if needs_recompile(src_file, obj_file) {
if build_config.debug || build_config.verbose || lib_config.debug || lib_config.verbose {
println('Compiling ${lib_config.name}: ${src_file}...') println('Compiling ${lib_config.name}: ${src_file}...')
}
lib_target_config := config.TargetConfig(lib_config) lib_target_config := config.TargetConfig(lib_config)
// show compile command if verbose // show compile command if verbose
if lib_config.verbose || build_config.verbose { if lib_config.verbose || build_config.verbose {
@ -526,7 +540,9 @@ fn build_shared_library(mut lib_config config.SharedLibConfig, build_config conf
lib_output_dir := lib_config.output_dir lib_output_dir := lib_config.output_dir
// ensure output directory exists // ensure output directory exists
os.mkdir_all(lib_output_dir) or { return error('Failed to create shared lib output directory: ${lib_output_dir}') } os.mkdir_all(lib_output_dir) or { return error('Failed to create shared lib output directory: ${lib_output_dir}') }
if build_config.debug || build_config.verbose || lib_config.debug || lib_config.verbose {
println('Linking shared library: ${lib_output_dir}/${lib_config.name.split('/').last()}.so') println('Linking shared library: ${lib_output_dir}/${lib_config.name.split('/').last()}.so')
}
link_shared_library(object_files, lib_config.name, lib_output_dir, build_config, lib_config) or { link_shared_library(object_files, lib_config.name, lib_output_dir, build_config, lib_config) or {
return error('Failed to link shared library ${lib_config.name}') return error('Failed to link shared library ${lib_config.name}')
} }
@ -538,7 +554,7 @@ fn build_shared_library(mut lib_config config.SharedLibConfig, build_config conf
fn build_tool(mut tool_config config.ToolConfig, build_config config.BuildConfig) ! { fn build_tool(mut tool_config config.ToolConfig, build_config config.BuildConfig) ! {
if tool_config.sources.len == 0 { if tool_config.sources.len == 0 {
if build_config.verbose { if build_config.debug || build_config.verbose || tool_config.debug || tool_config.verbose {
println('No sources specified for tool ${tool_config.name}, skipping') println('No sources specified for tool ${tool_config.name}, skipping')
} }
return return
@ -568,7 +584,9 @@ fn build_tool(mut tool_config config.ToolConfig, build_config config.BuildConfig
os.mkdir_all(obj_path) or { return error('Failed to create object directory: ${obj_path}') } os.mkdir_all(obj_path) or { return error('Failed to create object directory: ${obj_path}') }
if needs_recompile(src_file, obj_file) { if needs_recompile(src_file, obj_file) {
if build_config.debug || build_config.verbose || tool_config.debug || tool_config.verbose {
println('Compiling ${tool_config.name}: ${src_file}...') println('Compiling ${tool_config.name}: ${src_file}...')
}
tool_target_config := config.TargetConfig(tool_config) tool_target_config := config.TargetConfig(tool_config)
// show compile command if verbose // show compile command if verbose
if tool_config.verbose || build_config.verbose { if tool_config.verbose || build_config.verbose {
@ -596,7 +614,9 @@ fn build_tool(mut tool_config config.ToolConfig, build_config config.BuildConfig
// Link executable // Link executable
executable := os.join_path(tool_config.output_dir, tool_config.name) executable := os.join_path(tool_config.output_dir, tool_config.name)
if build_config.debug || build_config.verbose || tool_config.debug || tool_config.verbose {
println('Linking tool: ${executable}') println('Linking tool: ${executable}')
}
link_tool(object_files, executable, build_config, tool_config) or { link_tool(object_files, executable, build_config, tool_config) or {
return error('Failed to link tool ${tool_config.name}') return error('Failed to link tool ${tool_config.name}')
} }
@ -721,7 +741,9 @@ fn compile_shaders(build_config config.BuildConfig) ! {
output_path := os.join_path(shaders_out_dir, output_name) output_path := os.join_path(shaders_out_dir, output_name)
cmd := '${glslc_path} -o ${output_path} -fshader-stage=vertex ${src_path}' cmd := '${glslc_path} -o ${output_path} -fshader-stage=vertex ${src_path}'
if build_config.debug || build_config.verbose {
println('Compiling vertex shader: ${shader}') println('Compiling vertex shader: ${shader}')
}
if build_config.verbose { if build_config.verbose {
println('Shader compile command: ${cmd}') println('Shader compile command: ${cmd}')
@ -750,7 +772,9 @@ fn compile_shaders(build_config config.BuildConfig) ! {
output_path := os.join_path(shaders_out_dir, output_name) output_path := os.join_path(shaders_out_dir, output_name)
cmd := '${glslc_path} -o ${output_path} -fshader-stage=fragment ${src_path}' cmd := '${glslc_path} -o ${output_path} -fshader-stage=fragment ${src_path}'
if build_config.debug || build_config.verbose {
println('Compiling fragment shader: ${shader}') println('Compiling fragment shader: ${shader}')
}
if build_config.verbose { if build_config.verbose {
println('Shader compile command: ${cmd}') println('Shader compile command: ${cmd}')

16
deps/deps.v vendored
View File

@ -91,7 +91,9 @@ pub fn fetch_dependencies(build_config config.BuildConfig) ! {
} }
println('Processing dependency: ${dep.name}') println('Processing dependency: ${dep.name}')
if build_config.debug || build_config.verbose {
println(' parsed: url="${dep.url}", archive="${dep.archive}", extract_to="${dep.extract_to}"') println(' parsed: url="${dep.url}", archive="${dep.archive}", extract_to="${dep.extract_to}"')
}
// Allow dependencies with only a name. If no URL is provided, skip // Allow dependencies with only a name. If no URL is provided, skip
// download/extract/clone steps and only run any provided build_cmds. // download/extract/clone steps and only run any provided build_cmds.
@ -108,10 +110,14 @@ pub fn fetch_dependencies(build_config config.BuildConfig) ! {
if is_git { if is_git {
// Clone repository if needed // Clone repository if needed
if os.is_dir(extract_to) { if os.is_dir(extract_to) {
if build_config.debug || build_config.verbose {
println('Dependency already cloned at ${extract_to}, skipping clone') println('Dependency already cloned at ${extract_to}, skipping clone')
}
} else { } else {
cmd := 'git clone --depth 1 ${url_trim} ${extract_to}' cmd := 'git clone --depth 1 ${url_trim} ${extract_to}'
if build_config.debug || build_config.verbose {
println('Running: ${cmd}') println('Running: ${cmd}')
}
code := os.system(cmd) code := os.system(cmd)
if code != 0 { if code != 0 {
return error('Failed to clone ${url_trim}: exit ${code}') return error('Failed to clone ${url_trim}: exit ${code}')
@ -133,8 +139,10 @@ pub fn fetch_dependencies(build_config config.BuildConfig) ! {
} }
} }
} else { } else {
if build_config.debug || build_config.verbose {
println('Archive already exists: ${archive_path}') println('Archive already exists: ${archive_path}')
} }
}
// Optionally verify checksum // Optionally verify checksum
if dep.checksum != '' { if dep.checksum != '' {
@ -152,7 +160,9 @@ pub fn fetch_dependencies(build_config config.BuildConfig) ! {
// Extract archive // Extract archive
if os.is_dir(extract_to) { if os.is_dir(extract_to) {
if build_config.debug || build_config.verbose {
println('Already extracted to ${extract_to}, skipping') println('Already extracted to ${extract_to}, skipping')
}
} else { } else {
os.mkdir_all(extract_to) or { return error('Failed to create ${extract_to}: ${err}') } os.mkdir_all(extract_to) or { return error('Failed to create ${extract_to}: ${err}') }
@ -160,7 +170,9 @@ pub fn fetch_dependencies(build_config config.BuildConfig) ! {
lower := archive_path.to_lower() lower := archive_path.to_lower()
if lower.ends_with('.tar.gz') || lower.ends_with('.tgz') || lower.ends_with('.tar.xz') || lower.ends_with('.tar') { if lower.ends_with('.tar.gz') || lower.ends_with('.tgz') || lower.ends_with('.tar.xz') || lower.ends_with('.tar') {
cmd := 'tar -xf ${archive_path} -C ${deps_dir}' cmd := 'tar -xf ${archive_path} -C ${deps_dir}'
if build_config.debug || build_config.verbose {
println('Extracting with: ${cmd}') println('Extracting with: ${cmd}')
}
code := os.system(cmd) code := os.system(cmd)
if code != 0 { if code != 0 {
return error('Failed to extract ${archive_path}: exit ${code}') return error('Failed to extract ${archive_path}: exit ${code}')
@ -168,7 +180,9 @@ pub fn fetch_dependencies(build_config config.BuildConfig) ! {
// If the archive created a top-level dir, caller should set extract_to to match archive content. // If the archive created a top-level dir, caller should set extract_to to match archive content.
} else if lower.ends_with('.zip') { } else if lower.ends_with('.zip') {
cmd := 'unzip -q ${archive_path} -d ${extract_to}' cmd := 'unzip -q ${archive_path} -d ${extract_to}'
if build_config.debug || build_config.verbose {
println('Extracting zip with: ${cmd}') println('Extracting zip with: ${cmd}')
}
code := os.system(cmd) code := os.system(cmd)
if code != 0 { if code != 0 {
return error('Failed to unzip ${archive_path}: exit ${code}') return error('Failed to unzip ${archive_path}: exit ${code}')
@ -192,7 +206,9 @@ pub fn fetch_dependencies(build_config config.BuildConfig) ! {
} }
for cmd_line in dep.build_cmds { for cmd_line in dep.build_cmds {
if build_config.debug || build_config.verbose {
println('Running build command for ${dep.name}: ${cmd_line}') println('Running build command for ${dep.name}: ${cmd_line}')
}
old_cwd := os.getwd() old_cwd := os.getwd()
os.chdir(run_dir) or { return error('Failed to chdir: ${err}') } os.chdir(run_dir) or { return error('Failed to chdir: ${err}') }
code := os.system(cmd_line) code := os.system(cmd_line)