From b027df5f1da6e6be6ffa0d55d9fc07425b93be33 Mon Sep 17 00:00:00 2001 From: Kurt Wolf Date: Tue, 19 Dec 2023 17:57:31 -0500 Subject: [PATCH] error message and whitespace tweaks --- libninja/src/rust.rs | 4 +++- libninja/src/rust/io.rs | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/libninja/src/rust.rs b/libninja/src/rust.rs index 0bf183d..da6231c 100644 --- a/libninja/src/rust.rs +++ b/libninja/src/rust.rs @@ -11,6 +11,7 @@ use proc_macro2::TokenStream; use quote::quote; use syn::Item; use text_io::read; +use tracing::debug; use codegen::ToRustIdent; use codegen::ToRustType; @@ -188,7 +189,8 @@ fn write_file_with_template(mut file: File, template: Option) -> anyhow::Result<()> { +pub fn write_rust_file_to_path(path: &Path, file: mir::File) -> anyhow::Result<()> { let code = file.to_rust_code(); write_rust_code_to_path(path, code) } @@ -17,9 +17,9 @@ pub fn write_rust_to_path(path: &Path, code: TokenStream, template: &str) -> any let code = format_code(code)?; let mut f = fs::open(path)?; let mut s = template.to_string(); - if !s.ends_with('\n') { + if !s.is_empty() && !s.ends_with('\n') { s += "\n"; } s += &code; fs::write_file(path, &s) -} +} \ No newline at end of file