Skip to content

Commit

Permalink
fix: use Path API for AssetPath manipulation in embedded_path macro
Browse files Browse the repository at this point in the history
Path manipulation is far less error prone when using the std::path::Path
API. This lets us remove all instances of "/" which is not a portable
path separator.
  • Loading branch information
bonsairobo committed Nov 5, 2023
1 parent 97970f2 commit f4f1684
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions crates/bevy_asset/src/io/embedded/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ impl EmbeddedAssetRegistry {
#[macro_export]
macro_rules! embedded_path {
($path_str: expr) => {{
embedded_path!("/src/", $path_str)
embedded_path!("src", $path_str)
}};

($source_path: expr, $path_str: expr) => {{
let crate_name = module_path!().split(':').next().unwrap();
let after_src = file!().split($source_path).nth(1).unwrap();
let file_path = std::path::Path::new(after_src)
.parent()
.unwrap()
.join($path_str);
let file_path = std::path::Path::new(file!());
let after_src = file_path
.strip_prefix($source_path)
.unwrap_or_else(|_| panic!("{file_path:?} does not have prefix {}", $source_path));
let file_path = after_src.parent().unwrap().join($path_str);
std::path::Path::new(crate_name).join(file_path)
}};
}
Expand Down Expand Up @@ -186,7 +186,7 @@ macro_rules! embedded_path {
#[macro_export]
macro_rules! embedded_asset {
($app: ident, $path: expr) => {{
embedded_asset!($app, "/src/", $path)
embedded_asset!($app, "src", $path)
}};

($app: ident, $source_path: expr, $path: expr) => {{
Expand Down

0 comments on commit f4f1684

Please sign in to comment.