Skip to content

Commit b897851

Browse files
committed
🐛 - Fix crash due to canonalization
1 parent c2770a3 commit b897851

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

src/build.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ fn generate_ast(
9999
"-bs-ast".to_string(),
100100
"-o".to_string(),
101101
ast_path.to_string(),
102-
helpers::canonicalize_string_path(file),
102+
helpers::canonicalize_string_path(file).unwrap(),
103103
],
104104
]
105105
.concat();
106106

107107
/* Create .ast */
108108
let res_to_ast = Command::new(helpers::get_bsc(&root_path))
109-
.current_dir(helpers::canonicalize_string_path(&build_path_abs))
109+
.current_dir(helpers::canonicalize_string_path(&build_path_abs).unwrap())
110110
.args(res_to_ast_args)
111111
.output()
112112
.expect("Error converting .res to .ast");
@@ -606,7 +606,7 @@ pub fn compile_mlmap(package: &package_tree::Package, namespace: &str, root_path
606606
.concat();
607607

608608
let _ = Command::new(helpers::get_bsc(&root_path))
609-
.current_dir(helpers::canonicalize_string_path(&build_path_abs))
609+
.current_dir(helpers::canonicalize_string_path(&build_path_abs).unwrap())
610610
.args(args)
611611
.output()
612612
.expect("err");
@@ -646,7 +646,7 @@ pub fn compile_file(
646646
.map(|x| {
647647
vec![
648648
"-I".to_string(),
649-
helpers::canonicalize_string_path(&helpers::get_build_path(root_path, &x)),
649+
helpers::canonicalize_string_path(&helpers::get_build_path(root_path, &x)).unwrap(),
650650
]
651651
})
652652
.collect::<Vec<Vec<String>>>();
@@ -713,14 +713,12 @@ pub fn compile_file(
713713
// "-I".to_string(),
714714
// abs_node_modules_path.to_string() + "/rescript/ocaml",
715715
// ],
716-
vec![helpers::canonicalize_string_path(&ast_path.to_owned())],
716+
vec![helpers::canonicalize_string_path(&ast_path.to_owned()).unwrap()],
717717
]
718718
.concat();
719719

720720
let to_mjs = Command::new(helpers::get_bsc(&root_path))
721-
.current_dir(helpers::canonicalize_string_path(
722-
&build_path_abs.to_owned(),
723-
))
721+
.current_dir(helpers::canonicalize_string_path(&build_path_abs.to_owned()).unwrap())
724722
.args(to_mjs_args)
725723
.output();
726724

src/clean.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ pub fn cleanup_previous_build(
166166

167167
let canonicalized_rescript_file_locations = rescript_file_locations
168168
.iter()
169-
.map(|rescript_file_location| helpers::canonicalize_string_path(rescript_file_location))
169+
.map(|rescript_file_location| {
170+
helpers::canonicalize_string_path(rescript_file_location).unwrap()
171+
})
170172
.collect::<AHashSet<String>>();
171173
// delete the .mjs file which appear in our previous compile assets
172174
// but does not exists anymore
@@ -385,7 +387,8 @@ pub fn cleanup_after_build(
385387
match &module.source_type {
386388
SourceType::SourceFile(source_file) => {
387389
remove_compile_assets(
388-
&source_file.implementation.path,
390+
&helpers::canonicalize_string_path(&source_file.implementation.path)
391+
.unwrap(),
389392
&module.package.name,
390393
&module.package.namespace,
391394
&project_root,

src/helpers.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,11 @@ pub fn get_compiler_asset(
171171
+ extension
172172
}
173173

174-
pub fn canonicalize_string_path(path: &str) -> String {
174+
pub fn canonicalize_string_path(path: &str) -> Option<String> {
175175
return Path::new(path)
176176
.canonicalize()
177-
.expect("Could not canonicalize")
178-
.to_str()
179-
.expect("Could not canonicalize")
180-
.to_string();
177+
.ok()
178+
.map(|path| path.to_str().expect("Could not canonicalize").to_string());
181179
}
182180

183181
pub fn get_bs_compiler_asset(
@@ -191,12 +189,12 @@ pub fn get_bs_compiler_asset(
191189
"ast" | "iast" => &None,
192190
_ => namespace,
193191
};
194-
let canoncialized_source_file = canonicalize_string_path(source_file);
192+
let canoncialized_source_file = source_file;
193+
let canonicalized_path =
194+
canonicalize_string_path(&get_package_path(root_path, &package_name)).unwrap();
195+
195196
let dir = std::path::Path::new(&canoncialized_source_file)
196-
.strip_prefix(canonicalize_string_path(&get_package_path(
197-
root_path,
198-
&package_name,
199-
)))
197+
.strip_prefix(canonicalized_path)
200198
.unwrap()
201199
.parent()
202200
.unwrap();

0 commit comments

Comments
 (0)