diff --git a/embed/src/dir.rs b/embed/src/dir.rs index 0bc81a1..406d67e 100644 --- a/embed/src/dir.rs +++ b/embed/src/dir.rs @@ -39,6 +39,7 @@ pub struct File { } fn read_dir(path: &PathBuf) -> Vec { + dbg!(path); let mut entries = Vec::new(); for entry in fs::read_dir(path).expect("Failed to list directory contents") { @@ -72,17 +73,3 @@ pub fn __include_dir_runtime(caller: &str, path: &str) -> Dir { Dir { children, path } } - -#[macro_export] -macro_rules! dir { - ($path:literal) => {{ - #[cfg(debug_assertions)] - { - ::embed::__include_dir_runtime(file!(), $path) - } - #[cfg(not(debug_assertions))] - { - ::embed::__include_dir!($path) - } - }}; -} diff --git a/embed/src/lib.rs b/embed/src/lib.rs index d67790b..24a9aba 100644 --- a/embed/src/lib.rs +++ b/embed/src/lib.rs @@ -3,6 +3,5 @@ mod dir; mod file; -pub use dir::__include_dir_runtime; -#[doc(hidden)] -pub use embed_macros::__include_dir; +pub use dir::*; +pub use embed_macros::dir; diff --git a/embed_macros/src/lib.rs b/embed_macros/src/lib.rs index a00ddd0..49b6794 100644 --- a/embed_macros/src/lib.rs +++ b/embed_macros/src/lib.rs @@ -1,6 +1,7 @@ #![cfg(procmacro2_semver_exempt)] use std::{ + env, fs, path::PathBuf, }; @@ -14,10 +15,18 @@ use syn::{ LitStr, }; -#[doc(hidden)] #[proc_macro] -pub fn __include_dir(input: pm1::TokenStream) -> pm1::TokenStream { - let caller = TokenStream::from(input).span().source_file().path(); +pub fn dir(input: pm1::TokenStream) -> pm1::TokenStream { + if false { + let path = parse_macro_input!(input as LitStr).value(); + + return quote! { + ::embed::__include_dir_runtime(file!(), #path) + } + .into(); + } + + let caller = dbg!(TokenStream::from(input.clone()).span().source_file().path()); let input2 = input.clone(); let path = parse_macro_input!(input2 as LitStr).value(); @@ -27,12 +36,6 @@ pub fn __include_dir(input: pm1::TokenStream) -> pm1::TokenStream { .expect("Failed to get the parent of file") .join(path); - let path = if path.ends_with("..") { - path.parent().unwrap().to_path_buf() - } else { - path - }; - let path_str = path .to_str() .expect("Failed to get the string representation of PathBuf"); @@ -51,12 +54,12 @@ pub fn __include_dir(input: pm1::TokenStream) -> pm1::TokenStream { vec![#(#children),*] }; - (quote! { + quote! { ::embed::Dir { children: #children_tokens, path: ::std::path::PathBuf::from(#path_str), } - }) + } .into() } @@ -85,15 +88,15 @@ fn read_dir(base: &PathBuf, path: &PathBuf) -> Vec { }; entries.push(quote! { - ::embed::DirEntry(::embed::Dir { + ::embed::DirEntry::Dir(::embed::Dir { children: #children_tokens, path: ::std::path::PathBuf::from(#path_str), }) }); } else if filetype.is_file() { entries.push(quote! { - ::embed::DirEntry(::embed::File { - content: include_bytes!(#path_str), + ::embed::DirEntry::File(::embed::File { + content: include_bytes!(#path_str).to_vec(), path: ::std::path::PathBuf::from(#path_str), }) });