From fe27f4ba1ad0fb355eca4aaccc14b7a1655f972c Mon Sep 17 00:00:00 2001 From: Jaap Frolich Date: Sat, 22 Jul 2023 23:18:38 +0200 Subject: [PATCH] :bug: - Fix clean --- src/build.rs | 15 +++++++-------- src/clean.rs | 44 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/build.rs b/src/build.rs index 22e598b..ab3b22c 100644 --- a/src/build.rs +++ b/src/build.rs @@ -1128,13 +1128,12 @@ pub fn clean(path: &str) { ); std::io::stdout().flush().unwrap(); - let path = std::path::Path::new(&package.package_dir) - .join("lib") - .join("ocaml"); + let path_str = helpers::get_build_path(&project_root, &package.name, package.is_root); + let path = std::path::Path::new(&path_str); let _ = std::fs::remove_dir_all(path); - let path = std::path::Path::new(&package.package_dir) - .join("lib") - .join("bs"); + + let path_str = helpers::get_bs_build_path(&project_root, &package.name, package.is_root); + let path = std::path::Path::new(&path_str); let _ = std::fs::remove_dir_all(path); }); let timing_clean_compiler_assets_elapsed = timing_clean_compiler_assets.elapsed(); @@ -1155,9 +1154,9 @@ pub fn clean(path: &str) { SWEEP ); std::io::stdout().flush().unwrap(); - let mut build_state = BuildState::new(project_root, root_config_name, packages); + let mut build_state = BuildState::new(project_root.to_owned(), root_config_name, packages); parse_packages(&mut build_state); - clean_mjs_files(&build_state.modules); + clean_mjs_files(&build_state, &project_root); let timing_clean_mjs_elapsed = timing_clean_mjs.elapsed(); println!( "{}\r{} {}Cleaned mjs files in {:.2}s", diff --git a/src/clean.rs b/src/clean.rs index 87db2a4..296a5aa 100644 --- a/src/clean.rs +++ b/src/clean.rs @@ -1,3 +1,4 @@ +use crate::bsconfig; use crate::build; use crate::build_types::*; use crate::helpers; @@ -44,8 +45,8 @@ fn remove_asts(source_file: &str, package_name: &str, root_path: &str, is_root: )); } -fn remove_mjs_file(source_file: &str) { - let _ = std::fs::remove_file(helpers::change_extension(source_file, "mjs")); +fn remove_mjs_file(source_file: &str, suffix: &bsconfig::Suffix) { + let _ = std::fs::remove_file(helpers::change_extension(source_file, &suffix.to_string())); } fn remove_compile_assets( @@ -77,21 +78,39 @@ fn remove_compile_assets( } } -pub fn clean_mjs_files(all_modules: &AHashMap) { +pub fn clean_mjs_files(build_state: &BuildState, project_root: &str) { // get all rescript file locations - let rescript_file_locations = all_modules + let rescript_file_locations = build_state + .modules .values() .filter_map(|module| match &module.source_type { SourceType::SourceFile(source_file) => { - Some(source_file.implementation.path.to_string()) + let package = build_state.packages.get(&module.package_name).unwrap(); + Some(( + std::path::PathBuf::from(helpers::get_package_path( + &project_root, + &module.package_name, + package.is_root, + )) + .join(source_file.implementation.path.to_string()) + .to_string_lossy() + .to_string(), + package + .bsconfig + .suffix + .to_owned() + .unwrap_or(bsconfig::Suffix::Mjs), + )) } _ => None, }) - .collect::>(); + .collect::>(); rescript_file_locations .par_iter() - .for_each(|rescript_file_location| remove_mjs_file(&rescript_file_location)); + .for_each(|(rescript_file_location, suffix)| { + remove_mjs_file(&rescript_file_location, &suffix) + }); } pub fn cleanup_previous_build(build_state: &mut BuildState) -> (usize, usize, AHashSet) { @@ -104,6 +123,7 @@ pub fn cleanup_previous_build(build_state: &mut BuildState) -> (usize, usize, AH SystemTime, String, bool, + Option, ), > = AHashMap::new(); let mut cmi_modules: AHashMap = AHashMap::new(); @@ -178,6 +198,7 @@ pub fn cleanup_previous_build(build_state: &mut BuildState) -> (usize, usize, AH entry.metadata().unwrap().modified().unwrap(), ast_file_path, package.is_root, + package.bsconfig.suffix.to_owned(), ), ); let _ = ast_rescript_file_locations.insert(res_file_path); @@ -227,6 +248,7 @@ pub fn cleanup_previous_build(build_state: &mut BuildState) -> (usize, usize, AH _last_modified, _ast_file_path, is_root, + suffix, ) = ast_modules .get(&res_file_location.to_string()) .expect("Could not find module name for ast file"); @@ -244,7 +266,10 @@ pub fn cleanup_previous_build(build_state: &mut BuildState) -> (usize, usize, AH &build_state.project_root, *is_root, ); - remove_mjs_file(&res_file_location) + remove_mjs_file( + &res_file_location, + &suffix.to_owned().unwrap_or(bsconfig::Suffix::Mjs), + ); }); ast_rescript_file_locations @@ -258,6 +283,7 @@ pub fn cleanup_previous_build(build_state: &mut BuildState) -> (usize, usize, AH ast_last_modified, ast_file_path, _is_root, + _suffix, ) = ast_modules .get(res_file_location) .expect("Could not find module name for ast file"); @@ -331,7 +357,7 @@ pub fn cleanup_previous_build(build_state: &mut BuildState) -> (usize, usize, AH let ast_module_names = ast_modules .values() - .map(|(module_name, _, _, _, _, _)| module_name) + .map(|(module_name, _, _, _, _, _, _)| module_name) .collect::>(); let all_module_names = build_state