forked from rojo-rbx/rojo
Major Subsystem Rewrite (Reconciler Mk5) (#217)
This commit is contained in:
committed by
GitHub
parent
8e8291a0bd
commit
fea303ac8b
@@ -1,17 +1,17 @@
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
collections::HashMap,
|
||||
fs::File,
|
||||
io::{self, Write, BufWriter},
|
||||
path::PathBuf,
|
||||
};
|
||||
|
||||
use log::info;
|
||||
use rbx_dom_weak::{RbxTree, RbxInstanceProperties};
|
||||
use failure::Fail;
|
||||
|
||||
use crate::{
|
||||
imfs::{Imfs, FsError},
|
||||
project::{Project, ProjectLoadError},
|
||||
rbx_session::construct_oneoff_tree,
|
||||
rbx_snapshot::SnapshotError,
|
||||
imfs::new::{Imfs, RealFetcher, WatchMode, FsError},
|
||||
snapshot::{apply_patch_set, compute_patch_set},
|
||||
snapshot_middleware::snapshot_from_imfs,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -46,9 +46,6 @@ pub enum BuildError {
|
||||
#[fail(display = "Could not detect what kind of file to create")]
|
||||
UnknownOutputKind,
|
||||
|
||||
#[fail(display = "Project load error: {}", _0)]
|
||||
ProjectLoadError(#[fail(cause)] ProjectLoadError),
|
||||
|
||||
#[fail(display = "IO error: {}", _0)]
|
||||
IoError(#[fail(cause)] io::Error),
|
||||
|
||||
@@ -60,18 +57,13 @@ pub enum BuildError {
|
||||
|
||||
#[fail(display = "{}", _0)]
|
||||
FsError(#[fail(cause)] FsError),
|
||||
|
||||
#[fail(display = "{}", _0)]
|
||||
SnapshotError(#[fail(cause)] SnapshotError),
|
||||
}
|
||||
|
||||
impl_from!(BuildError {
|
||||
ProjectLoadError => ProjectLoadError,
|
||||
io::Error => IoError,
|
||||
rbx_xml::EncodeError => XmlModelEncodeError,
|
||||
rbx_binary::EncodeError => BinaryModelEncodeError,
|
||||
FsError => FsError,
|
||||
SnapshotError => SnapshotError,
|
||||
});
|
||||
|
||||
fn xml_encode_config() -> rbx_xml::EncodeOptions {
|
||||
@@ -84,18 +76,34 @@ pub fn build(options: &BuildOptions) -> Result<(), BuildError> {
|
||||
.or_else(|| detect_output_kind(options))
|
||||
.ok_or(BuildError::UnknownOutputKind)?;
|
||||
|
||||
info!("Hoping to generate file of type {:?}", output_kind);
|
||||
log::info!("Hoping to generate file of type {:?}", output_kind);
|
||||
|
||||
info!("Looking for project at {}", options.fuzzy_project_path.display());
|
||||
let mut tree = RbxTree::new(RbxInstanceProperties {
|
||||
name: "ROOT".to_owned(),
|
||||
class_name: "Folder".to_owned(),
|
||||
properties: HashMap::new(),
|
||||
});
|
||||
let root_id = tree.get_root_id();
|
||||
|
||||
let project = Project::load_fuzzy(&options.fuzzy_project_path)?;
|
||||
log::trace!("Constructing in-memory filesystem");
|
||||
let mut imfs = Imfs::new(RealFetcher::new(WatchMode::Disabled));
|
||||
|
||||
info!("Found project at {}", project.file_location.display());
|
||||
info!("Using project {:#?}", project);
|
||||
log::trace!("Reading project root");
|
||||
let entry = imfs.get(&options.fuzzy_project_path)
|
||||
.expect("could not get project path");
|
||||
|
||||
let mut imfs = Imfs::new();
|
||||
imfs.add_roots_from_project(&project)?;
|
||||
let tree = construct_oneoff_tree(&project, &imfs)?;
|
||||
log::trace!("Generating snapshot of instances from IMFS");
|
||||
let snapshot = snapshot_from_imfs(&mut imfs, &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);
|
||||
|
||||
log::trace!("Opening output file for write");
|
||||
let mut file = BufWriter::new(File::create(&options.output_file)?);
|
||||
|
||||
match output_kind {
|
||||
@@ -103,19 +111,16 @@ pub fn build(options: &BuildOptions) -> Result<(), BuildError> {
|
||||
// Model files include the root instance of the tree and all its
|
||||
// descendants.
|
||||
|
||||
let root_id = tree.get_root_id();
|
||||
rbx_xml::to_writer(&mut file, &tree, &[root_id], xml_encode_config())?;
|
||||
},
|
||||
OutputKind::Rbxlx => {
|
||||
// Place files don't contain an entry for the DataModel, but our
|
||||
// RbxTree representation does.
|
||||
|
||||
let root_id = tree.get_root_id();
|
||||
let top_level_ids = tree.get_instance(root_id).unwrap().get_children_ids();
|
||||
rbx_xml::to_writer(&mut file, &tree, top_level_ids, xml_encode_config())?;
|
||||
},
|
||||
OutputKind::Rbxm => {
|
||||
let root_id = tree.get_root_id();
|
||||
rbx_binary::encode(&tree, &[root_id], &mut file)?;
|
||||
},
|
||||
OutputKind::Rbxl => {
|
||||
@@ -123,7 +128,6 @@ pub fn build(options: &BuildOptions) -> Result<(), BuildError> {
|
||||
log::warn!("Using the XML place format (rbxlx) is recommended instead.");
|
||||
log::warn!("For more info, see https://github.com/LPGhatguy/rojo/issues/180");
|
||||
|
||||
let root_id = tree.get_root_id();
|
||||
let top_level_ids = tree.get_instance(root_id).unwrap().get_children_ids();
|
||||
rbx_binary::encode(&tree, top_level_ids, &mut file)?;
|
||||
},
|
||||
@@ -131,5 +135,7 @@ pub fn build(options: &BuildOptions) -> Result<(), BuildError> {
|
||||
|
||||
file.flush()?;
|
||||
|
||||
log::trace!("Done!");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user