mirror of
https://github.com/RGBCube/embd-rs
synced 2025-07-26 21:17:44 +00:00
Add error message for trying to embed .
This commit is contained in:
parent
2b624eb362
commit
41e02a9b3b
3 changed files with 17 additions and 5 deletions
|
@ -79,6 +79,7 @@ macro_rules! dir {
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
{
|
{
|
||||||
::embed_macros::__include_dir!(file!(), $path) // FIXME
|
::embed_macros::__include_dir!(file!(), $path) // FIXME
|
||||||
|
// ::embed_macros::__include_dir!("embed/src/lib.rs", $path)
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,5 +5,5 @@ mod file;
|
||||||
pub use file::*;
|
pub use file::*;
|
||||||
|
|
||||||
// fn expand() {
|
// fn expand() {
|
||||||
// dir!("")
|
// dir!(".")
|
||||||
// }
|
// }
|
||||||
|
|
|
@ -35,23 +35,33 @@ impl Parse for TwoStrArgs {
|
||||||
|
|
||||||
#[proc_macro]
|
#[proc_macro]
|
||||||
pub fn __include_dir(input: pm1::TokenStream) -> pm1::TokenStream {
|
pub fn __include_dir(input: pm1::TokenStream) -> pm1::TokenStream {
|
||||||
let TwoStrArgs { caller, path } = parse_macro_input!(input as TwoStrArgs);
|
let input2 = input.clone();
|
||||||
|
let TwoStrArgs { caller, path } = parse_macro_input!(input2 as TwoStrArgs);
|
||||||
|
|
||||||
let path = PathBuf::from(caller)
|
let path = PathBuf::from(caller)
|
||||||
.parent()
|
.parent()
|
||||||
.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("..") {
|
let path = if path.ends_with("..") {
|
||||||
path
|
|
||||||
} else {
|
|
||||||
path.parent().unwrap().to_path_buf()
|
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");
|
||||||
|
|
||||||
|
if path_str.ends_with(".") {
|
||||||
|
return syn::Error::new_spanned(
|
||||||
|
TokenStream::from(input),
|
||||||
|
"Can't embed current file as it is not a directory",
|
||||||
|
)
|
||||||
|
.to_compile_error()
|
||||||
|
.into();
|
||||||
|
}
|
||||||
|
|
||||||
let children = read_dir(&path, &path);
|
let children = read_dir(&path, &path);
|
||||||
let children_tokens = quote! {
|
let children_tokens = quote! {
|
||||||
vec![#(#children),*]
|
vec![#(#children),*]
|
||||||
|
@ -100,6 +110,7 @@ fn read_dir(base: &PathBuf, path: &PathBuf) -> Vec<TokenStream> {
|
||||||
entries.push(quote! {
|
entries.push(quote! {
|
||||||
::embed::DirEntry(::embed::File {
|
::embed::DirEntry(::embed::File {
|
||||||
content: include_bytes!(#path_str),
|
content: include_bytes!(#path_str),
|
||||||
|
// content: include_bytes(#path_str),
|
||||||
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