Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions crates/bevy_macro_utils/src/bevy_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use std::{
path::{Path, PathBuf},
time::SystemTime,
};
use toml_edit::{DocumentMut, Item};
use toml_edit::{ImDocument, Item};

/// The path to the `Cargo.toml` file for the Bevy project.
#[derive(Debug)]
pub struct BevyManifest {
manifest: DocumentMut,
manifest: ImDocument<Box<str>>,
modified_time: SystemTime,
}

Expand All @@ -34,14 +34,15 @@ impl BevyManifest {
return manifest;
}
}

let manifest = BevyManifest {
manifest: Self::read_manifest(&manifest_path),
modified_time,
};

let key = manifest_path.clone();
let mut manifests = MANIFESTS.write();
manifests.insert(
manifest_path.clone(),
BevyManifest {
manifest: Self::read_manifest(&manifest_path),
modified_time,
},
);
manifests.insert(key, manifest);

RwLockReadGuard::map(RwLockWriteGuard::downgrade(manifests), |manifests| {
manifests.get(&manifest_path).unwrap()
Expand Down Expand Up @@ -69,11 +70,11 @@ impl BevyManifest {
std::fs::metadata(cargo_manifest_path).and_then(|metadata| metadata.modified())
}

fn read_manifest(path: &Path) -> DocumentMut {
fn read_manifest(path: &Path) -> ImDocument<Box<str>> {
let manifest = std::fs::read_to_string(path)
.unwrap_or_else(|_| panic!("Unable to read cargo manifest: {}", path.display()));
manifest
.parse::<DocumentMut>()
.unwrap_or_else(|_| panic!("Unable to read cargo manifest: {}", path.display()))
.into_boxed_str();
ImDocument::parse(manifest)
.unwrap_or_else(|_| panic!("Failed to parse cargo manifest: {}", path.display()))
}

Expand Down