mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-21 13:15:50 +00:00
This PR refactors all of the methods on `Vfs` from accepting `&mut self` to accepting `&self` and keeping data wrapped in a mutex. This builds on previous changes to make reference count file contents and cleans up the last places where we're returning borrowed data out of the VFS interface. Once this change lands, there are two possible directions we can go that I see: * Conservative: Refactor all remaining `&mut Vfs` handles to `&Vfs` * Interesting: Embrace ref counting by changing `Vfs` methods to accept `self: Arc<Self>`, which makes the `VfsEntry` API no longer need an explicit `Vfs` argument for its operations. * Change VfsFetcher to be immutable with internal locking * Refactor Vfs::would_be_resident * Refactor Vfs::read_if_not_exists * Refactor Vfs::raise_file_removed * Refactor Vfs::raise_file_changed * Add Vfs::get_internal as bits of Vfs::get * Switch Vfs to use internal locking * Migrate all Vfs methods from &mut self to &self * Make VfsEntry access Vfs immutably * Remove outer VFS locking (#260) * Refactor all snapshot middleware to accept &Vfs instead of &mut Vfs * Remove outer VFS Mutex across the board
66 lines
2.2 KiB
Rust
66 lines
2.2 KiB
Rust
//! Initialization routines that are used by more than one Rojo command or
|
|
//! utility.
|
|
|
|
use std::path::Path;
|
|
|
|
use rbx_dom_weak::RbxInstanceProperties;
|
|
|
|
use crate::{
|
|
project::{Project, ProjectLoadError},
|
|
snapshot::{apply_patch_set, compute_patch_set, InstancePropertiesWithMeta, RojoTree},
|
|
snapshot_middleware::{snapshot_from_vfs, InstanceSnapshotContext, SnapshotPluginContext},
|
|
vfs::{Vfs, VfsFetcher},
|
|
};
|
|
|
|
pub fn start<F: VfsFetcher>(
|
|
fuzzy_project_path: &Path,
|
|
vfs: &Vfs<F>,
|
|
) -> (Option<Project>, RojoTree) {
|
|
log::trace!("Loading project file from {}", fuzzy_project_path.display());
|
|
let maybe_project = match Project::load_fuzzy(fuzzy_project_path) {
|
|
Ok(project) => Some(project),
|
|
Err(ProjectLoadError::NotFound) => None,
|
|
Err(other) => panic!("{}", other), // TODO: return error upward
|
|
};
|
|
|
|
log::trace!("Constructing initial tree");
|
|
let mut tree = RojoTree::new(InstancePropertiesWithMeta {
|
|
properties: RbxInstanceProperties {
|
|
name: "ROOT".to_owned(),
|
|
class_name: "Folder".to_owned(),
|
|
properties: Default::default(),
|
|
},
|
|
metadata: Default::default(),
|
|
});
|
|
|
|
let root_id = tree.get_root_id();
|
|
|
|
log::trace!("Constructing snapshot context");
|
|
let mut snapshot_context = InstanceSnapshotContext::default();
|
|
if let Some(project) = &maybe_project {
|
|
// If the project file defines no plugins, then there's no need to
|
|
// initialize the snapshot plugin context.
|
|
if !project.plugins.is_empty() {
|
|
snapshot_context.plugin_context = Some(SnapshotPluginContext::new(&project.plugins));
|
|
}
|
|
}
|
|
|
|
log::trace!("Reading project root");
|
|
let entry = vfs
|
|
.get(fuzzy_project_path)
|
|
.expect("could not get project path");
|
|
|
|
log::trace!("Generating snapshot of instances from VFS");
|
|
let snapshot = snapshot_from_vfs(&mut snapshot_context, vfs, &entry)
|
|
.expect("snapshot failed")
|
|
.expect("snapshot did not return an instance");
|
|
|
|
log::trace!("Computing patch set");
|
|
let patch_set = compute_patch_set(&snapshot, &tree, root_id);
|
|
|
|
log::trace!("Applying patch set");
|
|
apply_patch_set(&mut tree, patch_set);
|
|
|
|
(maybe_project, tree)
|
|
}
|