mirror of
https://github.com/RGBCube/embd-rs
synced 2025-07-27 05:27:44 +00:00
Make it work, filenames are complicated right now
This commit is contained in:
parent
af2946a3a8
commit
531adba675
3 changed files with 20 additions and 31 deletions
|
@ -39,6 +39,7 @@ pub struct File {
|
|||
}
|
||||
|
||||
fn read_dir(path: &PathBuf) -> Vec<DirEntry> {
|
||||
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)
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<TokenStream> {
|
|||
};
|
||||
|
||||
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),
|
||||
})
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue