diff --git a/src/build.rs b/src/build.rs index 082bc6c..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 @@ -134,10 +137,14 @@ pub fn initialize_build( default_timing: Option, filter: &Option, path: &str, + bsc_path: Option, ) -> Result { let project_root = helpers::get_abs_path(path); let workspace_root = helpers::get_workspace_root(&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 root_config_name = packages::get_package_name(&project_root); let rescript_version = helpers::get_rescript_version(&bsc_path); @@ -412,6 +419,7 @@ pub fn build( path: &str, no_timing: bool, create_sourcedirs: bool, + bsc_path: Option, ) -> Result { let default_timing: Option = if no_timing { Some(std::time::Duration::new(0.0 as u64, 0.0 as u32)) @@ -420,7 +428,7 @@ pub fn build( }; let timing_total = Instant::now(); let mut build_state = - initialize_build(default_timing, filter, path).map_err(BuildError::InitializeBuild)?; + initialize_build(default_timing, filter, path, bsc_path).map_err(BuildError::InitializeBuild)?; match incremental_build(&mut build_state, default_timing, true, false, create_sourcedirs) { Ok(_) => { 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..0617373 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,6 +50,9 @@ struct Args { #[arg(long)] rescript_version: Option, + + #[arg(long)] + bsc_path: Option, } fn main() { @@ -65,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); } } @@ -76,13 +82,14 @@ 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, &folder, args.no_timing.unwrap_or(false), args.create_sourcedirs.unwrap_or(false), + args.bsc_path, ) { Err(e) => { eprintln!("Error Building: {e}"); diff --git a/src/watcher.rs b/src/watcher.rs index b5685d8..166d44c 100644 --- a/src/watcher.rs +++ b/src/watcher.rs @@ -53,7 +53,7 @@ async fn async_watch( after_build: Option, create_sourcedirs: bool, ) -> notify::Result<()> { - let mut build_state = build::initialize_build(None, filter, path).expect("Can't initialize build"); + let mut build_state = build::initialize_build(None, filter, path, None).expect("Can't initialize build"); let mut needs_compile_type = CompileType::Incremental; // create a mutex to capture if ctrl-c was pressed let ctrlc_pressed = Arc::new(Mutex::new(false)); @@ -205,7 +205,8 @@ async fn async_watch( } CompileType::Full => { let timing_total = Instant::now(); - build_state = build::initialize_build(None, filter, path).expect("Can't initialize build"); + build_state = + build::initialize_build(None, filter, path, None).expect("Can't initialize build"); let _ = build::incremental_build(&mut build_state, None, initial_build, false, create_sourcedirs); if let Some(a) = after_build.clone() {