Skip to content

✨ - Add bsc-path argument #118

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

Merged
merged 2 commits into from
May 24, 2024
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
16 changes: 12 additions & 4 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct CompilerArgs {
pub parser_args: Vec<String>,
}

pub fn get_compiler_args(path: &str, rescript_version: Option<String>) -> String {
pub fn get_compiler_args(path: &str, rescript_version: Option<String>, bsc_path: Option<String>) -> 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"),
Expand All @@ -64,7 +64,10 @@ pub fn get_compiler_args(path: &str, rescript_version: Option<String>) -> 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
Expand Down Expand Up @@ -134,10 +137,14 @@ pub fn initialize_build(
default_timing: Option<Duration>,
filter: &Option<regex::Regex>,
path: &str,
bsc_path: Option<String>,
) -> Result<BuildState, InitializeBuildError> {
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);

Expand Down Expand Up @@ -412,6 +419,7 @@ pub fn build(
path: &str,
no_timing: bool,
create_sourcedirs: bool,
bsc_path: Option<String>,
) -> Result<BuildState, BuildError> {
let default_timing: Option<std::time::Duration> = if no_timing {
Some(std::time::Duration::new(0.0 as u64, 0.0 as u32))
Expand All @@ -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(_) => {
Expand Down
8 changes: 6 additions & 2 deletions src/build/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) {
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();
Expand Down
11 changes: 9 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ struct Args {

#[arg(long)]
rescript_version: Option<String>,

#[arg(long)]
bsc_path: Option<String>,
}

fn main() {
Expand All @@ -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);
}
}
Expand All @@ -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}");
Expand Down
5 changes: 3 additions & 2 deletions src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async fn async_watch(
after_build: Option<String>,
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));
Expand Down Expand Up @@ -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() {
Expand Down