mirror of
https://github.com/RGBCube/embd-rs
synced 2025-07-27 13:37: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> {
|
fn read_dir(path: &PathBuf) -> Vec<DirEntry> {
|
||||||
|
dbg!(path);
|
||||||
let mut entries = Vec::new();
|
let mut entries = Vec::new();
|
||||||
|
|
||||||
for entry in fs::read_dir(path).expect("Failed to list directory contents") {
|
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 }
|
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 dir;
|
||||||
mod file;
|
mod file;
|
||||||
|
|
||||||
pub use dir::__include_dir_runtime;
|
pub use dir::*;
|
||||||
#[doc(hidden)]
|
pub use embed_macros::dir;
|
||||||
pub use embed_macros::__include_dir;
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#![cfg(procmacro2_semver_exempt)]
|
#![cfg(procmacro2_semver_exempt)]
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
env,
|
||||||
fs,
|
fs,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
@ -14,10 +15,18 @@ use syn::{
|
||||||
LitStr,
|
LitStr,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
#[proc_macro]
|
#[proc_macro]
|
||||||
pub fn __include_dir(input: pm1::TokenStream) -> pm1::TokenStream {
|
pub fn dir(input: pm1::TokenStream) -> pm1::TokenStream {
|
||||||
let caller = TokenStream::from(input).span().source_file().path();
|
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 input2 = input.clone();
|
||||||
let path = parse_macro_input!(input2 as LitStr).value();
|
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")
|
.expect("Failed to get the parent of file")
|
||||||
.join(path);
|
.join(path);
|
||||||
|
|
||||||
let path = if path.ends_with("..") {
|
|
||||||
path.parent().unwrap().to_path_buf()
|
|
||||||
} else {
|
|
||||||
path
|
|
||||||
};
|
|
||||||
|
|
||||||
let path_str = path
|
let path_str = path
|
||||||
.to_str()
|
.to_str()
|
||||||
.expect("Failed to get the string representation of PathBuf");
|
.expect("Failed to get the string representation of PathBuf");
|
||||||
|
@ -51,12 +54,12 @@ pub fn __include_dir(input: pm1::TokenStream) -> pm1::TokenStream {
|
||||||
vec![#(#children),*]
|
vec![#(#children),*]
|
||||||
};
|
};
|
||||||
|
|
||||||
(quote! {
|
quote! {
|
||||||
::embed::Dir {
|
::embed::Dir {
|
||||||
children: #children_tokens,
|
children: #children_tokens,
|
||||||
path: ::std::path::PathBuf::from(#path_str),
|
path: ::std::path::PathBuf::from(#path_str),
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,15 +88,15 @@ fn read_dir(base: &PathBuf, path: &PathBuf) -> Vec<TokenStream> {
|
||||||
};
|
};
|
||||||
|
|
||||||
entries.push(quote! {
|
entries.push(quote! {
|
||||||
::embed::DirEntry(::embed::Dir {
|
::embed::DirEntry::Dir(::embed::Dir {
|
||||||
children: #children_tokens,
|
children: #children_tokens,
|
||||||
path: ::std::path::PathBuf::from(#path_str),
|
path: ::std::path::PathBuf::from(#path_str),
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
} else if filetype.is_file() {
|
} else if filetype.is_file() {
|
||||||
entries.push(quote! {
|
entries.push(quote! {
|
||||||
::embed::DirEntry(::embed::File {
|
::embed::DirEntry::File(::embed::File {
|
||||||
content: include_bytes!(#path_str),
|
content: include_bytes!(#path_str).to_vec(),
|
||||||
path: ::std::path::PathBuf::from(#path_str),
|
path: ::std::path::PathBuf::from(#path_str),
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue