diff --git a/embed/src/dir.rs b/embed/src/dir.rs index 6152443..231902d 100644 --- a/embed/src/dir.rs +++ b/embed/src/dir.rs @@ -5,11 +5,13 @@ use std::{ path::PathBuf, }; +#[derive(Debug, Clone)] pub enum DirEntry { Dir(Dir), File(File), } +#[derive(Debug, Clone)] pub struct Dir { pub children: Vec, pub path: PathBuf, @@ -30,6 +32,7 @@ impl Dir { } } +#[derive(Debug, Clone)] pub struct File { pub content: Vec, pub path: PathBuf, @@ -70,22 +73,15 @@ pub fn __include_dir(caller: &str, path: &str) -> Dir { } #[macro_export] -macro_rules! __dir { - ($caller:literal, $path:literal) => {{ +macro_rules! dir { + ($path:literal) => {{ #[cfg(debug_assertions)] { - ::embed::__include_dir($caller, $path) + ::embed::__include_dir(file!(), $path) } #[cfg(not(debug_assertions))] { - ::embed_macros::__include_dir!($caller, $path) + ::embed_macros::__include_dir!($path) } }}; } - -#[macro_export] -macro_rules! dir { - ($path:literal) => { - ::embed::__dir!(file!(), $path) - }; -} diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 3cbe8d9..9edefa2 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -13,6 +13,6 @@ edition = "2021" proc_macro = true [dependencies] -proc-macro2 = "1" +proc-macro2 = { version = "1", features = [ "span-locations" ] } quote = "1" syn = "2" diff --git a/macros/src/lib.rs b/macros/src/lib.rs index f318cc9..4f26371 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg(procmacro2_semver_exempt)] + use std::{ fs, path::PathBuf, @@ -7,38 +9,19 @@ use proc_macro as pm1; use proc_macro2::TokenStream; use quote::quote; use syn::{ - parse::{ - Parse, - ParseStream, - }, parse_macro_input, + spanned::Spanned, LitStr, - Token, }; -struct TwoStrArgs { - caller: String, - path: String, -} - -impl Parse for TwoStrArgs { - fn parse(input: ParseStream) -> syn::Result { - let caller = input.parse::()?.value(); - - input.parse::()?; - - let path = input.parse::()?.value(); - - Ok(Self { caller, path }) - } -} - #[proc_macro] pub fn __include_dir(input: pm1::TokenStream) -> pm1::TokenStream { - let input2 = input.clone(); - let TwoStrArgs { caller, path } = parse_macro_input!(input2 as TwoStrArgs); + let caller = TokenStream::from(input).span().source_file().path(); - let path = PathBuf::from(caller) + let input2 = input.clone(); + let path = parse_macro_input!(input2 as LitStr).value(); + + let path = caller .parent() .expect("Failed to get the parent of file") .join(path);