Skip to content

Commit e0084c2

Browse files
committed
feat: run rescript-legacy when passing --legacy
1 parent fd4e1de commit e0084c2

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

src/build.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ use serde::Serialize;
2121
use std::fmt;
2222
use std::fs::File;
2323
use std::io::{stdout, Write};
24+
use std::os::unix::process::ExitStatusExt;
2425
use std::path::PathBuf;
26+
use std::process::Stdio;
2527
use std::time::{Duration, Instant};
2628

2729
use self::compile::compiler_args;
@@ -506,3 +508,21 @@ pub fn build(
506508
}
507509
}
508510
}
511+
512+
pub fn pass_through_legacy(args: Vec<String>) -> i32 {
513+
let project_root = helpers::get_abs_path(".");
514+
let workspace_root = helpers::get_workspace_root(&project_root);
515+
516+
let bsb_path = helpers::get_rescript_legacy(&project_root, workspace_root);
517+
518+
let status = std::process::Command::new(bsb_path)
519+
.args(args)
520+
.stdout(Stdio::inherit())
521+
.stderr(Stdio::inherit())
522+
.status();
523+
524+
status
525+
.unwrap_or(std::process::ExitStatus::from_raw(1))
526+
.code()
527+
.unwrap_or(1)
528+
}

src/helpers.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,21 @@ pub fn create_build_path(build_path: &str) {
146146
.unwrap();
147147
}
148148

149+
pub fn get_rescript_legacy(root_path: &str, workspace_root: Option<String>) -> String {
150+
match (
151+
PathBuf::from(format!("{}/node_modules/rescript/rescript", root_path)).canonicalize(),
152+
workspace_root.map(|workspace_root| {
153+
PathBuf::from(format!("{}/node_modules/rescript/rescript", workspace_root)).canonicalize()
154+
}),
155+
) {
156+
(Ok(path), _) => path,
157+
(_, Some(Ok(path))) => path,
158+
_ => panic!("Could not find rescript"),
159+
}
160+
.to_string_lossy()
161+
.to_string()
162+
}
163+
149164
pub fn get_bsc(root_path: &str, workspace_root: Option<String>) -> String {
150165
let subfolder = match (std::env::consts::OS, std::env::consts::ARCH) {
151166
("macos", "aarch64") => "darwinarm64",

src/main.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,15 @@ struct Args {
8989
///
9090
/// After this flag is encountered, the rest of the command line arguments are passed to the legacy build system.
9191
#[arg(long, allow_hyphen_values = true, num_args = 0..)]
92-
legacy: Vec<String>,
92+
legacy: Option<Vec<String>>,
9393
}
9494

9595
fn main() -> Result<()> {
9696
let args = Args::parse();
9797

98-
if !args.legacy.is_empty() {
99-
let s = std::env::args().collect::<Vec<String>>().join(" ");
100-
101-
println!("Using legacy build system");
102-
println!("Running: {s}");
103-
std::process::exit(0);
98+
if let Some(legacy_args) = args.legacy {
99+
let code = build::pass_through_legacy(legacy_args);
100+
std::process::exit(code);
104101
}
105102

106103
let log_level_filter = args.verbose.log_level_filter();

0 commit comments

Comments
 (0)