Skip to content

Commit 4a97a8f

Browse files
authored
✨ - Add bsc-path argument (#118)
1 parent f406559 commit 4a97a8f

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

src/build.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub struct CompilerArgs {
5252
pub parser_args: Vec<String>,
5353
}
5454

55-
pub fn get_compiler_args(path: &str, rescript_version: Option<String>) -> String {
55+
pub fn get_compiler_args(path: &str, rescript_version: Option<String>, bsc_path: Option<String>) -> String {
5656
let filename = &helpers::get_abs_path(path);
5757
let package_root = helpers::get_abs_path(
5858
&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>) -> String
6464
let rescript_version = if let Some(rescript_version) = rescript_version {
6565
rescript_version
6666
} else {
67-
let bsc_path = helpers::get_bsc(&package_root, workspace_root.to_owned());
67+
let bsc_path = match bsc_path {
68+
Some(bsc_path) => bsc_path,
69+
None => helpers::get_bsc(&package_root, workspace_root.to_owned()),
70+
};
6871
helpers::get_rescript_version(&bsc_path)
6972
};
7073
// make PathBuf from package root and get the relative path for filename
@@ -134,10 +137,14 @@ pub fn initialize_build(
134137
default_timing: Option<Duration>,
135138
filter: &Option<regex::Regex>,
136139
path: &str,
140+
bsc_path: Option<String>,
137141
) -> Result<BuildState, InitializeBuildError> {
138142
let project_root = helpers::get_abs_path(path);
139143
let workspace_root = helpers::get_workspace_root(&project_root);
140-
let bsc_path = helpers::get_bsc(&project_root, workspace_root.to_owned());
144+
let bsc_path = match bsc_path {
145+
Some(bsc_path) => bsc_path,
146+
None => helpers::get_bsc(&project_root, workspace_root.to_owned()),
147+
};
141148
let root_config_name = packages::get_package_name(&project_root);
142149
let rescript_version = helpers::get_rescript_version(&bsc_path);
143150

@@ -412,6 +419,7 @@ pub fn build(
412419
path: &str,
413420
no_timing: bool,
414421
create_sourcedirs: bool,
422+
bsc_path: Option<String>,
415423
) -> Result<BuildState, BuildError> {
416424
let default_timing: Option<std::time::Duration> = if no_timing {
417425
Some(std::time::Duration::new(0.0 as u64, 0.0 as u32))
@@ -420,7 +428,7 @@ pub fn build(
420428
};
421429
let timing_total = Instant::now();
422430
let mut build_state =
423-
initialize_build(default_timing, filter, path).map_err(BuildError::InitializeBuild)?;
431+
initialize_build(default_timing, filter, path, bsc_path).map_err(BuildError::InitializeBuild)?;
424432

425433
match incremental_build(&mut build_state, default_timing, true, false, create_sourcedirs) {
426434
Ok(_) => {

src/build/clean.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,16 @@ pub fn cleanup_after_build(build_state: &BuildState) {
319319
});
320320
}
321321

322-
pub fn clean(path: &str) {
322+
pub fn clean(path: &str, bsc_path: Option<String>) {
323323
let project_root = helpers::get_abs_path(path);
324324
let workspace_root = helpers::get_workspace_root(&project_root);
325325
let packages = packages::make(&None, &project_root, &workspace_root);
326326
let root_config_name = packages::get_package_name(&project_root);
327-
let bsc_path = helpers::get_bsc(&project_root, workspace_root.to_owned());
327+
let bsc_path = match bsc_path {
328+
Some(bsc_path) => bsc_path,
329+
None => helpers::get_bsc(&project_root, workspace_root.to_owned()),
330+
};
331+
328332
let rescript_version = helpers::get_rescript_version(&bsc_path);
329333

330334
let timing_clean_compiler_assets = Instant::now();

src/main.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ struct Args {
5050

5151
#[arg(long)]
5252
rescript_version: Option<String>,
53+
54+
#[arg(long)]
55+
bsc_path: Option<String>,
5356
}
5457

5558
fn main() {
@@ -65,7 +68,10 @@ fn main() {
6568
match args.compiler_args {
6669
None => (),
6770
Some(path) => {
68-
println!("{}", build::get_compiler_args(&path, args.rescript_version));
71+
println!(
72+
"{}",
73+
build::get_compiler_args(&path, args.rescript_version, args.bsc_path)
74+
);
6975
std::process::exit(0);
7076
}
7177
}
@@ -76,13 +82,14 @@ fn main() {
7682
std::process::exit(1)
7783
}
7884
lock::Lock::Aquired(_) => match command {
79-
Command::Clean => build::clean::clean(&folder),
85+
Command::Clean => build::clean::clean(&folder, args.bsc_path),
8086
Command::Build => {
8187
match build::build(
8288
&filter,
8389
&folder,
8490
args.no_timing.unwrap_or(false),
8591
args.create_sourcedirs.unwrap_or(false),
92+
args.bsc_path,
8693
) {
8794
Err(e) => {
8895
eprintln!("Error Building: {e}");

src/watcher.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async fn async_watch(
5353
after_build: Option<String>,
5454
create_sourcedirs: bool,
5555
) -> notify::Result<()> {
56-
let mut build_state = build::initialize_build(None, filter, path).expect("Can't initialize build");
56+
let mut build_state = build::initialize_build(None, filter, path, None).expect("Can't initialize build");
5757
let mut needs_compile_type = CompileType::Incremental;
5858
// create a mutex to capture if ctrl-c was pressed
5959
let ctrlc_pressed = Arc::new(Mutex::new(false));
@@ -205,7 +205,8 @@ async fn async_watch(
205205
}
206206
CompileType::Full => {
207207
let timing_total = Instant::now();
208-
build_state = build::initialize_build(None, filter, path).expect("Can't initialize build");
208+
build_state =
209+
build::initialize_build(None, filter, path, None).expect("Can't initialize build");
209210
let _ =
210211
build::incremental_build(&mut build_state, None, initial_build, false, create_sourcedirs);
211212
if let Some(a) = after_build.clone() {

0 commit comments

Comments
 (0)