@@ -156,10 +156,11 @@ let extract ~opaque_access ~file ident =
156
156
CWarnings. set_flags warnings
157
157
158
158
(* Add any modules that have been marked "open" *)
159
- let open_modules ms mlf =
159
+ let open_modules ~ dir ms mlf =
160
160
let prefix = String. concat " " List. (concat @@ map (fun m -> [" open " ; m; " ;;" ]) ms) in
161
- let open_cmd = Printf. sprintf " awk -v n=1 -v s=\" %s\" 'NR == n {print s} {print}' %s > __qc_tmp && mv __qc_tmp %s" prefix mlf mlf in
162
- ignore (Sys. command open_cmd)
161
+ let open_cmd = Printf. sprintf " awk -v n=1 -v s=\" %s\" 'NR == n {print s} {print}' %s > %s/__qc_tmp && mv %s/__qc_tmp %s" prefix mlf dir dir mlf in
162
+ if Sys. command open_cmd <> 0 then
163
+ CErrors. user_err (str " awk command failed on " ++ str mlf ++ fnl () )
163
164
164
165
let tmp_int_re = Str. regexp " type int =[ ]*int"
165
166
@@ -180,16 +181,16 @@ let remove_mli mlif =
180
181
Sys. remove mlif;
181
182
ignore (Sys. command (" touch " ^ mlif))
182
183
183
- let fixup mlif mlf =
184
- open_modules ! modules_to_open mlf;
184
+ let fixup ~ dir mlif mlf =
185
+ open_modules ~dir ! modules_to_open mlf;
185
186
redefine_int mlf;
186
187
remove_mli mlif
187
188
188
189
(* Copy over the contents of the ocaml directory *)
189
190
let copy_dirs dir ds =
190
191
List. iter (fun s -> ignore (Sys. command (Printf. sprintf " cp -r %s %s" s dir))) ds
191
192
192
- let compile dir mlif mlf =
193
+ let compile ~ dir mlif mlf =
193
194
let run_command cmd =
194
195
if Sys. command cmd <> 0 then
195
196
let build_log = read_file (dir ^ " /build.log" ) in
@@ -283,17 +284,17 @@ let run_exec execn =
283
284
| Repl -> run_exec_repl execn
284
285
| Forward -> run_exec_forward execn
285
286
286
- let compile_and_run dir mlif mlf =
287
- compile dir mlif mlf |> run_exec
287
+ let compile_and_run ~ dir mlif mlf =
288
+ compile ~ dir mlif mlf |> run_exec
288
289
289
290
let extract_and_run ~plugin_name ~opaque_access ident =
290
291
let dir = mk_tmp_dir ~plugin_name in
291
292
let mlf : string = dir < /> " extracted_main.ml" in
292
293
let mlif : string = Filename. chop_extension mlf ^ " .mli" in
293
294
extract ~opaque_access ~file: mlf ident;
294
- fixup mlif mlf;
295
+ fixup ~dir mlif mlf;
295
296
copy_dirs dir ! extra_dir;
296
- compile_and_run dir mlif mlf
297
+ compile_and_run ~ dir mlif mlf
297
298
;;
298
299
299
300
let mk_ref s = CAst. make @@ CRef (qualid_of_string s, None )
0 commit comments