Working module reading
This commit is contained in:
@@ -3,6 +3,7 @@ use <std::path::PathBuf>;
|
||||
use <std::fs>;
|
||||
use <std::process>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub class Module {
|
||||
pub String name;
|
||||
pub PathBuf path;
|
||||
@@ -14,15 +15,23 @@ pub class Module {
|
||||
self.path = mist_path;
|
||||
|
||||
if (self.path.is_dir()) {
|
||||
var entries = match (fs::read_dir(&self.path)) {
|
||||
PathBuf dir = self.path.clone();
|
||||
|
||||
// Behavior 2: It's a directory node. Check for gateway package.mist first.
|
||||
PathBuf pkg_gate = self.path.join("package.mist");
|
||||
if (pkg_gate.exists()) {
|
||||
self.path = pkg_gate;
|
||||
}
|
||||
|
||||
self.scan_directory(&dir, &rust_path);
|
||||
}
|
||||
}
|
||||
|
||||
void scan_directory(self mut*, Path* search_dir, Path* rust_path) {
|
||||
var entries = match (fs::read_dir(search_dir)) {
|
||||
Ok[entries] => entries;
|
||||
Err[e] => {
|
||||
eprintln!(
|
||||
"error: failed to read directory {}\n {}",
|
||||
self.path.display(),
|
||||
e
|
||||
);
|
||||
|
||||
eprintln!("error: failed to read directory {}\n {}", search_dir.display(), e);
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
@@ -32,13 +41,16 @@ pub class Module {
|
||||
Ok[entry] => entry;
|
||||
Err[e] => {
|
||||
eprintln!("error: failed to read directory entry\n {}", e);
|
||||
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
PathBuf child_path = entry.path();
|
||||
|
||||
if (child_path == self.path) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String child_name = child_path.file_stem()
|
||||
.and_then(|var s| s.to_str())
|
||||
.expect("Failed to get module name")
|
||||
@@ -46,23 +58,32 @@ pub class Module {
|
||||
|
||||
PathBuf child_output = rust_path.join(&child_name).with_extension("rs");
|
||||
|
||||
if (should_skip(&child_path, &child_output)) {
|
||||
if (!child_path.is_dir() && should_skip(&child_path, &child_output)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
self.children.push(new Module(child_name, child_path, child_output));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub Module new_package(PathBuf mist_path, PathBuf rust_path) {
|
||||
pub Module master_package(PathBuf mist_path, PathBuf rust_path) {
|
||||
String name = mist_path.file_stem()
|
||||
.and_then(|var s| s.to_str())
|
||||
.expect("Failed to get module name")
|
||||
.to_string();
|
||||
|
||||
new Module(name, mist_path, rust_path)
|
||||
var mut root_mod = new Module(name, mist_path.clone(), rust_path.clone());
|
||||
|
||||
if (!mist_path.is_dir()) {
|
||||
PathBuf parent_dir = mist_path.parent()
|
||||
.expect("Failed to get parent directory of root file")
|
||||
.to_path_buf();
|
||||
|
||||
root_mod.scan_directory(&parent_dir, &rust_path);
|
||||
}
|
||||
|
||||
root_mod
|
||||
}
|
||||
|
||||
bool should_skip(Path* source, Path* output) {
|
||||
|
||||
@@ -6,6 +6,7 @@ use <std::time>;
|
||||
use <std::env>;
|
||||
|
||||
use <mist_parser::error>;
|
||||
use <crate::modules>;
|
||||
|
||||
pub PathBuf build(bool force) {
|
||||
var start = time::Instant::now();
|
||||
@@ -15,8 +16,11 @@ pub PathBuf build(bool force) {
|
||||
PathBuf src = root.join("src");
|
||||
PathBuf out = root.join(".mist/src");
|
||||
|
||||
|
||||
build_dir(&root, &src, &src, &out, force);
|
||||
|
||||
var master = modules::master_package(src.join("main.mist"), out.join("main.rs"));
|
||||
|
||||
var elapsed = start.elapsed();
|
||||
|
||||
println!(
|
||||
|
||||
Reference in New Issue
Block a user