summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2024-11-01 07:24:31 +1300
committerBen Bridle <ben@derelict.engineering>2024-11-01 07:24:31 +1300
commitfe710b107c5e9902a01ad3e5405b7d9da6ee9844 (patch)
tree4eade1100d2c338bea9903ac4058f5a779124c96 /src
parent8d9c19cdc6c252eb3b833b6808a7a8f1e0d173a9 (diff)
downloadbedrock-asm-fe710b107c5e9902a01ad3e5405b7d9da6ee9844.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/symbol_resolver.rs5
1 files changed, 4 insertions, 1 deletions
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);
}