From 48e6d74560dedf597c189b7b3a03a7ffa8d1a687 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 2b17581..b8b6342 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 e4bde12..364d816 100644 --- a/src/build/clean.rs +++ b/src/build/clean.rs @@ -318,12 +318,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 2b519b4..0617373 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,7 +68,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); } } @@ -79,7 +82,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,