Commit 978a8df0 authored by Andrei Paskevich's avatar Andrei Paskevich

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.
parent f984ada8
......@@ -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 []
......
......@@ -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 ->
......
......@@ -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
(*******************************)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment