From 978a8df03c65eb8a9bc4bd4d04b374766bf15697 Mon Sep 17 00:00:00 2001 From: Andrei Paskevich Date: Fri, 18 Nov 2011 08:29:04 +0100 Subject: [PATCH] export Call_prover.call_on_file This allows to call editors from IDE in a less hackish way and might even fix the problem with Coq editing on Windows. --- src/driver/call_provers.ml | 33 +++++++++++++++++++++------------ src/driver/call_provers.mli | 10 ++++++++++ src/ide/session.ml | 9 ++++----- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/driver/call_provers.ml b/src/driver/call_provers.ml index 4aaf4b875..693b1eb79 100644 --- a/src/driver/call_provers.ml +++ b/src/driver/call_provers.ml @@ -114,29 +114,30 @@ type post_prover_call = unit -> prover_result type prover_call = Unix.wait_flag list -> post_prover_call type pre_prover_call = unit -> prover_call -let call_on_buffer ~command ?(timelimit=0) ?(memlimit=0) - ~regexps ~timeregexps ~exitcodes ~filename buffer = +let call_on_file ~command ?(timelimit=0) ?(memlimit=0) + ~regexps ~timeregexps ~exitcodes + ?(cleanup=false) fin = let arglist = Cmdline.cmdline_split command in let command = List.hd arglist in - let fin,cin = Filename.open_temp_file "why_" ("_" ^ filename) in - Buffer.output_buffer cin buffer; close_out cin; - let on_timelimit = ref false in + let on_filename = ref false in let cmd_regexp = Str.regexp "%\\(.\\)" in - let replace file s = match Str.matched_group 1 s with + let replace s = match Str.matched_group 1 s with | "%" -> "%" - | "f" -> file + | "f" -> on_filename := true; fin | "t" -> on_timelimit := true; string_of_int timelimit | "m" -> string_of_int memlimit | "b" -> string_of_int (memlimit * 1024) | _ -> failwith "unknown format specifier, use %%f, %%t, %%m or %%b" in let subst s = - try Str.global_substitute cmd_regexp (replace fin) s - with e -> Sys.remove fin; raise e + try Str.global_substitute cmd_regexp replace s + with e -> if cleanup then Sys.remove fin; raise e in - let argarray = Array.of_list (List.map subst arglist) in + let arglist = List.map subst arglist in + let argarray = Array.of_list + (if !on_filename then arglist else arglist @ [fin]) in fun () -> let fd_in = Unix.openfile fin [Unix.O_RDONLY] 0 in @@ -158,8 +159,8 @@ let call_on_buffer ~command ?(timelimit=0) ?(memlimit=0) fun () -> if Debug.nottest_flag debug then begin - Sys.remove fin; - Sys.remove fout; + if cleanup then Sys.remove fin; + Sys.remove fout end; let ans = match ret with | Unix.WSTOPPED n -> @@ -183,6 +184,14 @@ let call_on_buffer ~command ?(timelimit=0) ?(memlimit=0) pr_output = out; pr_time = time } +let call_on_buffer ~command ?(timelimit=0) ?(memlimit=0) + ~regexps ~timeregexps ~exitcodes ~filename buffer = + + let fin,cin = Filename.open_temp_file "why_" ("_" ^ filename) in + Buffer.output_buffer cin buffer; close_out cin; + call_on_file ~command ~timelimit ~memlimit + ~regexps ~timeregexps ~exitcodes ~cleanup:true fin + let query_call call = try Some (call [Unix.WNOHANG]) with Exit -> None let wait_on_call call = call [] diff --git a/src/driver/call_provers.mli b/src/driver/call_provers.mli index 0b65fe233..f21b6d44e 100644 --- a/src/driver/call_provers.mli +++ b/src/driver/call_provers.mli @@ -72,6 +72,16 @@ type pre_prover_call = unit -> prover_call type post_prover_call = unit -> prover_result (** Thread-unsafe closure that interprets the prover's results *) +val call_on_file : + command : string -> + ?timelimit : int -> + ?memlimit : int -> + regexps : (Str.regexp * prover_answer) list -> + timeregexps : timeregexp list -> + exitcodes : (int * prover_answer) list -> + ?cleanup : bool -> + string -> pre_prover_call + val call_on_buffer : command : string -> ?timelimit : int -> diff --git a/src/ide/session.ml b/src/ide/session.ml index 8e19fcb54..9b6390bad 100644 --- a/src/ide/session.ml +++ b/src/ide/session.ml @@ -584,10 +584,10 @@ let schedule_proof_attempt ~debug ~timelimit ~memlimit ?old actions_queue; run_idle_handler () -let schedule_edition command callback = +let schedule_edition command filename callback = let precall = - Call_provers.call_on_buffer ~command ~regexps:[] ~timeregexps:[] - ~exitcodes:[(0,Call_provers.Unknown "")] ~filename:"" (Buffer.create 1) + Call_provers.call_on_file ~command ~regexps:[] ~timeregexps:[] + ~exitcodes:[(0,Call_provers.Unknown "")] filename in callback Running; running_proofs := (Check_prover(callback, precall ())) :: !running_proofs; @@ -622,8 +622,7 @@ let schedule_edit_proof ~debug:_ ~editor ~file ~driver ~callback goal = Driver.print_task ?old driver fmt goal; Util.option_iter close_in old; close_out ch; - let command = editor ^ " \"" ^ file ^ "\"" in - schedule_edition command callback + schedule_edition editor file callback (*******************************) -- GitLab