From 2e9cabb0432e4b2b47a0b9be42dc29d39f1768c9 Mon Sep 17 00:00:00 2001 From: Nixon Date: Sat, 8 Jun 2024 17:03:29 +0800 Subject: [PATCH] chore: remove unused libs & files --- Cargo.lock | 44 +---- crates/motiongfx_core/macros/Cargo.toml | 1 - crates/motiongfx_macro_utils/Cargo.toml | 14 -- crates/motiongfx_macro_utils/src/lib.rs | 175 ------------------ crates/motiongfx_vello/Cargo.toml | 1 - crates/motiongfx_vello/macros/Cargo.toml | 17 -- crates/motiongfx_vello/macros/src/lib.rs | 40 ---- .../motiongfx_vello/src/motion/fill_motion.rs | 2 - .../src/motion/stroke_motion.rs | 2 - 9 files changed, 2 insertions(+), 294 deletions(-) delete mode 100644 crates/motiongfx_macro_utils/Cargo.toml delete mode 100644 crates/motiongfx_macro_utils/src/lib.rs delete mode 100644 crates/motiongfx_vello/macros/Cargo.toml delete mode 100644 crates/motiongfx_vello/macros/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index d62ef76..1963704 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2538,21 +2538,11 @@ name = "motiongfx_core_macros" version = "0.1.0" dependencies = [ "bevy_macro_utils", - "motiongfx_macro_utils", "proc-macro2", "quote", "syn 2.0.46", ] -[[package]] -name = "motiongfx_macro_utils" -version = "0.1.0" -dependencies = [ - "quote", - "syn 2.0.46", - "toml_edit 0.22.12", -] - [[package]] name = "motiongfx_vello" version = "0.1.0" @@ -2560,16 +2550,6 @@ dependencies = [ "bevy", "bevy_vello_graphics", "motiongfx_core", - "motiongfx_vello_macros", -] - -[[package]] -name = "motiongfx_vello_macros" -version = "0.1.0" -dependencies = [ - "motiongfx_macro_utils", - "quote", - "syn 2.0.46", ] [[package]] @@ -3606,7 +3586,7 @@ checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ "indexmap", "toml_datetime", - "winnow 0.5.15", + "winnow", ] [[package]] @@ -3617,18 +3597,7 @@ checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03" dependencies = [ "indexmap", "toml_datetime", - "winnow 0.5.15", -] - -[[package]] -name = "toml_edit" -version = "0.22.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3328d4f68a705b2a4498da1d580585d39a6510f98318a2cec3018a7ec61ddef" -dependencies = [ - "indexmap", - "toml_datetime", - "winnow 0.6.9", + "winnow", ] [[package]] @@ -4472,15 +4441,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "winnow" -version = "0.6.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86c949fede1d13936a99f14fafd3e76fd642b556dd2ce96287fbe2e0151bfac6" -dependencies = [ - "memchr", -] - [[package]] name = "x11-dl" version = "2.21.0" diff --git a/crates/motiongfx_core/macros/Cargo.toml b/crates/motiongfx_core/macros/Cargo.toml index 3a41a43..59105fb 100644 --- a/crates/motiongfx_core/macros/Cargo.toml +++ b/crates/motiongfx_core/macros/Cargo.toml @@ -12,7 +12,6 @@ proc-macro = true syn = "2.0" quote = "1.0" bevy_macro_utils = "0.13" -motiongfx_macro_utils = { path = "../../motiongfx_macro_utils" } proc-macro2 = "1.0" [lints] diff --git a/crates/motiongfx_macro_utils/Cargo.toml b/crates/motiongfx_macro_utils/Cargo.toml deleted file mode 100644 index ecc9f9c..0000000 --- a/crates/motiongfx_macro_utils/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "motiongfx_macro_utils" -version.workspace = true -edition.workspace = true -license.workspace = true -repository.workspace = true - -[dependencies] -syn = "2.0" -quote = "1.0" -toml_edit = "0.22" - -[lints] -workspace = true diff --git a/crates/motiongfx_macro_utils/src/lib.rs b/crates/motiongfx_macro_utils/src/lib.rs deleted file mode 100644 index d15b0d5..0000000 --- a/crates/motiongfx_macro_utils/src/lib.rs +++ /dev/null @@ -1,175 +0,0 @@ -extern crate proc_macro; - -use std::{env, path::PathBuf}; - -use proc_macro::TokenStream; -use syn::DeriveInput; -use toml_edit::{DocumentMut, Item}; - -/// The path to the `Cargo.toml` file for the MotionGfx project. -pub struct MotionGfxManifest { - manifest: DocumentMut, -} - -impl Default for MotionGfxManifest { - fn default() -> Self { - Self { - manifest: env::var_os("CARGO_MANIFEST_DIR") - .map(PathBuf::from) - .map(|mut path| { - path.push("Cargo.toml"); - if !path.exists() { - panic!( - "No Cargo manifest found for crate. Expected: {}", - path.display() - ); - } - let manifest = std::fs::read_to_string(path.clone()).unwrap_or_else(|_| { - panic!("Unable to read cargo manifest: {}", path.display()) - }); - manifest.parse::().unwrap_or_else(|_| { - panic!("Failed to parse cargo manifest: {}", path.display()) - }) - }) - .expect("CARGO_MANIFEST_DIR is not defined."), - } - } -} -const BEVY_MOTIONGFX: &str = "bevy_motiongfx"; - -impl MotionGfxManifest { - /// Attempt to retrieve the [path](syn::Path) of a particular package in - /// the [manifest](MotionGfxManifest) by [name](str). - pub fn maybe_get_path(&self, name: &str) -> Option { - fn dep_package(dep: &Item) -> Option<&str> { - if dep.as_str().is_some() { - None - } else { - dep.get("package").map(|name| { - println!("{:?}", name.as_str()); - name.as_str().unwrap() - }) - } - } - - let find_in_deps = |deps: &Item| -> Option { - let package = if let Some(dep) = deps.get(name) { - return Some(Self::parse_str(dep_package(dep).unwrap_or(name))); - } else if let Some(dep) = deps.get(BEVY_MOTIONGFX) { - dep_package(dep).unwrap_or(BEVY_MOTIONGFX) - } else { - return None; - }; - - let mut path = Self::parse_str::(package); - if let Some(module) = name.strip_prefix("motiongfx_") { - path.segments.push(Self::parse_str(module)); - } - Some(path) - }; - - let package_name = self - .manifest - .get("package") - .and_then(|p| p.get("name")) - .unwrap(); - let deps = self.manifest.get("dependencies"); - let deps_dev = self.manifest.get("dev-dependencies"); - - // First, check if we are referencing the package itself - if let Some(package_name) = package_name.as_str() { - if package_name == name { - return Some(Self::parse_str("crate")); - } - } - - deps.and_then(find_in_deps) - .or_else(|| deps_dev.and_then(find_in_deps)) - } - - /// Returns the path for the crate with the given name. - /// - /// This is a convenience method for constructing a [manifest] and - /// calling the [`get_path`] method. - /// - /// This method should only be used where you just need the path and can't - /// cache the [manifest]. If caching is possible, it's recommended to create - /// the [manifest] yourself and use the [`get_path`] method. - /// - /// [`get_path`]: Self::get_path - /// [manifest]: Self - pub fn get_path_direct(name: &str) -> syn::Path { - Self::default().get_path(name) - } - - /// Returns the path for the crate with the given name. - pub fn get_path(&self, name: &str) -> syn::Path { - self.maybe_get_path(name) - .unwrap_or_else(|| Self::parse_str(name)) - } - - /// Attempt to parse the provided [path](str) as a [syntax tree node](syn::parse::Parse) - pub fn try_parse_str(path: &str) -> Option { - syn::parse(path.parse::().ok()?).ok() - } - - /// Attempt to parse provided [path](str) as a [syntax tree node](syn::parse::Parse). - /// - /// # Panics - /// - /// Will panic if the path is not able to be parsed. For a non-panicing option, see [`try_parse_str`] - /// - /// [`try_parse_str`]: Self::try_parse_str - pub fn parse_str(path: &str) -> T { - Self::try_parse_str(path).unwrap() - } - - /// Attempt to get a subcrate [path](syn::Path) under Bevy MotionGfx by [name](str) - pub fn get_subcrate(&self, subcrate: &str) -> Option { - self.maybe_get_path(BEVY_MOTIONGFX) - .map(|bevy_path| { - let mut segments = bevy_path.segments; - segments.push(MotionGfxManifest::parse_str(subcrate)); - syn::Path { - leading_colon: None, - segments, - } - }) - .or_else(|| self.maybe_get_path(&format!("motiongfx_{subcrate}"))) - } -} - -/// Attempt to get the one and only field tagged by a given [attribute name](str). -/// -/// # Panics -/// -/// Will panic if no field is found or more than 1 field is found. -pub fn get_one_field_of_attribute(ast: &DeriveInput, attr_name: &str) -> syn::Ident { - let syn::Data::Struct(struct_data) = &ast.data else { - panic!("Can only be implemented on a Struct."); - }; - - let field_filter: Vec<&syn::Field> = struct_data - .fields - .iter() - .filter(|field| { - field - .attrs - .iter() - .filter(|attr| attr.path().is_ident(attr_name)) - .count() - == 1 - }) - .collect(); - - if field_filter.len() != 1 { - panic!( - "Expected exactly 1 field with #[{}] attribute. Given {}.", - attr_name, - field_filter.len() - ); - } - - let shape_ident = field_filter[0].ident.as_ref().unwrap(); - shape_ident.clone() -} diff --git a/crates/motiongfx_vello/Cargo.toml b/crates/motiongfx_vello/Cargo.toml index 1def9aa..efb6960 100644 --- a/crates/motiongfx_vello/Cargo.toml +++ b/crates/motiongfx_vello/Cargo.toml @@ -7,7 +7,6 @@ repository.workspace = true [dependencies] motiongfx_core = { version = "0.1.0", path = "../motiongfx_core" } -motiongfx_vello_macros = { version = "0.1.0", path = "macros" } bevy_vello_graphics = { version = "0.1.0", git = "https://github.com/voxell-tech/bevy_vello_graphics" } bevy = "0.13" diff --git a/crates/motiongfx_vello/macros/Cargo.toml b/crates/motiongfx_vello/macros/Cargo.toml deleted file mode 100644 index 9650725..0000000 --- a/crates/motiongfx_vello/macros/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "motiongfx_vello_macros" -version.workspace = true -edition.workspace = true -license.workspace = true -repository.workspace = true - -[lib] -proc-macro = true - -[dependencies] -syn = "2.0" -quote = "1.0" -motiongfx_macro_utils = { path = "../../motiongfx_macro_utils" } - -[lints] -workspace = true diff --git a/crates/motiongfx_vello/macros/src/lib.rs b/crates/motiongfx_vello/macros/src/lib.rs deleted file mode 100644 index 178be54..0000000 --- a/crates/motiongfx_vello/macros/src/lib.rs +++ /dev/null @@ -1,40 +0,0 @@ -use motiongfx_macro_utils::get_one_field_of_attribute; -use proc_macro::TokenStream; -use quote::quote; -use syn::{parse_macro_input, DeriveInput}; - -#[proc_macro_derive(FillMotion, attributes(fill))] -pub fn fill_motion_derive_macro(input: TokenStream) -> TokenStream { - let input = parse_macro_input!(input as DeriveInput); - - let ident = input.ident.clone(); - let (impl_generics, type_generics, where_clause) = input.generics.split_for_impl(); - let fill_ident = get_one_field_of_attribute(&input, "fill"); - - quote! { - impl #impl_generics FillMotion for #ident #type_generics #where_clause { - fn get_fill(&mut self) -> &mut ::bevy_vello_graphics::fill::Fill { - &mut self.#fill_ident - } - } - } - .into() -} - -#[proc_macro_derive(StrokeMotion, attributes(stroke))] -pub fn stroke_motion_derive_macro(input: TokenStream) -> TokenStream { - let input = parse_macro_input!(input as DeriveInput); - - let ident = input.ident.clone(); - let (impl_generics, type_generics, where_clause) = input.generics.split_for_impl(); - let stroke_ident = get_one_field_of_attribute(&input, "stroke"); - - quote! { - impl #impl_generics StrokeMotion for #ident #type_generics #where_clause { - fn get_stroke(&mut self) -> &mut ::bevy_vello_graphics::stroke::Stroke { - &mut self.#stroke_ident - } - } - } - .into() -} diff --git a/crates/motiongfx_vello/src/motion/fill_motion.rs b/crates/motiongfx_vello/src/motion/fill_motion.rs index d3cb52c..3ddc2a5 100644 --- a/crates/motiongfx_vello/src/motion/fill_motion.rs +++ b/crates/motiongfx_vello/src/motion/fill_motion.rs @@ -1,5 +1,3 @@ -pub use motiongfx_vello_macros::FillMotion; - use bevy::prelude::*; use bevy_vello_graphics::prelude::*; use motiongfx_core::{ diff --git a/crates/motiongfx_vello/src/motion/stroke_motion.rs b/crates/motiongfx_vello/src/motion/stroke_motion.rs index c2511f8..a2b3ce1 100644 --- a/crates/motiongfx_vello/src/motion/stroke_motion.rs +++ b/crates/motiongfx_vello/src/motion/stroke_motion.rs @@ -1,5 +1,3 @@ -pub use motiongfx_vello_macros::StrokeMotion; - use bevy::prelude::*; use bevy_vello_graphics::prelude::*; use motiongfx_core::{