From add09eb2da0a96c25046de4c20acf3f1a9b8565d Mon Sep 17 00:00:00 2001 From: Jaap Frolich Date: Fri, 24 May 2024 16:20:39 +0200 Subject: [PATCH] support bsc-path arg also in clean and compiler args --- src/build.rs | 7 +++++-- src/build/clean.rs | 8 ++++++-- src/main.rs | 7 +++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/build.rs b/src/build.rs index 082bc6c..e3d6fca 100644 --- a/src/build.rs +++ b/src/build.rs @@ -52,7 +52,7 @@ pub struct CompilerArgs { pub parser_args: Vec, } -pub fn get_compiler_args(path: &str, rescript_version: Option) -> String { +pub fn get_compiler_args(path: &str, rescript_version: Option, bsc_path: Option) -> String { let filename = &helpers::get_abs_path(path); let package_root = helpers::get_abs_path( &helpers::get_nearest_bsconfig(&std::path::PathBuf::from(path)).expect("Couldn't find package root"), @@ -64,7 +64,10 @@ pub fn get_compiler_args(path: &str, rescript_version: Option) -> String let rescript_version = if let Some(rescript_version) = rescript_version { rescript_version } else { - let bsc_path = helpers::get_bsc(&package_root, workspace_root.to_owned()); + let bsc_path = match bsc_path { + Some(bsc_path) => bsc_path, + None => helpers::get_bsc(&package_root, workspace_root.to_owned()), + }; helpers::get_rescript_version(&bsc_path) }; // make PathBuf from package root and get the relative path for filename diff --git a/src/build/clean.rs b/src/build/clean.rs index f4e3c1c..3b5ae8b 100644 --- a/src/build/clean.rs +++ b/src/build/clean.rs @@ -319,12 +319,16 @@ pub fn cleanup_after_build(build_state: &BuildState) { }); } -pub fn clean(path: &str) { +pub fn clean(path: &str, bsc_path: Option) { let project_root = helpers::get_abs_path(path); let workspace_root = helpers::get_workspace_root(&project_root); let packages = packages::make(&None, &project_root, &workspace_root); let root_config_name = packages::get_package_name(&project_root); - let bsc_path = helpers::get_bsc(&project_root, workspace_root.to_owned()); + let bsc_path = match bsc_path { + Some(bsc_path) => bsc_path, + None => helpers::get_bsc(&project_root, workspace_root.to_owned()), + }; + let rescript_version = helpers::get_rescript_version(&bsc_path); let timing_clean_compiler_assets = Instant::now(); diff --git a/src/main.rs b/src/main.rs index 9a5b98e..1a5d8a8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,7 +65,10 @@ fn main() { match args.compiler_args { None => (), Some(path) => { - println!("{}", build::get_compiler_args(&path, args.rescript_version)); + println!( + "{}", + build::get_compiler_args(&path, args.rescript_version, args.bsc_path) + ); std::process::exit(0); } } @@ -76,7 +79,7 @@ fn main() { std::process::exit(1) } lock::Lock::Aquired(_) => match command { - Command::Clean => build::clean::clean(&folder), + Command::Clean => build::clean::clean(&folder, args.bsc_path), Command::Build => { match build::build( &filter,