Skip to content

Commit

Permalink
feat: janus now supports dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmasoldi3r committed Dec 16, 2023
1 parent a9c20fe commit 968e96c
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 11 deletions.
38 changes: 38 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions janus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ indicatif = "0.17.3"
serde = { version = "1.0.163", features = ["derive"] }
toml = "0.8.3"
dialoguer = "0.11.0"
copy_dir = "0.1.3"

[dev-dependencies]
spectral = "0.6.0"
5 changes: 3 additions & 2 deletions janus/src/compilation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{
};

use console::style;
use copy_dir::copy_dir;

use crate::{
compilation::utils::{get_output_folder, get_source_folder},
Expand Down Expand Up @@ -255,8 +256,8 @@ impl CompilationHost {
// Those two steps cause exit if failed
create_dist_dirs(&info.output);
resolve_deps(&info, dependencies);
let paths = glob::glob("./**/*.saturn").unwrap();
let total = glob::glob("./**/*.saturn").unwrap().count();
let paths = glob::glob("./src/**/*.saturn").unwrap();
let total = glob::glob("./src/**/*.saturn").unwrap().count();
println!("Compiling sources...");
let pb = get_bar(total as u64);
let mut objects = Vec::<PathBuf>::new();
Expand Down
11 changes: 6 additions & 5 deletions janus/src/compilation/pipelines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl FilePipeline {
output: Option<PathBuf>,
exclude: &HashSet<PathBuf>,
) {
let pb = get_bar(objects.len() as u64);
let pb = get_bar(glob::glob("./dist/cache/objects/**/*.lua").unwrap().count() as u64);
let mut main: Option<PathBuf> = None;
let mut file_out = match info.target {
CompilationTarget::Lua => {
Expand All @@ -31,18 +31,19 @@ impl FilePipeline {
};
let mut main_path = objects_base_path.join(info.main.strip_prefix(&info.source).unwrap());
main_path.set_extension("lua");
for entry in objects.iter() {
if entry == &main_path {
for entry in glob::glob("./dist/cache/objects/**/*.lua").unwrap() {
let entry = entry.expect("Could not unwrap an entry path");
if &entry == &main_path {
main = Some(entry.clone());
continue;
}
if exclude.contains(entry) {
if exclude.contains(&entry) {
continue;
}
let base_target = entry.strip_prefix(&objects_base_path).unwrap();
let target = target_base_path.join(base_target);
pb.set_message(format!("Linking {:?}...", &target));
let src = fs::read_to_string(entry).unwrap();
let src = fs::read_to_string(&entry).unwrap();
let mut path_name = entry.clone();
path_name.set_extension("");
let mut path_name = path_name.strip_prefix(&objects_base_path).unwrap();
Expand Down
65 changes: 61 additions & 4 deletions janus/src/deps.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,71 @@
use std::time::Duration;
use std::{
path::Path,
process::{Command, Stdio},
time::Duration,
};

use crate::{compilation::CompilationInfo, display::get_bar, janusfile::DependencyList};
use copy_dir::copy_dir;
use indicatif::ProgressBar;

use crate::{
compilation::CompilationInfo,
display::get_bar,
janusfile::{DependencyList, DependencyObject},
};

fn resolve_dep_options(name: &String, options: &DependencyObject, bar: &ProgressBar) {
let old_msg = bar.message();
if !Path::new(&format!("dist/dependencies/{name}")).exists() {
if let Some(git) = options.git.clone() {
bar.set_message(format!("Cloning {git}..."));
let status = Command::new("git")
.arg("clone")
.arg(git)
.arg(name)
.current_dir("dist/dependencies")
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
.expect("Failed to resolve the dependency!");
if !status.success() {
panic!("Failed to resolve the dependency!");
}
}
}
bar.set_message(format!("Compiling {name}..."));
let status = Command::new("janus")
.arg("build")
.current_dir(format!("dist/dependencies/{name}"))
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
.expect("Failed to compile the dependency!");
if !status.success() {
panic!("Failed to compile the dependency!");
}
bar.set_message(format!("Copying {name} artifacts..."));
if !Path::new(&format!("dist/cache/objects/{name}")).exists() {
copy_dir(
format!("dist/dependencies/{name}/dist/cache/objects"),
format!("dist/cache/objects/{name}"),
)
.expect("Failed to copy dependency artifacts!");
}
bar.set_message(old_msg);
}

pub fn resolve_deps(info: &CompilationInfo, dependencies: DependencyList) {
let _ = info; // TODO!
let pb = get_bar(dependencies.len() as u64);
println!("Resolving dependencies...");
for (name, _dep) in dependencies.into_iter() {
for (name, dep) in dependencies.into_iter() {
pb.set_message(format!("Linking {}...", name));
std::thread::sleep(Duration::from_millis(20));
match dep {
crate::janusfile::DependencyDef::PlainVersion(_) => todo!(),
crate::janusfile::DependencyDef::Options(options) => {
resolve_dep_options(&name, &options, &pb)
}
}
pb.inc(1);
}
pb.finish_with_message("Done");
Expand Down

0 comments on commit 968e96c

Please sign in to comment.