diff --git a/src/build.rs b/src/build.rs index 213347c..dcf734f 100644 --- a/src/build.rs +++ b/src/build.rs @@ -453,7 +453,7 @@ fn generate_asts(version: &str, build_state: &mut BuildState, pb: &ProgressBar) } _ => (), } - logs::append(&package.package_dir, &err); + logs::append(&build_state.project_root, package.is_root, &package.name, &err); stderr.push_str(&err); } } @@ -465,7 +465,7 @@ fn generate_asts(version: &str, build_state: &mut BuildState, pb: &ProgressBar) } _ => (), } - logs::append(&package.package_dir, &err); + logs::append(&build_state.project_root, package.is_root, &package.name, &err); has_failure = true; stderr.push_str(&err); } @@ -484,7 +484,7 @@ fn generate_asts(version: &str, build_state: &mut BuildState, pb: &ProgressBar) } _ => (), } - logs::append(&package.package_dir, &err); + logs::append(&build_state.project_root, package.is_root, &package.name, &err); stderr.push_str(&err); } } @@ -500,7 +500,7 @@ fn generate_asts(version: &str, build_state: &mut BuildState, pb: &ProgressBar) } _ => (), } - logs::append(&package.package_dir, &err); + logs::append(&build_state.project_root, package.is_root, &package.name, &err); has_failure = true; stderr.push_str(&err); } @@ -599,12 +599,15 @@ pub fn parse_packages(build_state: &mut BuildState) { Some(package_modules) => build_state.module_names.extend(package_modules), None => (), } - let build_path_abs = helpers::get_build_path( + let build_path_abs = + helpers::get_build_path(&build_state.project_root, &package.bsconfig.name, package.is_root); + let bs_build_path = helpers::get_bs_build_path( &build_state.project_root, &package.bsconfig.name, package.is_root, ); helpers::create_build_path(&build_path_abs); + helpers::create_build_path(&bs_build_path); package.namespace.to_suffix().iter().for_each(|namespace| { // generate the mlmap "AST" file for modules that have a namespace configured @@ -1251,7 +1254,7 @@ pub fn build(filter: &Option, path: &str, no_timing: bool) -> Resu println!("{}", &err); } Err(err) => { - logs::finalize(&build_state.packages); + logs::finalize(&build_state.project_root, &build_state.packages); println!( "{}\r{} {}Error parsing source files in {:.2}s", LINE_CLEAR, @@ -1538,15 +1541,24 @@ pub fn build(filter: &Option, path: &str, no_timing: bool) -> Resu SourceType::SourceFile(ref mut source_file) => { match result { Ok(Some(err)) => { - source_file.implementation.compile_state = - CompileState::Warning; - logs::append(&package.package_dir, &err); + source_file.implementation.compile_state = CompileState::Warning; + logs::append( + &build_state.project_root, + package.is_root, + &package.name, + &err, + ); compile_warnings.push_str(&err); } Ok(None) => (), Err(err) => { source_file.implementation.compile_state = CompileState::Error; - logs::append(&package.package_dir, &err); + logs::append( + &build_state.project_root, + package.is_root, + &package.name, + &err, + ); compile_errors.push_str(&err); } }; @@ -1554,14 +1566,24 @@ pub fn build(filter: &Option, path: &str, no_timing: bool) -> Resu Some(Ok(Some(err))) => { source_file.interface.as_mut().unwrap().compile_state = CompileState::Warning; - logs::append(&package.package_dir, &err); + logs::append( + &build_state.project_root, + package.is_root, + &package.name, + &err, + ); compile_warnings.push_str(&err); } Some(Ok(None)) => (), Some(Err(err)) => { source_file.interface.as_mut().unwrap().compile_state = CompileState::Error; - logs::append(&package.package_dir, &err); + logs::append( + &build_state.project_root, + package.is_root, + &package.name, + &err, + ); compile_errors.push_str(&err); } _ => (), @@ -1587,7 +1609,7 @@ pub fn build(filter: &Option, path: &str, no_timing: bool) -> Resu } let compile_duration = start_compiling.elapsed(); - logs::finalize(&build_state.packages); + logs::finalize(&build_state.project_root, &build_state.packages); pb.finish(); clean::cleanup_after_build(&build_state); if compile_errors.len() > 0 { diff --git a/src/logs.rs b/src/logs.rs index bc09f7e..95c9e08 100644 --- a/src/logs.rs +++ b/src/logs.rs @@ -12,12 +12,13 @@ enum Location { Ocaml, } -fn get_log_file_path(subfolder: Location, name: &str) -> String { - let subfolder_str = match subfolder { - Location::Bs => "bs", - Location::Ocaml => "ocaml", +fn get_log_file_path(project_root: &str, subfolder: Location, name: &str, is_root: bool) -> String { + let build_folder = match subfolder { + Location::Bs => helpers::get_bs_build_path(project_root, name, is_root), + Location::Ocaml => helpers::get_build_path(project_root, name, is_root), }; - name.to_owned() + "/lib/" + subfolder_str + "/.compiler.log" + + build_folder.to_owned() + "/.compiler.log" } fn escape_colours(str: &str) -> String { @@ -43,38 +44,45 @@ fn write_to_log_file(mut file: File, package_name: &str, content: &str) { } } -pub fn initialize(packages: &AHashMap) { - packages.par_iter().for_each(|(name, _)| { - let _ = File::create(get_log_file_path(Location::Bs, name)).map(|file| { - write_to_log_file( - file, - &name, - &format!("#Start({})\n", helpers::get_system_time()), - ) - }); +pub fn initialize(project_root: &str, packages: &AHashMap) { + packages.par_iter().for_each(|(name, package)| { + let _ = File::create(get_log_file_path( + project_root, + Location::Bs, + name, + package.is_root, + )) + .map(|file| write_to_log_file(file, &name, &format!("#Start({})\n", helpers::get_system_time()))) + .expect(&("Cannot create compiler log for package ".to_owned() + name)); }) } -pub fn append(name: &str, str: &str) { - let _ = File::options() +pub fn append(project_root: &str, is_root: bool, name: &str, str: &str) { + File::options() .append(true) - .open(get_log_file_path(Location::Bs, name)) - .map(|file| write_to_log_file(file, &name, str)); + .open(get_log_file_path(project_root, Location::Bs, name, is_root)) + .map(|file| write_to_log_file(file, &name, str)) + .expect( + &("Cannot write compilerlog: ".to_owned() + + &get_log_file_path(project_root, Location::Bs, name, is_root)), + ); } -pub fn finalize(packages: &AHashMap) { - packages.par_iter().for_each(|(name, _)| { +pub fn finalize(project_root: &str, packages: &AHashMap) { + packages.par_iter().for_each(|(name, package)| { let _ = File::options() .append(true) - .open(get_log_file_path(Location::Bs, name)) - .map(|file| { - write_to_log_file( - file, - &name, - &format!("#Done({})\n", helpers::get_system_time()), - ) - }); + .open(get_log_file_path( + project_root, + Location::Bs, + name, + package.is_root, + )) + .map(|file| write_to_log_file(file, &name, &format!("#Done({})\n", helpers::get_system_time()))); - let _ = std::fs::copy(get_log_file_path(Location::Bs, name), get_log_file_path(Location::Ocaml, name)); + let _ = std::fs::copy( + get_log_file_path(project_root, Location::Bs, name, package.is_root), + get_log_file_path(project_root, Location::Ocaml, name, package.is_root), + ); }) }