Skip to content

Commit

Permalink
error message and whitespace tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtbuilds committed Dec 19, 2023
1 parent f65537d commit b027df5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion libninja/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -188,7 +189,8 @@ fn write_file_with_template(mut file: File<TokenStream>, template: Option<String
// file.defs
// let template = syn::parse_file(&template)?;
if template.contains("libninja: static") {
return write_rust_file_to_path(path, file);
debug!("Writing file from template/ as-is: {}", path.display());
return fs::write_file(path, &template);
}
let doc = std::mem::take(&mut file.doc)
.to_rust_code();
Expand Down
6 changes: 3 additions & 3 deletions libninja/src/rust/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ln_core::fs;
use crate::rust::codegen::ToRustCode;
use crate::rust::format::format_code;

pub fn write_rust_file_to_path(path: &Path, file: ::mir::File<TokenStream>) -> anyhow::Result<()> {
pub fn write_rust_file_to_path(path: &Path, file: mir::File<TokenStream>) -> anyhow::Result<()> {
let code = file.to_rust_code();
write_rust_code_to_path(path, code)
}
Expand All @@ -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)
}
}

0 comments on commit b027df5

Please sign in to comment.