| 1 |
open! Coq_dune |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
let native_mode = Coq_module.Rule_type.Coqc |
| 31 |
|
| 32 |
let native = match Coq_config.native_compiler with |
| 33 |
| Coq_config.NativeOff -> Coq_module.Rule_type.Disabled |
| 34 |
| Coq_config.NativeOn _ -> native_mode |
| 35 |
|
| 36 |
|
| 37 |
type args = { |
| 38 |
tname : string list; |
| 39 |
base_dir : string; |
| 40 |
async : bool; |
| 41 |
rule : Coq_module.Rule_type.t; |
| 42 |
split : bool; |
| 43 |
noinit : bool; |
| 44 |
user_flags : Arg.t list; |
| 45 |
dependencies : string list; |
| 46 |
} |
| 47 |
|
| 48 |
let parse_args () : args = |
| 49 |
match Array.to_list Sys.argv with |
| 50 |
| _ :: tname :: base_dir :: args -> |
| 51 |
let tname = String.split_on_char '.' tname in |
| 52 |
let _backtrace = [Arg.A "-d"; Arg.A "backtrace"] in |
| 53 |
let default = { base_dir; tname; |
| 54 |
async = false; |
| 55 |
split = false; |
| 56 |
noinit = false; |
| 57 |
rule = Coq_module.Rule_type.Regular { native }; |
| 58 |
user_flags = []; |
| 59 |
dependencies = []; |
| 60 |
} |
| 61 |
in |
| 62 |
let rec parse a = function |
| 63 |
| [] -> a |
| 64 |
| "-async" :: rest -> parse { a with async = true; user_flags = Arg.[A "-async-proofs"; A "on"] } rest |
| 65 |
| "-split" :: rest -> parse { a with split = true } rest |
| 66 |
| "-dep" :: d :: rest -> parse { a with dependencies = d :: a.dependencies } rest |
| 67 |
| "-noinit" :: rest -> parse { a with noinit = true } rest |
| 68 |
|
| 69 |
| "" :: rest -> parse a rest |
| 70 |
| unknown :: _ -> raise (Invalid_argument unknown) |
| 71 |
in |
| 72 |
parse default args |
| 73 |
| _ -> raise (Invalid_argument "usage: gen_rules theory_name directory") |
| 74 |
|
| 75 |
let ppr fmt = List.iter (Dune_file.Rule.pp fmt) |
| 76 |
let ppi fmt = List.iter (Dune_file.Install.pp fmt) |
| 77 |
|
| 78 |
let main () = |
| 79 |
|
| 80 |
let { tname; base_dir; async; rule; user_flags; split; noinit; dependencies } = parse_args () in |
| 81 |
let root_lvl = List.length (String.split_on_char '/' base_dir) in |
| 82 |
|
| 83 |
let corelib = |
| 84 |
let directory = Path.relative (Path.make "theories") "Corelib" in |
| 85 |
Coq_rules.Theory.{ directory; dirname = ["Corelib"]; implicit = true; deps = [] } |
| 86 |
in |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
let boot, implicit = if tname = ["Corelib"] then begin |
| 91 |
if noinit then CErrors.user_err Pp.(str "Corelib handles -noinit automatically."); |
| 92 |
Coq_rules.Boot_type.Corelib, true |
| 93 |
end |
| 94 |
else Coq_rules.Boot_type.Regular { corelib; noinit }, false |
| 95 |
in |
| 96 |
|
| 97 |
|
| 98 |
let dir_info = Dir_info.scan ~prefix:[] base_dir in |
| 99 |
let directory = Path.make base_dir in |
| 100 |
let theory = Coq_rules.Theory.{ directory; dirname = tname; implicit; deps = dependencies } in |
| 101 |
let cctx = Coq_rules.Context.make ~root_lvl ~theory ~user_flags ~rule ~boot ~dir_info ~async ~split in |
| 102 |
let vo_rules = Coq_rules.vo_rules ~dir_info ~cctx in |
| 103 |
let install_rules = Coq_rules.install_rules ~dir_info ~cctx in |
| 104 |
|
| 105 |
|
| 106 |
let fmt = Format.std_formatter in |
| 107 |
|
| 108 |
List.iter (Dune_file.Subdir.pp ppr fmt) vo_rules; |
| 109 |
List.iter (Dune_file.Subdir.pp ppi fmt) install_rules; |
| 110 |
|
| 111 |
|
| 112 |
begin |
| 113 |
match native_mode with |
| 114 |
|
| 115 |
| Coq_module.Rule_type.Disabled |
| 116 |
| Coq_module.Rule_type.Coqc -> () |
| 117 |
| Coq_module.Rule_type.CoqNative -> |
| 118 |
let coqnative_rules = Coq_rules.coqnative_rules ~dir_info ~cctx in |
| 119 |
List.iter (Dune_file.Subdir.pp ppr fmt) coqnative_rules |
| 120 |
end; |
| 121 |
|
| 122 |
Format.pp_print_flush fmt (); |
| 123 |
() |
| 124 |
|
| 125 |
let pr_feedback (fb : Feedback.feedback) = |
| 126 |
match fb.contents with |
| 127 |
| Message (_,_,_,msg) -> Format.eprintf "%a" Pp.pp_with msg |
| 128 |
| _ -> () [@@warning "-4"] |
| 129 |
|
| 130 |
let () = |
| 131 |
Printexc.record_backtrace true; |
| 132 |
let _ : int = Feedback.add_feeder pr_feedback in |
| 133 |
try main () |
| 134 |
with exn -> |
| 135 |
Format.eprintf "[gen_rules] Fatal error:@ @[<2>%a@]@\n%!" Pp.pp_with (CErrors.print exn); |
| 136 |
exit 1 |