Skip to content

Commit 39af95a

Browse files
committed
♻️ - decouple functions from progress bar
1 parent 3500459 commit 39af95a

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

src/build.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
pub mod build_types;
22
pub mod clean;
33
pub mod compile;
4-
pub mod dependency_cycle;
54
pub mod deps;
65
pub mod logs;
76
pub mod namespaces;
@@ -130,7 +129,7 @@ pub fn build(filter: &Option<regex::Regex>, path: &str, no_timing: bool) -> Resu
130129
);
131130

132131
let timing_ast = Instant::now();
133-
let result_asts = parse::generate_asts(&rescript_version, &mut build_state, &pb);
132+
let result_asts = parse::generate_asts(&rescript_version, &mut build_state, || pb.inc(1));
134133
let timing_ast_elapsed = timing_ast.elapsed();
135134

136135
match result_asts {
@@ -173,8 +172,22 @@ pub fn build(filter: &Option<regex::Regex>, path: &str, no_timing: bool) -> Resu
173172
);
174173

175174
let start_compiling = Instant::now();
176-
let (compile_errors, compile_warnings, num_compiled_modules) =
177-
compile::compile(&mut build_state, &deleted_module_names, &rescript_version);
175+
let pb = ProgressBar::new(build_state.modules.len().try_into().unwrap());
176+
pb.set_style(
177+
ProgressStyle::with_template(&format!(
178+
"{} {} Compiling... {{spinner}} {{pos}}/{{len}} {{msg}}",
179+
style("[6/7]").bold().dim(),
180+
SWORDS
181+
))
182+
.unwrap(),
183+
);
184+
let (compile_errors, compile_warnings, num_compiled_modules) = compile::compile(
185+
&mut build_state,
186+
&deleted_module_names,
187+
&rescript_version,
188+
|| pb.inc(1),
189+
|size| pb.set_length(size),
190+
);
178191
let compile_duration = start_compiling.elapsed();
179192

180193
logs::finalize(&build_state.project_root, &build_state.packages);

src/build/compile.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
mod dependency_cycle;
2+
13
use super::build_types::*;
2-
use super::dependency_cycle;
34
use super::logs;
45
use super::packages;
56
use crate::bsconfig;
67
use crate::helpers;
7-
use crate::helpers::emojis::*;
88
use ahash::AHashSet;
99
use console::style;
10-
use indicatif::{ProgressBar, ProgressStyle};
1110
use log::debug;
1211
use log::{info, log_enabled, Level::Info};
1312
use rayon::prelude::*;
@@ -18,6 +17,8 @@ pub fn compile(
1817
mut build_state: &mut BuildState,
1918
deleted_module_names: &AHashSet<String>,
2019
rescript_version: &str,
20+
inc: impl Fn() -> () + std::marker::Sync,
21+
set_length: impl Fn(u64) -> (),
2122
) -> (String, String, usize) {
2223
let mut compiled_modules = AHashSet::<String>::new();
2324

@@ -82,16 +83,8 @@ pub fn compile(
8283
}
8384
}
8485

85-
let pb = ProgressBar::new(compile_universe.len().try_into().unwrap());
86-
pb.set_style(
87-
ProgressStyle::with_template(&format!(
88-
"{} {} Compiling... {{spinner}} {{pos}}/{{len}} {{msg}}",
89-
style("[6/7]").bold().dim(),
90-
SWORDS
91-
))
92-
.unwrap(),
93-
);
9486
let compile_universe_count = compile_universe.len();
87+
set_length(compile_universe_count as u64);
9588

9689
// start off with all modules that have no deps in this compile universe
9790
let mut in_progress_modules = compile_universe
@@ -237,7 +230,7 @@ pub fn compile(
237230
}
238231
.map(|res| {
239232
if !(log_enabled!(Info)) {
240-
pb.inc(1);
233+
inc();
241234
}
242235
res
243236
})

src/build/dependency_cycle.rs renamed to src/build/compile/dependency_cycle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::build_types::*;
1+
use super::super::build_types::*;
22
use crate::helpers;
33
use ahash::AHashSet;
44

src/build/parse.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use super::packages;
55
use crate::bsconfig;
66
use crate::bsconfig::OneOrMore;
77
use crate::helpers;
8-
use indicatif::ProgressBar;
98
use log::debug;
109
use rayon::prelude::*;
1110
use std::path::{Path, PathBuf};
@@ -14,7 +13,7 @@ use std::process::Command;
1413
pub fn generate_asts(
1514
version: &str,
1615
build_state: &mut BuildState,
17-
pb: &ProgressBar,
16+
inc: impl Fn() -> () + std::marker::Sync,
1817
) -> Result<String, String> {
1918
let mut has_failure = false;
2019
let mut stderr = "".to_string();
@@ -69,7 +68,7 @@ pub fn generate_asts(
6968
|| source_file.interface.as_ref().map(|i| i.dirty).unwrap_or(false)
7069
{
7170
// dbg!("Compiling", source_file.implementation.path.to_owned());
72-
pb.inc(1);
71+
inc();
7372
let ast_result = generate_ast(
7473
package.to_owned(),
7574
root_package.to_owned(),

0 commit comments

Comments
 (0)