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