diff --git a/Cargo.lock b/Cargo.lock index 44d04f3c..99024612 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,12 +24,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "anes" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" - [[package]] name = "anstream" version = "0.6.13" @@ -90,17 +84,6 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.2.0" @@ -132,18 +115,6 @@ dependencies = [ "constant_time_eq", ] -[[package]] -name = "bumpalo" -version = "3.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" - -[[package]] -name = "cast" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" - [[package]] name = "cc" version = "1.0.92" @@ -162,45 +133,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" -[[package]] -name = "ciborium" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" -dependencies = [ - "ciborium-io", - "ciborium-ll", - "serde", -] - -[[package]] -name = "ciborium-io" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" - -[[package]] -name = "ciborium-ll" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" -dependencies = [ - "ciborium-io", - "half", -] - -[[package]] -name = "clap" -version = "3.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" -dependencies = [ - "bitflags 1.3.2", - "clap_lex 0.2.4", - "indexmap", - "textwrap", -] - [[package]] name = "clap" version = "4.5.4" @@ -217,7 +149,7 @@ version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e099138e1807662ff75e2cebe4ae2287add879245574489f9b1588eb5e5564ed" dependencies = [ - "clap 4.5.4", + "clap", "log", ] @@ -229,7 +161,7 @@ checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" dependencies = [ "anstream", "anstyle", - "clap_lex 0.7.0", + "clap_lex", "strsim", ] @@ -245,15 +177,6 @@ dependencies = [ "syn", ] -[[package]] -name = "clap_lex" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", -] - [[package]] name = "clap_lex" version = "0.7.0" @@ -300,42 +223,6 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" -[[package]] -name = "criterion" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7c76e09c1aae2bc52b3d2f29e13c6572553b30c4aa1b8a49fd70de6412654cb" -dependencies = [ - "anes", - "atty", - "cast", - "ciborium", - "clap 3.2.25", - "criterion-plot", - "itertools", - "lazy_static", - "num-traits", - "oorandom", - "plotters", - "rayon", - "regex", - "serde", - "serde_derive", - "serde_json", - "tinytemplate", - "walkdir", -] - -[[package]] -name = "criterion-plot" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" -dependencies = [ - "cast", - "itertools", -] - [[package]] name = "crossbeam-channel" version = "0.5.12" @@ -370,12 +257,6 @@ version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - [[package]] name = "ctrlc" version = "3.4.4" @@ -538,37 +419,12 @@ dependencies = [ "wasi", ] -[[package]] -name = "half" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" -dependencies = [ - "cfg-if", - "crunchy", -] - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "heck" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.3.9" @@ -581,16 +437,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" -[[package]] -name = "indexmap" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown", -] - [[package]] name = "indicatif" version = "0.17.8" @@ -639,35 +485,17 @@ version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" dependencies = [ - "hermit-abi 0.3.9", + "hermit-abi", "libc", "windows-sys 0.52.0", ] -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" -[[package]] -name = "js-sys" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" -dependencies = [ - "wasm-bindgen", -] - [[package]] name = "kqueue" version = "1.0.8" @@ -774,15 +602,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "num-traits" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" -dependencies = [ - "autocfg", -] - [[package]] name = "number_prefix" version = "0.4.0" @@ -795,18 +614,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "oorandom" -version = "11.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" - -[[package]] -name = "os_str_bytes" -version = "6.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -819,34 +626,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "plotters" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2c224ba00d7cadd4d5c660deaf2098e5e80e07846537c51f9cfa4be50c1fd45" -dependencies = [ - "num-traits", - "plotters-backend", - "plotters-svg", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "plotters-backend" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e76628b4d3a7581389a35d5b6e2139607ad7c75b17aed325f210aa91f4a9609" - -[[package]] -name = "plotters-svg" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38f6d39893cca0701371e3c27294f09797214b86f1fb951b89ade8ec04e2abab" -dependencies = [ - "plotters-backend", -] - [[package]] name = "portable-atomic" version = "1.6.0" @@ -935,11 +714,10 @@ version = "1.0.9" dependencies = [ "ahash", "blake3", - "clap 4.5.4", + "clap", "clap-verbosity-flag", "console", "convert_case", - "criterion", "ctrlc", "env_logger", "futures", @@ -1052,22 +830,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "textwrap" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" - -[[package]] -name = "tinytemplate" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" -dependencies = [ - "serde", - "serde_json", -] - [[package]] name = "unicode-ident" version = "1.0.12" @@ -1114,70 +876,6 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "wasm-bindgen" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" - -[[package]] -name = "web-sys" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 6639e559..5195fecd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,10 +29,3 @@ clap-verbosity-flag = "2.2.2" [profile.release] codegen-units = 1 lto = true - -[dev-dependencies] -criterion = "0.4" - -[[bench]] -name = "base_bench" -harness = false diff --git a/benches/base_bench.rs b/benches/base_bench.rs deleted file mode 100644 index 8b781a03..00000000 --- a/benches/base_bench.rs +++ /dev/null @@ -1,54 +0,0 @@ -use criterion::{criterion_group, criterion_main, Criterion}; -use rewatch::build; -use rewatch::build::clean; -use rewatch::build::packages; -use rewatch::helpers; - -use std::fs::File; -use std::io::prelude::*; - -fn criterion_benchmark(c: &mut Criterion) { - c.bench_function("build-package-tree", |b| { - // Folder for the testrepo - let folder = "walnut_monorepo"; - let project_root = helpers::get_abs_path(folder); - - b.iter(|| { - packages::make(&None, &project_root, &None); - }) - }); - - c.bench_function("clean-build-change-build", |b| { - // Folder for the testrepo - let folder = "testrepo"; - let filename = "testrepo/packages/dep02/src/Dep02.res"; - // Clean the build - clean::clean(folder); - // Read the file we'll be mutating - let mut file = File::options() - .read(true) - .write(true) - .append(true) - .open(filename) - .unwrap(); - let mut contents = String::new(); - file.read_to_string(&mut contents).unwrap(); - - b.iter(|| { - // Create initial build - let _ = build::build(&None, folder, false); - // Update the file - let _ = writeln!(file, r#"let log2 = () => ["a", "b"]->forEach(Js.log);log2()"#); - // Create another build - let _ = build::build(&None, folder, false); - - // Reset state - File::create(filename).unwrap(); - file.write_all(contents.as_bytes()).unwrap(); - let _ = build::build(&None, folder, false); - }) - }); -} - -criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); diff --git a/src/build/clean.rs b/src/build/clean.rs index 91c90fe9..de02747c 100644 --- a/src/build/clean.rs +++ b/src/build/clean.rs @@ -125,7 +125,7 @@ pub fn cleanup_previous_build( .get(package_name) .expect("Could not find package"); remove_compile_assets(package, res_file_location); - remove_mjs_file(res_file_location, &suffix); + remove_mjs_file(res_file_location, suffix); remove_iast(package, res_file_location); remove_ast(package, res_file_location); match helpers::get_extension(ast_file_path).as_str() { @@ -234,14 +234,13 @@ pub fn cleanup_previous_build( let deleted_module_names = ast_module_names .difference(&all_module_names) - .map(|module_name| { + .flat_map(|module_name| { // if the module is a namespace, we need to mark the whole namespace as dirty when a module has been deleted if let Some(namespace) = helpers::get_namespace_from_module_name(module_name) { return vec![namespace, module_name.to_string()]; } vec![module_name.to_string()] }) - .flatten() .collect::>(); build_state.deleted_modules = deleted_module_names; diff --git a/src/build/compile.rs b/src/build/compile.rs index 863a47c8..d185f059 100644 --- a/src/build/compile.rs +++ b/src/build/compile.rs @@ -219,11 +219,10 @@ pub fn compile( } else { None } - .map(|res| { + .inspect(|_res| { if !(log_enabled!(Info)) { inc(); } - res }) }) .collect::, >>() .iter() - .for_each(|result| match result { - Some((module_name, result, interface_result, is_clean, is_compiled)) => { - in_progress_modules.remove(module_name); + .for_each(|result| if let Some((module_name, result, interface_result, is_clean, is_compiled)) = result { + in_progress_modules.remove(module_name); - if *is_compiled { - num_compiled_modules += 1; - } + if *is_compiled { + num_compiled_modules += 1; + } - files_current_loop_count += 1; - compiled_modules.insert(module_name.to_string()); + files_current_loop_count += 1; + compiled_modules.insert(module_name.to_string()); - if *is_clean { - // actually add it to a list of clean modules - clean_modules.insert(module_name.to_string()); - } + if *is_clean { + // actually add it to a list of clean modules + clean_modules.insert(module_name.to_string()); + } - let module_dependents = build_state.get_module(module_name).unwrap().dependents.clone(); + let module_dependents = build_state.get_module(module_name).unwrap().dependents.clone(); - // if not clean -- compile modules that depend on this module - for dep in module_dependents.iter() { + // if not clean -- compile modules that depend on this module + for dep in module_dependents.iter() { + // mark the reverse dep as dirty when the source is not clean + if !*is_clean { + let dep_module = build_state.modules.get_mut(dep).unwrap(); // mark the reverse dep as dirty when the source is not clean - if !*is_clean { - let dep_module = build_state.modules.get_mut(dep).unwrap(); - // mark the reverse dep as dirty when the source is not clean - dep_module.compile_dirty = true; - } - if !compiled_modules.contains(dep) { - in_progress_modules.insert(dep.to_string()); - } + dep_module.compile_dirty = true; } + if !compiled_modules.contains(dep) { + in_progress_modules.insert(dep.to_string()); + } + } - let module = build_state.modules.get_mut(module_name).unwrap(); - let package = build_state - .packages - .get(&module.package_name) - .expect("Package not found"); - match module.source_type { - SourceType::MlMap(ref mut mlmap) => { - module.compile_dirty = false; - mlmap.parse_dirty = false; - } - SourceType::SourceFile(ref mut source_file) => { - match result { - Ok(Some(err)) => { - source_file.implementation.compile_state = CompileState::Warning; - logs::append(package, err); - compile_warnings.push_str(err); - } - Ok(None) => { - source_file.implementation.compile_state = CompileState::Success; - } - Err(err) => { - source_file.implementation.compile_state = CompileState::Error; - logs::append(package, err); - compile_errors.push_str(err); - } - }; - match interface_result { - Some(Ok(Some(err))) => { - source_file.interface.as_mut().unwrap().compile_state = - CompileState::Warning; - logs::append(package, err); - compile_warnings.push_str(err); - } - Some(Ok(None)) => { - if let Some(interface) = source_file.interface.as_mut() { - interface.compile_state = CompileState::Success; - } + let module = build_state.modules.get_mut(module_name).unwrap(); + let package = build_state + .packages + .get(&module.package_name) + .expect("Package not found"); + match module.source_type { + SourceType::MlMap(ref mut mlmap) => { + module.compile_dirty = false; + mlmap.parse_dirty = false; + } + SourceType::SourceFile(ref mut source_file) => { + match result { + Ok(Some(err)) => { + source_file.implementation.compile_state = CompileState::Warning; + logs::append(package, err); + compile_warnings.push_str(err); + } + Ok(None) => { + source_file.implementation.compile_state = CompileState::Success; + } + Err(err) => { + source_file.implementation.compile_state = CompileState::Error; + logs::append(package, err); + compile_errors.push_str(err); + } + }; + match interface_result { + Some(Ok(Some(err))) => { + source_file.interface.as_mut().unwrap().compile_state = + CompileState::Warning; + logs::append(package, err); + compile_warnings.push_str(err); + } + Some(Ok(None)) => { + if let Some(interface) = source_file.interface.as_mut() { + interface.compile_state = CompileState::Success; } + } - Some(Err(err)) => { - source_file.interface.as_mut().unwrap().compile_state = - CompileState::Error; - logs::append(package, err); - compile_errors.push_str(err); - } - _ => (), - }; - match (result, interface_result) { - // successfull compilation - (Ok(None), Some(Ok(None))) | (Ok(None), None) => { - module.compile_dirty = false; - module.last_compiled_cmi = Some(SystemTime::now()); - module.last_compiled_cmt = Some(SystemTime::now()); - } - // some error or warning - (Err(_), _) - | (_, Some(Err(_))) - | (Ok(Some(_)), _) - | (_, Some(Ok(Some(_)))) => { - module.compile_dirty = true; - } + Some(Err(err)) => { + source_file.interface.as_mut().unwrap().compile_state = + CompileState::Error; + logs::append(package, err); + compile_errors.push_str(err); + } + _ => (), + }; + match (result, interface_result) { + // successfull compilation + (Ok(None), Some(Ok(None))) | (Ok(None), None) => { + module.compile_dirty = false; + module.last_compiled_cmi = Some(SystemTime::now()); + module.last_compiled_cmt = Some(SystemTime::now()); + } + // some error or warning + (Err(_), _) + | (_, Some(Err(_))) + | (Ok(Some(_)), _) + | (_, Some(Ok(Some(_)))) => { + module.compile_dirty = true; } } } } - None => (), }); files_total_count += files_current_loop_count; @@ -388,7 +384,7 @@ pub fn compiler_args( // .unwrap_or(&vec![]) // .to_owned(); - let deps = vec![normal_deps] + let deps = [normal_deps] .concat() .par_iter() .map(|package_name| { @@ -455,7 +451,7 @@ pub fn compiler_args( _ => vec![], }; - vec![warn_number, warn_error].concat() + [warn_number, warn_error].concat() } }; diff --git a/src/build/deps.rs b/src/build/deps.rs index 5bd19395..2ce82b39 100644 --- a/src/build/deps.rs +++ b/src/build/deps.rs @@ -84,18 +84,15 @@ pub fn get_deps(build_state: &mut BuildState, deleted_modules: &AHashSet all_mod, ); - match &source_file.interface { - Some(interface) => { - let iast_path = package.get_iast_path(&interface.path); + if let Some(interface) = &source_file.interface { + let iast_path = package.get_iast_path(&interface.path); - deps.extend(get_dep_modules( - &iast_path, - package.namespace.to_suffix(), - package.modules.as_ref().unwrap(), - all_mod, - )) - } - None => (), + deps.extend(get_dep_modules( + &iast_path, + package.namespace.to_suffix(), + package.modules.as_ref().unwrap(), + all_mod, + )) } match &package.namespace { packages::Namespace::NamespaceWithEntry { namespace: _, entry } diff --git a/src/build/packages.rs b/src/build/packages.rs index b50c0c6d..631f0b39 100644 --- a/src/build/packages.rs +++ b/src/build/packages.rs @@ -278,10 +278,10 @@ pub fn read_dependency( /// Given a bsconfig, recursively finds all dependencies. /// 1. It starts with registering dependencies and -/// prevents the operation for the ones which are already -/// registerd for the parent packages. Especially relevant for peerDependencies. +/// prevents the operation for the ones which are already +/// registerd for the parent packages. Especially relevant for peerDependencies. /// 2. In parallel performs IO to read the dependencies bsconfig and -/// recursively continues operation for their dependencies as well. +/// recursively continues operation for their dependencies as well. fn read_dependencies( registered_dependencies_set: &mut AHashSet, parent_bsconfig: &bsconfig::Config, @@ -292,7 +292,7 @@ fn read_dependencies( return parent_bsconfig .bs_dependencies .to_owned() - .unwrap_or(vec![]) + .unwrap_or_default() .iter() .filter_map(|package_name| { if registered_dependencies_set.contains(package_name) { @@ -517,6 +517,7 @@ fn extend_with_children( /// 1. Get all the packages parsed, and take all the source folders from the bsconfig /// 2. Take the (by then deduplicated) packages, and find all the '.re', '.res', '.ml' and /// interface files. +/// /// The two step process is there to reduce IO overhead pub fn make( filter: &Option, @@ -528,12 +529,9 @@ pub fn make( /* Once we have the deduplicated packages, we can add the source files for each - to minimize * the IO */ let result = extend_with_children(filter, map); - result.values().for_each(|package| match &package.dirs { - Some(dirs) => dirs.iter().for_each(|dir| { - let _ = std::fs::create_dir_all(std::path::Path::new(&package.get_bs_build_path()).join(dir)); - }), - None => (), - }); + result.values().for_each(|package| if let Some(dirs) = &package.dirs { dirs.iter().for_each(|dir| { + let _ = std::fs::create_dir_all(std::path::Path::new(&package.get_bs_build_path()).join(dir)); + }) }); result } @@ -778,11 +776,9 @@ pub fn validate_packages_dependencies(packages: &AHashMap) -> b let pinned_dependencies = &package.bsconfig.pinned_dependencies.to_owned().unwrap_or(vec![]); let dev_dependencies = &package.bsconfig.bs_dev_dependencies.to_owned().unwrap_or(vec![]); - vec![ - ("bs-dependencies", bs_dependencies), + [("bs-dependencies", bs_dependencies), ("pinned-dependencies", pinned_dependencies), - ("bs-dev-dependencies", dev_dependencies), - ] + ("bs-dev-dependencies", dev_dependencies)] .iter() .for_each(|(dependency_type, dependencies)| { if let Some(unallowed_dependency_name) = @@ -812,11 +808,9 @@ pub fn validate_packages_dependencies(packages: &AHashMap) -> b console::style(package_name).bold() ); - vec![ - ("bs-dependencies", unallowed_deps.bs_deps.to_owned()), + [("bs-dependencies", unallowed_deps.bs_deps.to_owned()), ("pinned-dependencies", unallowed_deps.pinned_deps.to_owned()), - ("bs-dev-dependencies", unallowed_deps.bs_dev_deps.to_owned()), - ] + ("bs-dev-dependencies", unallowed_deps.bs_dev_deps.to_owned())] .iter() .for_each(|(deps_type, map)| { if !map.is_empty() { @@ -854,7 +848,7 @@ mod test { dev_deps: Vec, allowed_dependents: Option>, ) -> Package { - return Package { + Package { name: name.clone(), bsconfig: crate::bsconfig::Config { name: name.clone(), @@ -883,7 +877,7 @@ mod test { dirs: None, is_pinned_dep: false, is_root: false, - }; + } } #[test] fn should_return_false_with_invalid_parents_as_bs_dependencies() { @@ -910,7 +904,7 @@ mod test { ); let is_valid = super::validate_packages_dependencies(&packages); - assert_eq!(is_valid, false) + assert!(!is_valid) } #[test] @@ -938,7 +932,7 @@ mod test { ); let is_valid = super::validate_packages_dependencies(&packages); - assert_eq!(is_valid, false) + assert!(!is_valid) } #[test] @@ -966,7 +960,7 @@ mod test { ); let is_valid = super::validate_packages_dependencies(&packages); - assert_eq!(is_valid, false) + assert!(!is_valid) } #[test] @@ -994,6 +988,6 @@ mod test { ); let is_valid = super::validate_packages_dependencies(&packages); - assert_eq!(is_valid, true) + assert!(is_valid) } } diff --git a/src/build/parse.rs b/src/build/parse.rs index 4ca3c183..2452fa6f 100644 --- a/src/build/parse.rs +++ b/src/build/parse.rs @@ -172,7 +172,6 @@ pub fn generate_asts( } Ok(None) => { // The file had no interface file associated - () } } }; @@ -279,7 +278,7 @@ pub fn parser_args( let file = "../../".to_string() + file; ( ast_path.to_string(), - vec![ + [ vec!["-bs-v".to_string(), format!("{}", version)], ppx_flags, jsx_args, @@ -347,17 +346,14 @@ fn generate_ast( filename, package.name )) }; - match &result { - Ok((ast_path, _)) => { - let dir = std::path::Path::new(filename).parent().unwrap(); - let _ = std::fs::copy( - build_path_abs.to_string() + "/" + ast_path, - std::path::Path::new(&package.get_bs_build_path()) - .join(dir) - .join(ast_path), - ); - } - Err(_) => (), + if let Ok((ast_path, _)) = &result { + let dir = std::path::Path::new(filename).parent().unwrap(); + let _ = std::fs::copy( + build_path_abs.to_string() + "/" + ast_path, + std::path::Path::new(&package.get_bs_build_path()) + .join(dir) + .join(ast_path), + ); } result } @@ -374,17 +370,17 @@ fn path_to_ast_extension(path: &Path) -> &str { fn include_ppx(flag: &str, contents: &str) -> bool { if flag.contains("bisect") { return std::env::var("BISECT_ENABLE").is_ok(); - } else if (flag.contains("graphql-ppx") || flag.contains("graphql_ppx")) && !contents.contains("%graphql") + } + + if ((flag.contains("graphql-ppx") || flag.contains("graphql_ppx")) && !contents.contains("%graphql")) + || (flag.contains("spice") && !contents.contains("@spice")) + || (flag.contains("rescript-relay") && !contents.contains("%relay")) + || (flag.contains("re-formality") && !contents.contains("%form")) { return false; - } else if flag.contains("spice") && !contents.contains("@spice") { - return false; - } else if flag.contains("rescript-relay") && !contents.contains("%relay") { - return false; - } else if flag.contains("re-formality") && !contents.contains("%form") { - return false; - } - return true; + }; + + true } fn filter_ppx_flags( diff --git a/src/sourcedirs.rs b/src/sourcedirs.rs index d50f5636..41eafb50 100644 --- a/src/sourcedirs.rs +++ b/src/sourcedirs.rs @@ -20,7 +20,7 @@ pub struct SourceDirs<'a> { pub generated: &'a Vec, } -fn package_to_dirs<'a>(package: &'a Package, root_package_path: &String) -> AHashSet { +fn package_to_dirs(package: &Package, root_package_path: &String) -> AHashSet { let relative_path = PathBuf::from(&package.path) .strip_prefix(PathBuf::from(&root_package_path)) .unwrap() @@ -72,7 +72,7 @@ pub fn print(buildstate: &BuildState) { .filter(|(_name, package)| !package.is_root) .map(|(_name, package)| { // Extract Directories - let dirs = package_to_dirs(&package, &root_package.path); + let dirs = package_to_dirs(package, &root_package.path); // Extract Pkgs let pkgs = [ diff --git a/src/structure_hashmap.rs b/src/structure_hashmap.rs deleted file mode 100644 index 1e3abf40..00000000 --- a/src/structure_hashmap.rs +++ /dev/null @@ -1,54 +0,0 @@ -use crate::helpers::{is_source_file, LexicalAbsolute}; -use ahash::AHashMap; -use std::path::PathBuf; -use std::{error, fs}; - -pub fn read_folders( - filter: &Option, - path: &str, - recurse: bool, -) -> Result, Box> { - let mut map: AHashMap = AHashMap::new(); - - let path_buf = PathBuf::from(path); - let abs_path = path_buf - .to_lexical_absolute() - .map(|x| x.to_str().map(|y| y.to_string()).unwrap_or("".to_string())) - .and_then(|x| fs::metadata(x.to_owned()).map(|m| (x.to_owned(), m))); - - for entry in fs::read_dir(path.replace("//", "/"))? { - let path_buf = entry.map(|entry| entry.path())?; - let metadata = fs::metadata(&path_buf)?; - let name = path_buf - .file_name() - .and_then(|x| x.to_str()) - .unwrap_or("Unknown") - .to_string(); - - let path_ext = path_buf.extension().and_then(|x| x.to_str()); - - if metadata.file_type().is_dir() && recurse { - match read_folders(&filter, &(path.to_owned() + "/" + &name + "/"), recurse) { - Ok(s) => map.extend(s), - Err(e) => println!("Error reading directory: {}", e), - } - } - match path_ext { - Some(extension) if is_source_file(extension) => match abs_path { - Ok((ref path, _)) - if filter - .as_ref() - .map(|re| !re.is_match(&name)) - .unwrap_or(true) => - { - map.insert(path.to_owned() + "/" + &name, metadata); - } - Ok(_) => println!("Filtered: {:?}", name), - Err(ref e) => println!("Error reading directory: {}", e), - }, - _ => (), - } - } - - Ok(map) -}