mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-25 07:06:12 +00:00
Implement build command, shuffle around some internals to make it easier
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
#[macro_use] extern crate clap;
|
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
env,
|
env,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use clap::clap_app;
|
||||||
|
|
||||||
use librojo::commands;
|
use librojo::commands;
|
||||||
|
|
||||||
fn make_path_absolute(value: &Path) -> PathBuf {
|
fn make_path_absolute(value: &Path) -> PathBuf {
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
use std::{
|
use std::{
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
|
fs::File,
|
||||||
|
process,
|
||||||
|
};
|
||||||
|
|
||||||
|
use rbxmx;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
rbx_session::construct_oneoff_tree,
|
||||||
|
project::Project,
|
||||||
|
imfs::Imfs,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -9,5 +19,27 @@ pub struct BuildOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(options: &BuildOptions) {
|
pub fn build(options: &BuildOptions) {
|
||||||
println!("build {:#?}", options);
|
info!("Looking for project at {}", options.fuzzy_project_path.display());
|
||||||
|
|
||||||
|
let project = match Project::load_fuzzy(&options.fuzzy_project_path) {
|
||||||
|
Ok(project) => project,
|
||||||
|
Err(error) => {
|
||||||
|
error!("{}", error);
|
||||||
|
process::exit(1);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
info!("Found project at {}", project.file_location.display());
|
||||||
|
info!("Using project {:#?}", project);
|
||||||
|
|
||||||
|
let imfs = Imfs::new(&project)
|
||||||
|
.expect("Could not create in-memory filesystem");
|
||||||
|
|
||||||
|
let tree = construct_oneoff_tree(&project, &imfs);
|
||||||
|
let root_id = tree.get_root_id();
|
||||||
|
|
||||||
|
let mut file = File::create(&options.output_file)
|
||||||
|
.expect("Could not open output file for write");
|
||||||
|
|
||||||
|
rbxmx::encode(&tree, &[root_id], &mut file);
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,23 @@ use std::{
|
|||||||
io,
|
io,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::project::{Project, ProjectNode};
|
||||||
|
|
||||||
|
fn add_sync_points(imfs: &mut Imfs, project_node: &ProjectNode) -> io::Result<()> {
|
||||||
|
match project_node {
|
||||||
|
ProjectNode::Instance(node) => {
|
||||||
|
for child in node.children.values() {
|
||||||
|
add_sync_points(imfs, child)?;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
ProjectNode::SyncPoint(node) => {
|
||||||
|
imfs.add_root(&node.path)?;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// The in-memory filesystem keeps a mirror of all files being watcher by Rojo
|
/// The in-memory filesystem keeps a mirror of all files being watcher by Rojo
|
||||||
/// in order to deduplicate file changes in the case of bidirectional syncing
|
/// in order to deduplicate file changes in the case of bidirectional syncing
|
||||||
/// from Roblox Studio.
|
/// from Roblox Studio.
|
||||||
@@ -15,7 +32,15 @@ pub struct Imfs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Imfs {
|
impl Imfs {
|
||||||
pub fn new() -> Imfs {
|
pub fn new(project: &Project) -> io::Result<Imfs> {
|
||||||
|
let mut imfs = Imfs::empty();
|
||||||
|
|
||||||
|
add_sync_points(&mut imfs, &project.tree)?;
|
||||||
|
|
||||||
|
Ok(imfs)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn empty() -> Imfs {
|
||||||
Imfs {
|
Imfs {
|
||||||
items: HashMap::new(),
|
items: HashMap::new(),
|
||||||
roots: HashSet::new(),
|
roots: HashSet::new(),
|
||||||
|
|||||||
@@ -157,6 +157,10 @@ impl RbxSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn construct_oneoff_tree(project: &Project, imfs: &Imfs) -> RbxTree {
|
||||||
|
construct_initial_tree(project, imfs).0
|
||||||
|
}
|
||||||
|
|
||||||
struct ConstructContext<'a> {
|
struct ConstructContext<'a> {
|
||||||
tree: RbxTree,
|
tree: RbxTree,
|
||||||
imfs: &'a Imfs,
|
imfs: &'a Imfs,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use std::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
message_queue::MessageQueue,
|
message_queue::MessageQueue,
|
||||||
project::{Project, ProjectNode},
|
project::Project,
|
||||||
imfs::Imfs,
|
imfs::Imfs,
|
||||||
session_id::SessionId,
|
session_id::SessionId,
|
||||||
rbx_session::RbxSession,
|
rbx_session::RbxSession,
|
||||||
@@ -20,29 +20,9 @@ pub struct Session {
|
|||||||
fs_watcher: FsWatcher,
|
fs_watcher: FsWatcher,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_sync_points(imfs: &mut Imfs, project_node: &ProjectNode) -> io::Result<()> {
|
|
||||||
match project_node {
|
|
||||||
ProjectNode::Instance(node) => {
|
|
||||||
for child in node.children.values() {
|
|
||||||
add_sync_points(imfs, child)?;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
ProjectNode::SyncPoint(node) => {
|
|
||||||
imfs.add_root(&node.path)?;
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Session {
|
impl Session {
|
||||||
pub fn new(project: Project) -> io::Result<Session> {
|
pub fn new(project: Project) -> io::Result<Session> {
|
||||||
let mut imfs = Imfs::new();
|
let imfs = Arc::new(Mutex::new(Imfs::new(&project)?));
|
||||||
|
|
||||||
add_sync_points(&mut imfs, &project.tree)
|
|
||||||
.expect("Could not add sync points when starting new Rojo session");
|
|
||||||
|
|
||||||
let imfs = Arc::new(Mutex::new(imfs));
|
|
||||||
let project = Arc::new(project);
|
let project = Arc::new(project);
|
||||||
let message_queue = Arc::new(MessageQueue::new());
|
let message_queue = Arc::new(MessageQueue::new());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user