diff --git a/Cargo.lock b/Cargo.lock index 628d953a..845a8073 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2174,9 +2174,9 @@ checksum = "63335b2e2c34fae2fb0aa2cecfd9f0832a1e24b3b32ecec612c3426d46dc8aaa" [[package]] name = "num-complex" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" dependencies = [ "num-traits", ] @@ -2805,9 +2805,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51f344d206c5e1b010eec27349b815a4805f70a778895959d70b74b9b529b30a" +checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" [[package]] name = "rustls-webpki" @@ -2878,18 +2878,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.200" +version = "1.0.201" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddc6f9cc94d67c0e21aaf7eda3a010fd3af78ebf6e096aa6e2e13c79749cce4f" +checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.200" +version = "1.0.201" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "856f046b9400cee3c8c94ed572ecdb752444c24528c035cd35882aad6f492bcb" +checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" dependencies = [ "proc-macro2", "quote", @@ -2898,9 +2898,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.116" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "itoa", "ryu", diff --git a/crates/weaver_codegen_test/build.rs b/crates/weaver_codegen_test/build.rs index 979da23b..f4873166 100644 --- a/crates/weaver_codegen_test/build.rs +++ b/crates/weaver_codegen_test/build.rs @@ -100,10 +100,13 @@ fn create_single_generated_rs_file(root: &Path) { .to_str() .expect("Failed to convert to string"); let parent_modules = relative_path.parent().map_or(vec![], |parent| { - parent.components().filter_map(|component| match component { - Component::Normal(part) => Some(part.to_string_lossy().into_owned()), - _ => None, - }).collect() + parent + .components() + .filter_map(|component| match component { + Component::Normal(part) => Some(part.to_string_lossy().into_owned()), + _ => None, + }) + .collect() }); // Skip generated.rs diff --git a/crates/weaver_forge/src/lib.rs b/crates/weaver_forge/src/lib.rs index 09d03688..f8502460 100644 --- a/crates/weaver_forge/src/lib.rs +++ b/crates/weaver_forge/src/lib.rs @@ -2,15 +2,15 @@ #![doc = include_str!("../README.md")] -use std::{fs, io}; use std::borrow::Cow; use std::fmt::{Debug, Display, Formatter}; use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex}; +use std::{fs, io}; -use minijinja::{Environment, ErrorKind, State, Value}; use minijinja::syntax::SyntaxConfig; use minijinja::value::{from_args, Object}; +use minijinja::{Environment, ErrorKind, State, Value}; use rayon::iter::IntoParallelIterator; use rayon::iter::ParallelIterator; use serde::Serialize; @@ -95,7 +95,7 @@ impl Object for TemplateObject { args: &[Value], ) -> Result { if name == "set_file_name" { - let (file_name, ): (&str, ) = from_args(args)?; + let (file_name,): (&str,) = from_args(args)?; file_name.clone_into(&mut self.file_name.lock().expect("Lock poisoned")); Ok(Value::from("")) } else { @@ -254,13 +254,7 @@ impl TemplateEngine { } }; - // @todo - remove - println!("cargo:warning=Scanning file {:?}", relative_path); - for template in tmpl_matcher.matches(relative_path) { - // @todo - remove - println!("cargo:warning=Processing file {:?}", relative_path); - let filtered_result = match template.filter.apply(context.clone()) { Ok(result) => result, Err(e) => return Some(e), @@ -274,8 +268,8 @@ impl TemplateEngine { NewContext { ctx: &filtered_result, } - .try_into() - .ok()?, + .try_into() + .ok()?, relative_path, output_dir, ) { @@ -309,8 +303,8 @@ impl TemplateEngine { NewContext { ctx: &filtered_result, } - .try_into() - .ok()?, + .try_into() + .ok()?, relative_path, output_dir, ) { @@ -347,19 +341,18 @@ impl TemplateEngine { engine.add_global("template", Value::from_object(template_object.clone())); log.loading(&format!("Generating file {}", template_file)); - // @todo - remove - println!("cargo:warning=Loading file {:?}", template_file); - let template = engine - .get_template(template_file) - .map_err(|e| { - let templates = engine.templates().map(|(name, _)| name.to_owned()).collect::>(); - let error = format!("{}. Available templates: {:?}", e, templates); - InvalidTemplateFile { - template: template_file.into(), - error, - } - })?; + let template = engine.get_template(template_file).map_err(|e| { + let templates = engine + .templates() + .map(|(name, _)| name.to_owned()) + .collect::>(); + let error = format!("{}. Available templates: {:?}", e, templates); + InvalidTemplateFile { + template: template_file.into(), + error, + } + })?; let output = template .render(ctx.clone()) @@ -521,13 +514,14 @@ fn cross_platform_loader<'x, P: AsRef + 'x>( let dir = dir.as_ref().to_path_buf(); move |name| { let path = safe_join(&dir, name)?; - println!("cargo:warning=Loader loading template base: {:?}, path:{:?}", dir, path); match fs::read_to_string(path) { Ok(result) => Ok(Some(result)), Err(err) if err.kind() == io::ErrorKind::NotFound => Ok(None), - Err(err) => Err( - minijinja::Error::new(ErrorKind::InvalidOperation, "could not read template").with_source(err), - ), + Err(err) => Err(minijinja::Error::new( + ErrorKind::InvalidOperation, + "could not read template", + ) + .with_source(err)), } } } @@ -539,14 +533,18 @@ fn safe_join(root: &Path, template: &str) -> Result { path.push(template); // Canonicalize the paths to resolve any `..` or `.` components - let canonical_root = root.canonicalize() - .map_err(|e| minijinja::Error::new( + let canonical_root = root.canonicalize().map_err(|e| { + minijinja::Error::new( ErrorKind::InvalidOperation, - format!("Failed to canonicalize root path: {}", e)))?; - let canonical_combined = path.canonicalize() - .map_err(|e| minijinja::Error::new( + format!("Failed to canonicalize root path: {}", e), + ) + })?; + let canonical_combined = path.canonicalize().map_err(|e| { + minijinja::Error::new( ErrorKind::InvalidOperation, - format!("Failed to canonicalize combined path: {}", e)))?; + format!("Failed to canonicalize combined path: {}", e), + ) + })?; // Verify that the canonical combined path starts with the canonical root path if canonical_combined.starts_with(&canonical_root) { @@ -557,7 +555,8 @@ fn safe_join(root: &Path, template: &str) -> Result { format!( "The combined path is not a subdirectory of the root path: {:?} -> {:?}", canonical_root, canonical_combined - ))) + ), + )) } } @@ -756,12 +755,12 @@ mod tests { schema.registry(registry_id).expect("registry not found"), schema.catalog(), ) - .unwrap_or_else(|e| { - panic!( - "Failed to create the context for the template evaluation: {:?}", - e - ) - }); + .unwrap_or_else(|e| { + panic!( + "Failed to create the context for the template evaluation: {:?}", + e + ) + }); engine .generate(