diff options
author | Ben Bridle <ben@derelict.engineering> | 2024-11-01 07:24:31 +1300 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2024-11-01 07:24:31 +1300 |
commit | fe710b107c5e9902a01ad3e5405b7d9da6ee9844 (patch) | |
tree | 4eade1100d2c338bea9903ac4058f5a779124c96 /src | |
parent | 8d9c19cdc6c252eb3b833b6808a7a8f1e0d173a9 (diff) | |
download | bedrock-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.rs | 5 |
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); } |