| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
module CD = Coqdeplib |
| 7 |
module Dep_map = Map.Make(Path) |
| 8 |
|
| 9 |
type t = CD.Dep_info.Dep.t list Dep_map.t |
| 10 |
|
| 11 |
|
| 12 |
let from_list l = |
| 13 |
List.fold_left (fun map { CD.Dep_info.name; deps } -> |
| 14 |
let name = Path.make name in |
| 15 |
let path = Path.add_extension ~ext:".v" name in |
| 16 |
Dep_map.add path deps map) Dep_map.empty l |
| 17 |
|
| 18 |
let debug_coqdep = false |
| 19 |
let debug = false |
| 20 |
|
| 21 |
let coqdep_register_file vAccu file = |
| 22 |
|
| 23 |
CD.Common.treat_file_command_line vAccu (Path.to_string file) |
| 24 |
|
| 25 |
|
| 26 |
let make ~args ~(dir_info : _ Dir_info.t) = |
| 27 |
let args = "-dyndep" :: "opt" :: List.map Arg.to_string args in |
| 28 |
if debug_coqdep then Format.eprintf "coqdep: %s@\n%!" (String.concat " " args); |
| 29 |
let args = Coqdeplib.Args.parse (Coqdeplib.Args.make ()) args in |
| 30 |
|
| 31 |
let make_separator_hack = false in |
| 32 |
let rocqenv, st = CD.Common.init ~make_separator_hack args in |
| 33 |
|
| 34 |
assert (rocqenv = Boot); |
| 35 |
let st = |
| 36 |
Dir_info.fold dir_info ~init:st ~f:(fun ~prefix:_ vAccu files -> |
| 37 |
let files = List.map Coq_module.source files in |
| 38 |
List.fold_left coqdep_register_file vAccu files) in |
| 39 |
CD.Common.compute_deps st |> from_list |
| 40 |
|
| 41 |
let lookup ~dep_info file = |
| 42 |
if debug then Format.eprintf "lookup: %a@\n%!" Path.pp file; |
| 43 |
let file = Path.coqdep_fixup_dir file in |
| 44 |
Dep_map.find file dep_info |
| 45 |
|
| 46 |
let pp_binding fmt (s, _) = Format.fprintf fmt "%a" Path.pp s |
| 47 |
|
| 48 |
let lookup ~dep_info x = |
| 49 |
try lookup ~dep_info x |
| 50 |
with |
| 51 |
| Not_found -> |
| 52 |
if debug then |
| 53 |
begin |
| 54 |
Format.eprintf "@[<v>%a@]@\n%!" |
| 55 |
(Format.pp_print_list pp_binding) (Dep_map.bindings dep_info); |
| 56 |
Format.eprintf "@[dep: %a@\n%!@]" Path.pp x |
| 57 |
end; |
| 58 |
raise Not_found |