From 4c10ad8f5426b148a0e84b89eae91d62de6319b1 Mon Sep 17 00:00:00 2001 From: Shane Celis Date: Tue, 16 Jan 2024 05:11:39 -0500 Subject: [PATCH 1/3] bug: Don't evaluate cfg inside of macro. --- crates/bevy_asset/src/io/embedded/mod.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/bevy_asset/src/io/embedded/mod.rs b/crates/bevy_asset/src/io/embedded/mod.rs index 0448a7cdd83a7..0423bd9b1ee8a 100644 --- a/crates/bevy_asset/src/io/embedded/mod.rs +++ b/crates/bevy_asset/src/io/embedded/mod.rs @@ -199,12 +199,21 @@ macro_rules! embedded_asset { .world .resource_mut::<$crate::io::embedded::EmbeddedAssetRegistry>(); let path = $crate::embedded_path!($source_path, $path); - #[cfg(feature = "embedded_watcher")] - let full_path = std::path::Path::new(file!()).parent().unwrap().join($path); - #[cfg(not(feature = "embedded_watcher"))] - let full_path = std::path::PathBuf::new(); - embedded.insert_asset(full_path, &path, include_bytes!($path)); + let watched_path = $crate::io::embedded::watched_path(file!(), $path); + embedded.insert_asset(watched_path, &path, include_bytes!($path)); }}; + +} + +// Returns the path used by the watcher when the embedded_watcher feature is +// enabled. Returns an empty PathBuf otherwise. +#[doc(hidden)] +pub fn watched_path(source_file_path: &'static str, asset_path: &'static str) -> PathBuf { + #[cfg(feature = "embedded_watcher")] + let path = PathBuf::from(source_file_path).parent().unwrap().join(asset_path); + #[cfg(not(feature = "embedded_watcher"))] + let path = PathBuf::from(""); + path } /// Loads an "internal" asset by embedding the string stored in the given `path_str` and associates it with the given handle. From a5acf9ff400dc0ca37ef8a7231c12859defe4b79 Mon Sep 17 00:00:00 2001 From: Shane Celis Date: Tue, 16 Jan 2024 05:40:57 -0500 Subject: [PATCH 2/3] chore: Run cargo fmt --all --- crates/bevy_asset/src/io/embedded/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/bevy_asset/src/io/embedded/mod.rs b/crates/bevy_asset/src/io/embedded/mod.rs index 0423bd9b1ee8a..cd321a6bc9943 100644 --- a/crates/bevy_asset/src/io/embedded/mod.rs +++ b/crates/bevy_asset/src/io/embedded/mod.rs @@ -202,7 +202,6 @@ macro_rules! embedded_asset { let watched_path = $crate::io::embedded::watched_path(file!(), $path); embedded.insert_asset(watched_path, &path, include_bytes!($path)); }}; - } // Returns the path used by the watcher when the embedded_watcher feature is @@ -210,7 +209,10 @@ macro_rules! embedded_asset { #[doc(hidden)] pub fn watched_path(source_file_path: &'static str, asset_path: &'static str) -> PathBuf { #[cfg(feature = "embedded_watcher")] - let path = PathBuf::from(source_file_path).parent().unwrap().join(asset_path); + let path = PathBuf::from(source_file_path) + .parent() + .unwrap() + .join(asset_path); #[cfg(not(feature = "embedded_watcher"))] let path = PathBuf::from(""); path From daec40f9fe444f417d055a69fffb34df5a542a85 Mon Sep 17 00:00:00 2001 From: Shane Celis Date: Tue, 16 Jan 2024 07:16:19 -0500 Subject: [PATCH 3/3] refactor: Avoid unused variable warning. --- crates/bevy_asset/src/io/embedded/mod.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/bevy_asset/src/io/embedded/mod.rs b/crates/bevy_asset/src/io/embedded/mod.rs index cd321a6bc9943..80340ac9debbc 100644 --- a/crates/bevy_asset/src/io/embedded/mod.rs +++ b/crates/bevy_asset/src/io/embedded/mod.rs @@ -204,18 +204,21 @@ macro_rules! embedded_asset { }}; } -// Returns the path used by the watcher when the embedded_watcher feature is -// enabled. Returns an empty PathBuf otherwise. +/// Returns the path used by the watcher. #[doc(hidden)] +#[cfg(feature = "embedded_watcher")] pub fn watched_path(source_file_path: &'static str, asset_path: &'static str) -> PathBuf { - #[cfg(feature = "embedded_watcher")] - let path = PathBuf::from(source_file_path) + PathBuf::from(source_file_path) .parent() .unwrap() - .join(asset_path); - #[cfg(not(feature = "embedded_watcher"))] - let path = PathBuf::from(""); - path + .join(asset_path) +} + +/// Returns an empty PathBuf. +#[doc(hidden)] +#[cfg(not(feature = "embedded_watcher"))] +pub fn watched_path(_source_file_path: &'static str, _asset_path: &'static str) -> PathBuf { + PathBuf::from("") } /// Loads an "internal" asset by embedding the string stored in the given `path_str` and associates it with the given handle.