| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
type t = |
| 12 |
{ boot : bool |
| 13 |
; coqlib : string option |
| 14 |
; sort : bool |
| 15 |
; vos : bool |
| 16 |
; noglob : bool |
| 17 |
; ml_path : string list |
| 18 |
; vo_path : (bool * string * string) list |
| 19 |
; dyndep : string |
| 20 |
; worker : string option |
| 21 |
; files : string list |
| 22 |
} |
| 23 |
|
| 24 |
let make () = |
| 25 |
{ boot = false |
| 26 |
; coqlib = None |
| 27 |
; sort = false |
| 28 |
; vos = false |
| 29 |
; noglob = false |
| 30 |
; ml_path = [] |
| 31 |
; vo_path = [] |
| 32 |
; dyndep = "both" |
| 33 |
; worker = None |
| 34 |
; files = [] |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
let warn_unknown_option = |
| 39 |
CWarnings.create ~name:"unknown-option" |
| 40 |
Pp.(fun opt -> str "Unknown option \"" ++ str opt ++ str "\".") |
| 41 |
|
| 42 |
let usage () = |
| 43 |
let open Printf in |
| 44 |
eprintf " usage: rocq dep [options] <filename>+\n"; |
| 45 |
eprintf " options:\n"; |
| 46 |
eprintf " -boot : For rocq developers, prints dependencies over rocq library files (omitted by default).\n"; |
| 47 |
eprintf " -sort : output the given file name ordered by dependencies\n"; |
| 48 |
eprintf " -noglob | -no-glob : \n"; |
| 49 |
eprintf " -noinit : currently no effect\n"; |
| 50 |
eprintf " -f file : read -I, -Q, -R and filenames from _CoqProject-formatted file.\n"; |
| 51 |
eprintf " -I dir : add (non recursively) dir to ocaml path\n"; |
| 52 |
eprintf " -R dir logname : add and import dir recursively to rocq load path under logical name logname\n"; |
| 53 |
eprintf " -Q dir logname : add (recursively) and open (non recursively) dir to rocq load path under logical name logname\n"; |
| 54 |
eprintf " -vos : also output dependencies about .vos files\n"; |
| 55 |
eprintf " -exclude-dir dir : skip subdirectories named 'dir' during -R/-Q search\n"; |
| 56 |
eprintf " -coqlib dir : set the rocq core library directory\n"; |
| 57 |
eprintf " -dyndep (opt|byte|both|no|var) : set how dependencies over ML modules are printed\n"; |
| 58 |
eprintf " -worker WORKER : output WORKER instead of the rocqworker path\n"; |
| 59 |
eprintf " -w (w1,..,wn) : configure display of warnings\n"; |
| 60 |
eprintf "%!"; |
| 61 |
exit 1 |
| 62 |
|
| 63 |
let warn_project_file = |
| 64 |
let category = CWarnings.CoreCategories.filesystem in |
| 65 |
CWarnings.create ~name:"project-file" ~category Pp.str |
| 66 |
|
| 67 |
let add_ml_path st f = { st with ml_path = f :: st.ml_path } |
| 68 |
|
| 69 |
let add_vo_path st (isr,path,logic) = |
| 70 |
let logic = if String.equal logic "Coq" then "Corelib" else logic in |
| 71 |
{ st with vo_path = (isr,path,logic) :: st.vo_path } |
| 72 |
|
| 73 |
let add_file st f = { st with files = f :: st.files } |
| 74 |
|
| 75 |
let add_from_coqproject st f = |
| 76 |
let open CoqProject_file in |
| 77 |
let fold_sourced f acc l = List.fold_left (fun acc {thing} -> f acc thing) acc l in |
| 78 |
let project = |
| 79 |
try read_project_file ~warning_fn:warn_project_file f |
| 80 |
with |
| 81 |
| Parsing_error msg -> Error.cannot_parse_project_file f msg |
| 82 |
| UnableToOpenProjectFile msg -> Error.cannot_open_project_file msg |
| 83 |
in |
| 84 |
let st = fold_sourced (fun st { path } -> add_ml_path st path) st project.ml_includes in |
| 85 |
let st = fold_sourced (fun st ({path}, l) -> add_vo_path st (false,path,l)) st project.q_includes in |
| 86 |
let st = fold_sourced (fun st ({path}, l) -> add_vo_path st (true,path,l)) st project.r_includes in |
| 87 |
let st = fold_sourced add_file st (all_files project) in |
| 88 |
st |
| 89 |
|
| 90 |
let parse st args = |
| 91 |
let rec parse st = |
| 92 |
function |
| 93 |
| "-boot" :: ll -> parse { st with boot = true } ll |
| 94 |
| "-sort" :: ll -> parse { st with sort = true } ll |
| 95 |
| "-vos" :: ll -> parse { st with vos = true } ll |
| 96 |
| ("-noglob" | "-no-glob") :: ll -> parse { st with noglob = true } ll |
| 97 |
| "-noinit" :: ll -> parse st ll |
| 98 |
| "-f" :: f :: ll -> parse (add_from_coqproject st f) ll |
| 99 |
| "-I" :: r :: ll -> parse (add_ml_path st r) ll |
| 100 |
| "-I" :: [] -> usage () |
| 101 |
| "-R" :: r :: ln :: ll -> parse (add_vo_path st (true, r, ln)) ll |
| 102 |
| "-Q" :: r :: ln :: ll -> parse (add_vo_path st (false, r, ln)) ll |
| 103 |
| ("-Q"|"-R") :: ([] | [_]) -> usage () |
| 104 |
| "-exclude-dir" :: r :: ll -> System.exclude_directory r; parse st ll |
| 105 |
| "-exclude-dir" :: [] -> usage () |
| 106 |
| "-coqlib" :: r :: ll -> parse { st with coqlib = Some r } ll |
| 107 |
| "-coqlib" :: [] -> usage () |
| 108 |
| "-dyndep" :: dyndep :: ll -> parse { st with dyndep } ll |
| 109 |
| "-worker" :: w :: ll -> parse { st with worker = Some w } ll |
| 110 |
| "-w" :: w :: ll -> |
| 111 |
let w = if w = "none" then w else CWarnings.get_flags() ^ "," ^ w in |
| 112 |
CWarnings.set_flags w; |
| 113 |
parse st ll |
| 114 |
| ("-h"|"--help"|"-help") :: _ -> usage () |
| 115 |
| opt :: ll when String.length opt > 0 && opt.[0] = '-' -> |
| 116 |
warn_unknown_option opt; |
| 117 |
parse st ll |
| 118 |
| f :: ll -> parse (add_file st f) ll |
| 119 |
| [] -> st |
| 120 |
in |
| 121 |
let st = parse st args in |
| 122 |
{ st with |
| 123 |
ml_path = List.rev st.ml_path |
| 124 |
; vo_path = List.rev st.vo_path |
| 125 |
; files = List.rev st.files |
| 126 |
} |