Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ - Use package.path instead of manually constructing path part 2 #87

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn build(filter: &Option<regex::Regex>, path: &str, no_timing: bool) -> Resu
let _ = stdout().flush();
let mut build_state = BuildState::new(project_root, root_config_name, packages);
packages::parse_packages(&mut build_state);
logs::initialize(&build_state.project_root, &build_state.packages);
logs::initialize(&build_state.packages);
let timing_source_files_elapsed = timing_source_files.elapsed();
println!(
"{}\r{} {}Found source files in {:.2}s",
Expand Down Expand Up @@ -158,7 +158,7 @@ pub fn build(filter: &Option<regex::Regex>, path: &str, no_timing: bool) -> Resu
print!("{}", &err);
}
Err(err) => {
logs::finalize(&build_state.project_root, &build_state.packages);
logs::finalize(&build_state.packages);
println!(
"{}\r{} {}Error parsing source files in {:.2}s",
LINE_CLEAR,
Expand Down Expand Up @@ -204,7 +204,7 @@ pub fn build(filter: &Option<regex::Regex>, path: &str, no_timing: bool) -> Resu
);
let compile_duration = start_compiling.elapsed();

logs::finalize(&build_state.project_root, &build_state.packages);
logs::finalize(&build_state.packages);
pb.finish();
clean::cleanup_after_build(&build_state);
if compile_errors.len() > 0 {
Expand Down
107 changes: 22 additions & 85 deletions src/build/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,21 @@ use rayon::prelude::*;
use std::io::Write;
use std::time::Instant;

fn remove_ast(source_file: &str, package_path: &str, root_path: &str, is_root: bool) {
fn remove_ast(package: &packages::Package, source_file: &str) {
let _ = std::fs::remove_file(helpers::get_compiler_asset(
source_file,
package_path,
package,
&packages::Namespace::NoNamespace,
root_path,
source_file,
"ast",
is_root,
));
}

fn remove_iast(source_file: &str, package_path: &str, root_path: &str, is_root: bool) {
fn remove_iast(package: &packages::Package, source_file: &str) {
let _ = std::fs::remove_file(helpers::get_compiler_asset(
source_file,
package_path,
package,
&packages::Namespace::NoNamespace,
root_path,
source_file,
"iast",
is_root,
));
}

Expand All @@ -39,50 +35,26 @@ fn remove_mjs_file(source_file: &str, suffix: &String) {
));
}

fn remove_compile_asset(
source_file: &str,
package_path: &str,
namespace: &packages::Namespace,
root_path: &str,
is_root: bool,
extension: &str,
) {
fn remove_compile_asset(package: &packages::Package, source_file: &str, extension: &str) {
let _ = std::fs::remove_file(helpers::get_compiler_asset(
package,
&package.namespace,
source_file,
package_path,
namespace,
root_path,
extension,
is_root,
));
let _ = std::fs::remove_file(helpers::get_bs_compiler_asset(
package,
&package.namespace,
source_file,
package_path,
namespace,
root_path,
extension,
is_root,
));
}

pub fn remove_compile_assets(
source_file: &str,
package_path: &str,
namespace: &packages::Namespace,
root_path: &str,
is_root: bool,
) {
pub fn remove_compile_assets(package: &packages::Package, source_file: &str) {
// optimization
// only issue cmti if htere is an interfacce file
for extension in &["cmj", "cmi", "cmt", "cmti"] {
remove_compile_asset(
source_file,
package_path,
namespace,
root_path,
is_root,
extension,
);
remove_compile_asset(package, source_file, extension);
}
}

Expand All @@ -99,7 +71,7 @@ pub fn clean_mjs_files(build_state: &BuildState) {
.get(&build_state.root_config_name)
.expect("Could not find root package");
Some((
std::path::PathBuf::from(package.package_dir.to_string())
std::path::PathBuf::from(package.path.to_string())
.join(source_file.implementation.path.to_string())
.to_string_lossy()
.to_string(),
Expand Down Expand Up @@ -145,9 +117,7 @@ pub fn cleanup_previous_build(
let AstModule {
module_name,
package_name,
namespace: package_namespace,
ast_file_path,
is_root,
suffix,
..
} = compile_assets_state
Expand All @@ -159,31 +129,15 @@ pub fn cleanup_previous_build(
.packages
.get(package_name)
.expect("Could not find package");
remove_compile_assets(
res_file_location,
&package.package_dir,
package_namespace,
&build_state.project_root,
*is_root,
);
remove_compile_assets(package, res_file_location);
remove_mjs_file(
&res_file_location,
&suffix
.to_owned()
.unwrap_or(String::from(bsconfig::DEFAULT_SUFFIX)),
);
remove_iast(
res_file_location,
&package.package_dir,
&build_state.project_root,
*is_root,
);
remove_ast(
res_file_location,
&package.package_dir,
&build_state.project_root,
*is_root,
);
remove_iast(package, res_file_location);
remove_ast(package, res_file_location);
match helpers::get_extension(ast_file_path).as_str() {
"iast" => Some(module_name.to_owned()),
"ast" => None,
Expand Down Expand Up @@ -361,18 +315,8 @@ pub fn cleanup_after_build(build_state: &BuildState) {
if failed_to_parse(module) {
match &module.source_type {
SourceType::SourceFile(source_file) => {
remove_iast(
&source_file.implementation.path,
&package.package_dir,
&build_state.project_root,
package.is_root,
);
remove_ast(
&source_file.implementation.path,
&package.package_dir,
&build_state.project_root,
package.is_root,
);
remove_iast(package, &source_file.implementation.path);
remove_ast(package, &source_file.implementation.path);
}
_ => (),
}
Expand All @@ -386,14 +330,7 @@ pub fn cleanup_after_build(build_state: &BuildState) {
// we only clean the cmt (typed tree) here, this will cause the file to be recompiled
// (and thus keep showing the warning), but it will keep the cmi file, so that we don't
// unecessary mark all the dependents as dirty, when there is no change in the interface
remove_compile_asset(
&source_file.implementation.path,
&package.package_dir,
&package.namespace,
&build_state.project_root,
package.is_root,
"cmt",
);
remove_compile_asset(package, &source_file.implementation.path, "cmt");
}
SourceType::MlMap(_) => (),
}
Expand Down Expand Up @@ -424,11 +361,11 @@ pub fn clean(path: &str) {
);
std::io::stdout().flush().unwrap();

let path_str = helpers::get_build_path(&project_root, &package.package_dir, package.is_root);
let path_str = package.get_build_path();
let path = std::path::Path::new(&path_str);
let _ = std::fs::remove_dir_all(path);

let path_str = helpers::get_bs_build_path(&project_root, &package.package_dir, package.is_root);
let path_str = package.get_bs_build_path();
let path = std::path::Path::new(&path_str);
let _ = std::fs::remove_dir_all(path);
});
Expand Down
Loading
Loading