@@ -50,15 +50,11 @@ let read_file_cmi = f => {
5050};
5151
5252let get_output_name = name => {
53- let name =
54- try (Filename . chop_extension(name)) {
55- | Invalid_argument (_ ) => name
56- };
57- name ++ ".gr.wasm" ;
53+ Filepath . String . remove_extension(name) ++ ".gr.wasm" ;
5854};
5955
6056let find_ext_in_dir = (dir, name) => {
61- let fullname = Filename . concat(dir, name);
57+ let fullname = Filepath . String . concat(dir, name);
6258 let rec process_ext =
6359 fun
6460 | [] => None
@@ -68,9 +64,6 @@ let find_ext_in_dir = (dir, name) => {
6864 process_ext;
6965};
7066
71- let is_relpath = path =>
72- Filename . is_relative(path) && ! Filename . is_implicit(path);
73-
7467let find_in_path_uncap = (~exts= [] , base_dir, path, name) => {
7568 let rec try_dir =
7669 fun
@@ -81,14 +74,14 @@ let find_in_path_uncap = (~exts=[], base_dir, path, name) => {
8174 | None => try_dir(rem)
8275 };
8376 };
84- if (! Filename . is_relative(name) && Grain_utils . Fs_access . file_exists(name)) {
77+ if (! Filepath . String . is_relative(name) && Fs_access . file_exists(name)) {
8578 (
8679 name,
87- Filename . dirname(name),
88- Filename . remove_extension(Filename . basename(name)),
89- Filename . extension(name),
80+ Filepath . String . dirname(name),
81+ Filepath . String . ( remove_extension(basename(name) )),
82+ Filepath . String . extension(name),
9083 );
91- } else if (is_relpath(name)) {
84+ } else if (Filepath . String . is_relpath(name)) {
9285 try_dir([ base_dir] );
9386 } else {
9487 try (try_dir(path)) {
@@ -103,25 +96,18 @@ module PathTbl = {
10396
10497 let add : (t (' a ), (string , string ), ' a ) => unit =
10598 (tbl, (dir, unit_name), v) => {
106- let dir = Grain_utils . Filepath . String . realpath_quick(dir);
107- Hashtbl . add(
108- tbl,
109- Grain_utils . Filepath . String . smart_cat(dir, unit_name),
110- v,
111- );
99+ let dir = Filepath . String . realpath_quick(dir);
100+ Hashtbl . add(tbl, Filepath . String . smart_cat(dir, unit_name), v);
112101 };
113102
114103 let find_opt :
115104 (~disable_relpath : bool =?, t (' a ), string , list (string ), string ) =>
116105 option (' a ) =
117106 (~disable_relpath= false , tbl, base_path, path, unit_name) =>
118- if (! disable_relpath && is_relpath(unit_name)) {
107+ if (! disable_relpath && Filepath . String . is_relpath(unit_name)) {
119108 Hashtbl . find_opt(
120109 tbl,
121- Grain_utils . Filepath . String . canonicalize_relpath(
122- base_path,
123- unit_name,
124- ),
110+ Filepath . String . canonicalize_relpath(base_path, unit_name),
125111 );
126112 } else {
127113 List . fold_left(
@@ -131,9 +117,7 @@ module PathTbl = {
131117 | None =>
132118 Hashtbl . find_opt(
133119 tbl,
134- Grain_utils . Filepath . String . (
135- smart_cat(realpath_quick(elt), unit_name)
136- ),
120+ Filepath . String . (smart_cat(realpath_quick(elt), unit_name)),
137121 )
138122 }
139123 },
@@ -169,8 +153,8 @@ let current_resolution_table = () => {
169153
170154let log_resolution = (unit_name, dir, basename) => {
171155 let resolution =
172- Grain_utils . Filepath . (
173- to_string @@ String . derelativize @@ Filename . concat(dir, basename)
156+ Filepath . (
157+ to_string @@ String . derelativize @@ String . concat(dir, basename)
174158 );
175159 PathTbl . add(current_resolution_table() , (dir, unit_name), resolution);
176160 resolution;
@@ -179,12 +163,12 @@ let log_resolution = (unit_name, dir, basename) => {
179163let resolve_unit = (~search_path=?, ~cache= true , ~base_dir=?, unit_name) => {
180164 let base_dir =
181165 switch (base_dir) {
182- | None => Filename . dirname(current_filename^ () )
166+ | None => Filepath . String . dirname(current_filename^ () )
183167 | Some (bd ) => bd
184168 };
185169 let path =
186170 switch (search_path) {
187- | None => Grain_utils . Config . module_search_path()
171+ | None => Config . module_search_path()
188172 | Some (p ) => p
189173 };
190174 switch (
@@ -199,8 +183,8 @@ let resolve_unit = (~search_path=?, ~cache=true, ~base_dir=?, unit_name) => {
199183 if (cache) {
200184 log_resolution(unit_name, dir, basename);
201185 } else {
202- Grain_utils . Filepath . (
203- to_string @@ String . derelativize @@ Filename . concat(dir, basename)
186+ Filepath . (
187+ to_string @@ String . derelativize @@ String . concat(dir, basename)
204188 );
205189 };
206190 };
@@ -259,19 +243,19 @@ let located_to_out_file_name = (~base=?, located) => {
259243 | GrainModule (_ , Some (outpath ))
260244 | WasmModule (outpath ) => outpath
261245 };
262- Grain_utils . Filepath . ( to_string(String . derelativize(~base? , ret) ));
246+ Filepath . to_string(Filepath . String . derelativize(~base? , ret));
263247};
264248
265249let locate_unit_object_file = (~path=?, ~base_dir=?, unit_name) => {
266250 let base_dir =
267251 switch (base_dir) {
268- | None => Filename . dirname(current_filename^ () )
252+ | None => Filepath . String . dirname(current_filename^ () )
269253 | Some (bd ) => bd
270254 };
271255 let path =
272256 switch (path) {
273257 | Some (p ) => p
274- | None => Grain_utils . Config . module_search_path()
258+ | None => Config . module_search_path()
275259 };
276260 located_to_out_file_name(locate_module(base_dir, path, unit_name));
277261};
@@ -289,7 +273,7 @@ module Dependency_graph =
289273
290274 let rec get_dependencies : (t , string => option (t )) => list (t ) =
291275 (dn, lookup) => {
292- let base_dir = Filename . dirname(dn. dn_file_name);
276+ let base_dir = Filepath . String . dirname(dn. dn_file_name);
293277 let active_search_path = Config . module_search_path() ;
294278 let located = dn. dn_latest_resolution^;
295279
@@ -372,7 +356,7 @@ module Dependency_graph =
372356 // all dependencies have expected CRC, and the module was compiled with
373357 // the current compiler configuration. Otherwise, we need to recompile.
374358 let config_sum = Cmi_format . config_sum() ;
375- let base_dir = Filename . dirname(srcpath);
359+ let base_dir = Filepath . String . dirname(srcpath);
376360 dn. dn_up_to_date :=
377361 (
378362 switch (read_file_cmi(objpath)) {
@@ -419,7 +403,7 @@ module Dependency_graph =
419403 | Some (WasmModule (_ )) =>
420404 failwith ("impossible: compile_module > WasmModule" )
421405 | Some (GrainModule (srcpath , _ )) =>
422- Grain_utils . Filepath . ( to_string(String . derelativize(srcpath) ))
406+ Filepath . to_string(Filepath . String . derelativize(srcpath))
423407 };
424408 let outpath = get_output_name(srcpath);
425409 let loc = Option . value(loc, ~default= Grain_parsing . Location . dummy_loc);
@@ -429,8 +413,8 @@ module Dependency_graph =
429413 | Seq . Cons ((parent , unit_name ), _ ) => unit_name
430414 };
431415 with_preserve_unit^ (~loc, chosen_unit_name, srcpath, () =>
432- Grain_utils . Warnings . with_preserve_warnings(() =>
433- Grain_utils . Config . preserve_config(() =>
416+ Warnings . with_preserve_warnings(() =>
417+ Config . preserve_config(() =>
434418 compile_module_dependency^ (srcpath, outpath)
435419 )
436420 )
@@ -439,7 +423,7 @@ module Dependency_graph =
439423 dn. dn_up_to_date := true ;
440424 PathTbl . add(
441425 current_located_module_cache() ,
442- (Filename . dirname(outpath), chosen_unit_name),
426+ (Filepath . String . dirname(outpath), chosen_unit_name),
443427 GrainModule (srcpath, Some (outpath)),
444428 );
445429 };
@@ -448,8 +432,8 @@ module Dependency_graph =
448432let locate_module_file = (~loc, ~disable_relpath= false , unit_name) => {
449433 /* NOTE: We need to take care here to *not* wrap get_up_to_date with this try/with, since
450434 it will falsely raise No_module_file if a Not_found is raised during the compilation */
451- let base_dir = Filename . dirname(current_filename^ () );
452- let path = Grain_utils . Config . module_search_path() ;
435+ let base_dir = Filepath . String . dirname(current_filename^ () );
436+ let path = Config . module_search_path() ;
453437 let located =
454438 try (locate_module(~disable_relpath, base_dir, path, unit_name)) {
455439 | Not_found => error(No_module_file (unit_name, None ))
0 commit comments