From fe710b107c5e9902a01ad3e5405b7d9da6ee9844 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Fri, 1 Nov 2024 07:24:31 +1300 Subject: Don't merge empty source files When a library contains only macro definitions, the definitions will be kept in the .head.brc file and the main .brc file will be empty. To prevent from cluttering the merged source file with path comments for empty files, the contents of the file are first checked, and if the file contains only whitespace it will not be merged. --- src/symbol_resolver.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/symbol_resolver.rs b/src/symbol_resolver.rs index c96ba67..ab4f8e1 100644 --- a/src/symbol_resolver.rs +++ b/src/symbol_resolver.rs @@ -251,6 +251,9 @@ impl SymbolResolver { fn push_source_code_to_string(string: &mut String, source_file: &SourceFile) { + // Don't push source code if it contains only whitespace. + let source_code = &source_file.symbols.source_code; + if source_code.chars().all(|c| c.is_whitespace()) { return; } // Ensure that sections are separated by two newlines. if !string.is_empty() { if !string.ends_with('\n') { string.push('\n'); } @@ -260,7 +263,7 @@ fn push_source_code_to_string(string: &mut String, source_file: &SourceFile) { let path_str = source_file.path.as_os_str().to_string_lossy(); let path_comment = format!("(: {path_str} )\n"); string.push_str(&path_comment); - string.push_str(&source_file.symbols.source_code); + string.push_str(&source_code); } -- cgit v1.2.3-70-g09d2