diff --git a/src/cli/upload.rs b/src/cli/upload.rs index f6f847af..aed6ba30 100644 --- a/src/cli/upload.rs +++ b/src/cli/upload.rs @@ -2,7 +2,7 @@ use memofs::Vfs; use reqwest::header::{ACCEPT, CONTENT_TYPE, COOKIE, USER_AGENT}; use snafu::{ResultExt, Snafu}; -use crate::{auth_cookie::get_auth_cookie, cli::UploadCommand, common_setup}; +use crate::{auth_cookie::get_auth_cookie, cli::UploadCommand, serve_session::ServeSession}; #[derive(Debug, Snafu)] pub struct UploadError(Error); @@ -35,11 +35,11 @@ fn upload_inner(options: UploadCommand) -> Result<(), Error> { .or_else(get_auth_cookie) .ok_or(Error::NeedAuthCookie)?; - log::trace!("Constructing in-memory filesystem"); let vfs = Vfs::new_default(); - let (_maybe_project, tree) = common_setup::start(&options.absolute_project(), &vfs); + let session = ServeSession::new(vfs, &options.absolute_project()); + let tree = session.tree(); let inner_tree = tree.inner(); let root_id = inner_tree.get_root_id(); let root_instance = inner_tree.get_instance(root_id).unwrap(); diff --git a/src/common_setup.rs b/src/common_setup.rs deleted file mode 100644 index 7de22c06..00000000 --- a/src/common_setup.rs +++ /dev/null @@ -1,57 +0,0 @@ -//! Initialization routines that are used by more than one Rojo command or -//! utility. - -use std::path::Path; - -use memofs::Vfs; -use rbx_dom_weak::RbxInstanceProperties; - -use crate::{ - project::Project, - snapshot::{ - apply_patch_set, compute_patch_set, InstanceContext, InstancePropertiesWithMeta, - PathIgnoreRule, RojoTree, - }, - snapshot_middleware::snapshot_from_vfs, -}; - -pub fn start(fuzzy_project_path: &Path, vfs: &Vfs) -> (Option, RojoTree) { - log::trace!("Loading project file from {}", fuzzy_project_path.display()); - let maybe_project = Project::load_fuzzy(fuzzy_project_path).expect("TODO: Project load failed"); - - 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(); - - let mut instance_context = InstanceContext::default(); - - if let Some(project) = &maybe_project { - let rules = project.glob_ignore_paths.iter().map(|glob| PathIgnoreRule { - glob: glob.clone(), - base_path: project.folder_location().to_path_buf(), - }); - - instance_context.add_path_ignore_rules(rules); - } - - log::trace!("Generating snapshot of instances from VFS"); - let snapshot = snapshot_from_vfs(&instance_context, vfs, &fuzzy_project_path) - .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) -} diff --git a/src/lib.rs b/src/lib.rs index fdfab494..454449b2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,6 @@ mod tree_view; mod auth_cookie; mod change_processor; -mod common_setup; mod error; mod glob; mod message_queue; diff --git a/src/serve_session.rs b/src/serve_session.rs index 8d737733..c72a2279 100644 --- a/src/serve_session.rs +++ b/src/serve_session.rs @@ -7,14 +7,18 @@ use std::{ use crossbeam_channel::Sender; use memofs::Vfs; +use rbx_dom_weak::RbxInstanceProperties; use crate::{ change_processor::ChangeProcessor, - common_setup, message_queue::MessageQueue, project::Project, session_id::SessionId, - snapshot::{AppliedPatchSet, PatchSet, RojoTree}, + snapshot::{ + apply_patch_set, compute_patch_set, AppliedPatchSet, InstanceContext, + InstancePropertiesWithMeta, PatchSet, PathIgnoreRule, RojoTree, + }, + snapshot_middleware::snapshot_from_vfs, }; /// Contains all of the state for a Rojo serve session. @@ -86,7 +90,7 @@ pub struct ServeSession { /// block to prevent needing to spread Send + Sync + 'static into everything /// that handles ServeSession. impl ServeSession { - /// Start a new serve session from the given in-memory filesystem and start + /// Start a new serve session from the given in-memory filesystem and start /// path. /// /// The project file is expected to be loaded out-of-band since it's @@ -94,12 +98,45 @@ impl ServeSession { /// in-memory filesystem layer. pub fn new>(vfs: Vfs, start_path: P) -> Self { let start_path = start_path.as_ref(); - - log::trace!("Starting new ServeSession at path {}", start_path.display(),); - let start_time = Instant::now(); - let (root_project, tree) = common_setup::start(start_path, &vfs); + log::trace!("Starting new ServeSession at path {}", start_path.display()); + + log::trace!("Loading project file from {}", start_path.display()); + let root_project = Project::load_fuzzy(start_path).expect("TODO: Project load failed"); + + 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(); + + let mut instance_context = InstanceContext::default(); + + if let Some(project) = &root_project { + let rules = project.glob_ignore_paths.iter().map(|glob| PathIgnoreRule { + glob: glob.clone(), + base_path: project.folder_location().to_path_buf(), + }); + + instance_context.add_path_ignore_rules(rules); + } + + log::trace!("Generating snapshot of instances from VFS"); + let snapshot = snapshot_from_vfs(&instance_context, &vfs, &start_path) + .expect("snapshot failed") + .expect("snapshot did not return an instance"); + + log::trace!("Computing initial patch set"); + let patch_set = compute_patch_set(&snapshot, &tree, root_id); + + log::trace!("Applying initial patch set"); + apply_patch_set(&mut tree, patch_set); let session_id = SessionId::new(); let message_queue = MessageQueue::new();