Attention une mise à jour du serveur va être effectuée le vendredi 16 avril entre 12h et 12h30. Cette mise à jour va générer une interruption du service de quelques minutes.

Commit 176be2d1 authored by Francois Bobot's avatar Francois Bobot

Final Rc, WhyConf API libdir datadir are in .why.conf

parent 83dc345b
......@@ -120,7 +120,7 @@ LIB_CORE = ident ty term pattern decl theory task pretty env printer trans
LIB_PARSER = ptree denv typing parser lexer
LIB_DRIVER = call_provers driver_ast driver_parser driver_lexer driver \
whyconf
whyconf autodetection
LIB_TRANSFORM = simplify_recursive_definition simplify_formula \
inlining split_conjunction split_goal \
......
......@@ -3,18 +3,18 @@ name = "Alt-Ergo"
exec = "alt-ergo"
exec = "ergo"
version_switch = "-version"
version_regexp = ".*Ergo \\([^ ]*\\)"
version_regexp = ".*Ergo \\([^ \n]*\\)"
version_ok = "0.92"
version_old = "0.8"
version_old = "0.9"
command = "why3-cpulimit %t %m %e %f"
driver = "drivers/alt_ergo.drv"
[ATP cvc3]
[ATP cvc3]
name = "CVC3"
exec = "cvc3"
version_switch = "-version"
version_regexp = "This is CVC3 version \\([^ ]+\\)"
version_regexp = "This is CVC3 version \\([^ \n]+\\)"
version_ok = "2.2"
version_old = "2.1"
command = "why3-cpulimit 0 %m %e -timeout %t -lang smt %f 2>&1"
......@@ -30,7 +30,7 @@ driver = "drivers/tptp.drv"
name = "Gappa"
exec = "gappa"
version_switch = "--version"
version_regexp = "Gappa \\([^ ]*\\)"
version_regexp = "Gappa \\([^ \n]*\\)"
version_ok = "0.13.0"
version_old = "0.11.2"
version_old = "0.12.0"
......@@ -47,7 +47,7 @@ exec = "simplify"
exec = "Simplify-1.5.4"
exec = "Simplify-1.5.5"
version_switch = "-version"
version_regexp = "Simplify version \\([^ ,]+\\)"
version_regexp = "Simplify version \\([^ \n,]+\\)"
version_ok = "1.5.4"
version_ok = "1.5.5"
command = "why3-cpulimit %t %m %e %f 2>&1"
......@@ -56,8 +56,8 @@ driver = "drivers/simplify.drv"
[ATP spass]
name = "Spass"
exec = "SPASS"
version_switch = "-version (TODO)"
version_regexp = "SPASS version \\([^ ,]+\\) (TODO)"
version_switch = " || true"
version_regexp = "SPASS V \\([^ \n\t]+\\)"
command = "why3-cpulimit 0 %m %e -TPTP -PGiven=0 -PProblem=0 -DocProof -TimeLimit=%t %f 2>&1"
driver = "drivers/tptp.drv"
......@@ -66,7 +66,7 @@ name = "Z3"
exec = "z3"
exec = "z3-2.2"
version_switch = "-version"
version_regexp = "Z3 version \\([^ \r]+\\)"
version_regexp = "Z3 version \\([^ \n\r]+\\)"
version_ok = "2.2"
version_old = "2.1"
version_old = "1.3"
......@@ -77,7 +77,7 @@ driver = "drivers/z3.drv"
name = "Coq"
exec = "coqc"
version_switch = "-v"
version_regexp = "The Coq Proof Assistant, version \\([^ ]+\\)"
version_regexp = "The Coq Proof Assistant, version \\([^ \n]+\\)"
version_ok = "8.0"
version_ok = "8.1"
version_ok = "8.2"
......
(**************************************************************************)
(* *)
(* Copyright (C) 2010- *)
(* Francois Bobot *)
(* Jean-Christophe Filliatre *)
(* Johannes Kanig *)
(* Andrei Paskevich *)
(* *)
(* This software is free software; you can redistribute it and/or *)
(* modify it under the terms of the GNU Library General Public *)
(* License version 2.1, with the special exception on linking *)
(* described in file LICENSE. *)
(* *)
(* This software is distributed in the hope that it will be useful, *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *)
(* *)
(**************************************************************************)
open Format
open Util
open Whyconf
open Rc
(* auto-detection of provers *)
type prover_kind = ATP | ITP
type prover_autodetection_data =
{ kind : prover_kind;
prover_id : string;
prover_name : string;
execs : string list;
version_switch : string;
version_regexp : string;
versions_ok : string list;
versions_old : string list;
prover_command : string;
prover_driver : string;
prover_editor : string;
}
let prover_keys =
let add acc k = Sstr.add k acc in
List.fold_left add Sstr.empty
["name";"exec";"version_switch";"version_regexp";
"version_ok";"version_old";"command";
"editor";"driver"]
let load_prover kind (id,section) =
check_exhaustive section prover_keys;
{ kind = kind;
prover_id = id;
prover_name = get_string section "name";
execs = get_stringl section "exec";
version_switch = get_string section ~default:"" "version_switch";
version_regexp = get_string section ~default:"" "version_regexp";
versions_ok = get_stringl section ~default:[] "version_ok";
versions_old = get_stringl section ~default:[] "version_old";
prover_command = get_string section "command";
prover_driver = get_string section "driver";
prover_editor = get_string section ~default:"" "editor";
}
let load rc =
let atps = get_family rc "ATP" in
let atps = List.map (load_prover ATP) atps in
let itps = get_family rc "ITP" in
let tps = List.fold_left (cons (load_prover ITP)) atps itps in
tps
let read_auto_detection_data main =
let filename = Filename.concat main.datadir "provers-detection-data.conf" in
try
let rc = Rc.from_file filename in
load rc
with
| Failure "lexing" ->
eprintf "Syntax error in provers-detection-data.conf@.";
exit 2
| Not_found ->
eprintf "provers-detection-data.conf not found at %s@." filename;
exit 2
let provers_found = ref 0
let prover_tips_info = ref false
let make_command exec com =
let cmd_regexp = Str.regexp "%\\(.\\)" in
let replace s = match Str.matched_group 1 s with
| "e" -> exec
| c -> "%"^c
in
Str.global_substitute cmd_regexp replace com
let detect_prover main acc data =
List.fold_left
(fun acc com ->
let out = Filename.temp_file "out" "" in
let cmd = sprintf "%s %s" com data.version_switch in
let c = sprintf "(%s) > %s" cmd out in
let ret = Sys.command c in
if ret <> 0 then
begin
eprintf "command '%s' failed@." cmd;
acc
end
else
let s =
try
let ch = open_in out in
Sysutil.channel_contents ch
(* let s = ref (input_line ch) in *)
(* while !s = "" do s := input_line ch done; *)
(* close_in ch; *)
(* Sys.remove out; *)
(* !s *)
with Not_found | End_of_file -> ""
in
let re = Str.regexp data.version_regexp in
try
ignore (Str.search_forward re s 0);
let nam = data.prover_name in
let ver = Str.matched_group 1 s in
if List.mem ver data.versions_ok then
eprintf "Found prover %s version %s, OK.@." nam ver
else
begin
prover_tips_info := true;
if List.mem ver data.versions_old then
eprintf "Warning: prover %s version %s is quite old, please \
consider upgrading to a newer version.@."
nam ver
else
eprintf "Warning: prover %s version %s is not known to be \
supported, use it at your own risk!@." nam ver
end;
incr provers_found;
let c = make_command com data.prover_command in
Mstr.add data.prover_id
{name = data.prover_name;
version = ver;
command = c;
driver = Filename.concat main.libdir data.prover_driver;
editor = data.prover_editor} acc
with Not_found ->
begin
prover_tips_info := true;
eprintf "Warning: found prover %s but name/version not \
recognized by regexp `%s'@."
data.prover_name data.version_regexp;
eprintf "Answer was `%s'@." s;
acc
end)
acc
data.execs
let run_auto_detection config =
let main = get_main config in
let l = read_auto_detection_data main in
let detect = List.fold_left (detect_prover main) Mstr.empty l in
let length = Mstr.fold (fun _ _ i -> i+1) detect 0 in
eprintf "%d provers detected.@." length;
set_provers config detect
(**************************************************************************)
(* *)
(* Copyright (C) 2010- *)
(* Francois Bobot *)
(* Jean-Christophe Filliatre *)
(* Johannes Kanig *)
(* Andrei Paskevich *)
(* *)
(* This software is free software; you can redistribute it and/or *)
(* modify it under the terms of the GNU Library General Public *)
(* License version 2.1, with the special exception on linking *)
(* described in file LICENSE. *)
(* *)
(* This software is distributed in the hope that it will be useful, *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *)
(* *)
(**************************************************************************)
(** Replace the provers by autodetected one *)
val run_auto_detection : Whyconf.config -> Whyconf.config
......@@ -21,83 +21,17 @@ open Format
open Util
open Rc
(* Error handling *)
exception SyntaxError
exception ExtraParameters of string
exception MissingParameters of string
exception UnknownSection of string
exception UnknownField of string
exception MissingSection of string
exception MissingField of string
exception DuplicateSection of string
(* exception DuplicateField of string * Rc.rc_value * Rc.rc_value *)
(* exception StringExpected of string * Rc.rc_value *)
(* exception IdentExpected of string * Rc.rc_value *)
(* exception IntExpected of string * Rc.rc_value *)
exception DuplicateProver of string
let error ?loc e = match loc with
| None -> raise e
| Some loc -> raise (Loc.Located (loc, e))
(* lib and shared dirs *)
let libdir =
try
Sys.getenv "WHY3LIB"
with Not_found -> Config.libdir
let libdir =
try
Sys.getenv "WHY3LIB"
with Not_found -> Config.libdir
let datadir =
try
Sys.getenv "WHY3DATA"
with Not_found -> Config.datadir
(* conf files *)
(*
let print_rc_value fmt = function
| Rc.RCint i -> fprintf fmt "%d" i
| Rc.RCbool b -> fprintf fmt "%B" b
| Rc.RCfloat f -> fprintf fmt "%f" f
| Rc.RCstring s -> fprintf fmt "\"%s\"" s
| Rc.RCident s -> fprintf fmt "%s" s
*)
let () = Exn_printer.register (fun fmt e -> match e with
| SyntaxError ->
fprintf fmt "syntax error"
| ExtraParameters s ->
fprintf fmt "section '%s': header too long" s
| MissingParameters s ->
fprintf fmt "section '%s': header too short" s
| UnknownSection s ->
fprintf fmt "unknown section '%s'" s
| UnknownField s ->
fprintf fmt "unknown field '%s'" s
| MissingSection s ->
fprintf fmt "section '%s' is missing" s
| MissingField s ->
fprintf fmt "field '%s' is missing" s
| DuplicateSection s ->
fprintf fmt "section '%s' is already given" s
(* | DuplicateField (s,u,v) -> *)
(* fprintf fmt "cannot set field '%s' to %a, as it is already set to %a"
*)
(* s print_rc_value v print_rc_value u *)
(* | StringExpected (s,v) -> *)
(* fprintf fmt "cannot set field '%s' to %a: a string is expected" *)
(* s print_rc_value v *)
(* | IdentExpected (s,v) -> *)
(* fprintf fmt "cannot set field '%s' to %a: an identifier is expected"*)
(* s print_rc_value v *)
(* | IntExpected (s,v) -> *)
(* fprintf fmt "cannot set field '%s' to %a: an integer is expected" *)
(* s print_rc_value v *)
| DuplicateProver s ->
fprintf fmt "prover %s is already listed" s
| e -> raise e)
try
Sys.getenv "WHY3DATA"
with Not_found -> Config.datadir
(* Configuration file *)
......@@ -110,7 +44,9 @@ type config_prover = {
}
type main = {
loadpath : string list; (* "/usr/local/share/why/theories" *)
libdir : string;
datadir : string;
loadpath : string list;
timelimit : int;
memlimit : int;
running_provers_max : int;
......@@ -119,23 +55,30 @@ type main = {
type config = {
conf_file : string; (* "/home/innocent_user/.why.conf" *)
config : Rc.t ;
main : main;
provers : config_prover Mstr.t;
}
let default_main = {
loadpath = [Filename.concat Config.why_libdir "theories"];
timelimit = 10;
memlimit = 0;
running_provers_max = 2;
}
let default_main =
{
libdir = libdir;
datadir = datadir;
loadpath = [Filename.concat libdir "theories"];
timelimit = 10;
memlimit = 0;
running_provers_max = 2;
}
let set_main config main =
let set_main rc main =
let section = empty_section in
let section = set_string section "libdir" main.libdir in
let section = set_string section "datadir" main.datadir in
let section = set_stringl section "loadpath" main.loadpath in
let section = set_int section "timelimit" main.timelimit in
let section = set_int section "memlimit" main.memlimit in
let section =
set_int section "running_provers_max" main.running_provers_max in
{config with config = set_section config.config "main" section}
set_section rc "main" section
let set_prover id prover family =
let section = empty_section in
......@@ -146,14 +89,9 @@ let set_prover id prover family =
let section = set_string section "editor" prover.editor in
(id,section)::family
let set_provers config provers =
let set_provers rc provers =
let family = Mstr.fold set_prover provers [] in
{config with config = set_family config.config "prover" family}
let default_config =
{conf_file = Filename.concat (Rc.get_home_dir ()) ".why.conf";
config = Rc.empty;
}
set_family rc "prover" family
let absolute_filename dirname f =
if Filename.is_relative f then
......@@ -171,13 +109,10 @@ let load_prover dirname provers (id,section) =
editor = get_string ~default:"" section "editor";
} provers
let get_provers config =
let dirname = Filename.dirname config.conf_file in
let provers = get_family config.config "prover" in
List.fold_left (load_prover dirname) Mstr.empty provers
let load_main dirname section =
{ loadpath = List.map (absolute_filename dirname)
{ libdir = get_string ~default:default_main.libdir section "libdir";
datadir = get_string ~default:default_main.datadir section "datadir";
loadpath = List.map (absolute_filename dirname)
(get_stringl ~default:default_main.loadpath section "loadpath");
timelimit = get_int ~default:default_main.timelimit section "timelimit";
memlimit = get_int ~default:default_main.memlimit section "memlimit";
......@@ -186,183 +121,67 @@ let load_main dirname section =
"running_provers_max";
}
let get_main config =
match get_section config.config "main" with
| None -> default_main
| Some main ->
let dirname = Filename.dirname config.conf_file in
load_main dirname main
let read_config conf_file =
let read_config_rc conf_file =
let filename = match conf_file with
| Some filename -> filename
| None -> begin try Sys.getenv "WHY_CONFIG" with Not_found ->
if Sys.file_exists "why.conf" then "why.conf" else
if Sys.file_exists ".why.conf" then ".why.conf" else
let f = Filename.concat (Rc.get_home_dir ()) ".why.conf" in
if Sys.file_exists f then f else raise Not_found
if Sys.file_exists f then f else raise Exit
end
in
let rc = Rc.from_file filename in
filename,Rc.from_file filename
let get_config (filename,rc) =
let dirname = Filename.dirname filename in
let rc, main =
match get_section rc "main" with
| None -> set_main rc default_main,default_main
| Some main ->
rc, load_main dirname main in
let provers = get_family rc "prover" in
let provers = List.fold_left (load_prover dirname) Mstr.empty provers in
{ conf_file = filename;
config = rc;
config = rc;
main = main;
provers = provers;
}
let read_config conf_file =
try read_config conf_file with Not_found -> default_config
let save_config config = to_file config.conf_file config.config
let filenamerc = try read_config_rc conf_file
with Exit ->
(Filename.concat (Rc.get_home_dir ()) ".why.conf",Rc.empty) in
get_config filenamerc
(* auto-detection of provers *)
type prover_kind = ATP | ITP
type prover_autodetection_data =
{ kind : prover_kind;
prover_id : string;
mutable prover_name : string;
mutable execs : string list;
mutable version_switch : string;
mutable version_regexp : string;
mutable versions_ok : string list;
mutable versions_old : string list;
mutable prover_command : string;
mutable prover_driver : string;
mutable prover_editor : string;
}
let default k id =
{ kind = k;
prover_id = id;
prover_name = "";
execs = [];
version_switch = "";
version_regexp = "";
versions_ok = [];
versions_old = [];
prover_command = "";
prover_driver = "";
prover_editor = "";
}
let save_config config = to_file config.conf_file config.config
let prover_keys =
let add acc k = Sstr.add k acc in
List.fold_left add Sstr.empty
["name";"exec";"version_switch";"version_regexp";
"version_ok";"version_old";"command";
"editor";"driver"]
let get_main config = config.main
let get_provers config = config.provers
let load_prover kind (id,section) =
check_exhaustive section prover_keys;
{ kind = kind;
prover_id = id;
prover_name = get_string section "name";
execs = get_stringl section "exec";
version_switch = get_string section ~default:"" "version_switch";
version_regexp = get_string section ~default:"" "version_regexp";
versions_ok = get_stringl section ~default:[] "version_ok";
versions_old = get_stringl section ~default:[] "version_old";
prover_command = get_string section "command";
prover_driver = get_string section "driver";
prover_editor = get_string section ~default:"" "editor";
let set_main config main =
{config with
config = set_main config.config main;
main = main;
}
let load rc =
let atps = get_family rc "ATP" in
let atps = List.map (load_prover ATP) atps in
let itps = get_family rc "ITP" in
let tps = List.fold_left (cons (load_prover ITP)) atps itps in
tps
let read_auto_detection_data () =
try
let rc = Rc.from_file "prover-detection-data.conf" in
load rc
with
| Failure "lexing" ->
eprintf "Syntax error in prover-detection-data.conf@.";
exit 2
| Not_found ->
eprintf "prover-detection-data.conf not found@.";
exit 2
let provers_found = ref 0
let prover_tips_info = ref false
let set_provers config provers =
{config with
config = set_provers config.config provers;
provers = provers;
}
let get_section config name = assert (name <> "main");
get_section config.config name
let make_command exec com =
let cmd_regexp = Str.regexp "%\\(.\\)" in
let replace s = match Str.matched_group 1 s with
| "e" -> exec
| c -> "%"^c
in
Str.global_substitute cmd_regexp replace com
let get_family config name = assert (name <> "prover");
get_family config.config name
let detect_prover acc data =
List.fold_left
(fun acc com ->
let out = Filename.temp_file "out" "" in
let cmd = com ^ " " ^ data.version_switch in
let c = cmd ^ " > " ^ out in
let ret = Sys.command c in
if ret <> 0 then
begin
eprintf "command '%s' failed@." cmd;
acc
end
else
let s =
try
let ch = open_in out in
let s = ref (input_line ch) in
while !s = "" do s := input_line ch done;
close_in ch;
Sys.remove out;
!s
with Not_found | End_of_file -> ""
in
let re = Str.regexp data.version_regexp in
if Str.string_match re s 0 then
let nam = data.prover_name in
let ver = Str.matched_group 1 s in