Skip to content

Commit 3789848

Browse files
committed
Add separate command for documenation generation and add option for specifying output directory.
1 parent e7bda8d commit 3789848

File tree

5 files changed

+94
-13
lines changed

5 files changed

+94
-13
lines changed

src/ec.ml

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ let main () =
393393
eco : bool;
394394
gccompact : int option;
395395
gendoc : bool;
396+
outdirp : string option;
396397
}
397398
end in
398399

@@ -448,7 +449,8 @@ let main () =
448449
; interactive = true
449450
; eco = false
450451
; gccompact = None
451-
; gendoc = false }
452+
; gendoc = false
453+
; outdirp = None }
452454

453455
end
454456

@@ -476,14 +478,54 @@ let main () =
476478
; interactive = false
477479
; eco = cmpopts.cmpo_noeco
478480
; gccompact = cmpopts.cmpo_compact
479-
; gendoc = cmpopts.cmpo_doc }
481+
; gendoc = false
482+
; outdirp = None }
480483

481484
end
482485

483486
| `Runtest _ ->
484487
(* Eagerly executed *)
485488
assert false
489+
490+
| `GenDoc docopts -> begin
491+
let name = docopts.doco_input in
486492

493+
begin try
494+
let ext = Filename.extension name in
495+
ignore (EcLoader.getkind ext : EcLoader.kind)
496+
with EcLoader.BadExtension ext ->
497+
Format.eprintf "do not know what to do with %s@." ext;
498+
exit 1
499+
end;
500+
501+
let prvoff = {
502+
prvo_maxjobs = None;
503+
prvo_timeout = None;
504+
prvo_cpufactor = None;
505+
prvo_provers = None;
506+
prvo_pragmas = [];
507+
prvo_ppwidth = None;
508+
prvo_checkall = false;
509+
prvo_profile = false;
510+
prvo_iterate = false;
511+
prvo_why3server = None; }
512+
in
513+
514+
let terminal =
515+
lazy (T.from_channel ~name (open_in name))
516+
in
517+
518+
{ prvopts = prvoff
519+
; input = Some name
520+
; terminal = terminal
521+
; interactive = false
522+
; eco = true
523+
; gccompact = None
524+
; gendoc = true
525+
; outdirp = docopts.doco_outdirp }
526+
end
527+
528+
487529
in
488530

489531
(match state.input with
@@ -679,7 +721,7 @@ let main () =
679721
if not state.eco then
680722
finalize_input state.input (EcCommands.current ());
681723
if state.gendoc then
682-
EcDoc.generate_html state.input (EcCommands.current ());
724+
EcDoc.generate_html ?outdirp:state.outdirp state.input (EcCommands.current ());
683725
exit 0
684726
end;
685727
with

src/ecDoc.ml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,25 @@ let emit_pages (dp : string) (th : string) (tstr : string) (gdoc : string list)
290290

291291
(* -------------------------------------------------------------------- *)
292292
(* input = input name, scope contains all documentation items *)
293-
let generate_html (fname : string option) (scope : EcScope.scope) : unit =
293+
let generate_html ?(outdirp : string option) (fname : string option) (scope : EcScope.scope) : unit =
294294
match fname with
295295
| Some fn ->
296296
let kind =
297297
try EcLoader.getkind (Filename.extension fn)
298298
with EcLoader.BadExtension _ -> assert false
299299
in
300-
let dp, fn = Filename.dirname fn, Filename.basename fn in
300+
let dp =
301+
match outdirp with
302+
| None -> Filename.dirname fn
303+
| Some outdirp ->
304+
try
305+
if Sys.is_directory outdirp
306+
then outdirp
307+
else raise (Invalid_argument (Format.sprintf "%s is not an existing directory." outdirp))
308+
with
309+
| _ as ex -> Printf.eprintf "Exception: %s\n." (Printexc.to_string ex); raise ex
310+
in
311+
let fn = Filename.basename fn in
301312
let th = Filename.remove_extension fn in
302313
let tstr = thkind_str kind ^ " " ^ th in
303314
begin

src/ecDoc.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
(* -------------------------------------------------------------------- *)
2-
val generate_html : string option -> EcScope.scope -> unit
2+
val generate_html : ?outdirp:string -> string option -> EcScope.scope -> unit

src/ecOptions.ml

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type command = [
99
| `Config
1010
| `Runtest of run_option
1111
| `Why3Config
12+
| `GenDoc of doc_option
1213
]
1314

1415
and options = {
@@ -24,7 +25,6 @@ and cmp_option = {
2425
cmpo_tstats : string option;
2526
cmpo_noeco : bool;
2627
cmpo_script : bool;
27-
cmpo_doc : bool;
2828
}
2929

3030
and cli_option = {
@@ -41,6 +41,11 @@ and run_option = {
4141
runo_rawargs : string list;
4242
}
4343

44+
and doc_option = {
45+
doco_input : string;
46+
doco_outdirp : string option;
47+
}
48+
4449
and prv_options = {
4550
prvo_maxjobs : int option;
4651
prvo_timeout : int option;
@@ -342,8 +347,7 @@ let specs = {
342347
`Spec ("tstats" , `String, "Save timing statistics to <file>");
343348
`Spec ("script" , `Flag , "Computer-friendly output");
344349
`Spec ("no-eco" , `Flag , "Do not cache verification results");
345-
`Spec ("compact", `Int , "<internal>");
346-
`Spec ("doc" , `Flag , "Generate documentation")]);
350+
`Spec ("compact", `Int , "<internal>")]);
347351

348352
("cli", "Run EasyCrypt top-level", [
349353
`Group "loader";
@@ -361,6 +365,10 @@ let specs = {
361365
]);
362366

363367
("why3config", "Configure why3", []);
368+
369+
("gendoc", "Generate documentation", [
370+
`Spec ("odir", `String, "Output documentation files in <dir>")
371+
]);
364372
];
365373

366374
xp_groups = [
@@ -508,8 +516,7 @@ let cmp_options_of_values ini values input =
508516
cmpo_compact = get_int "compact" values;
509517
cmpo_tstats = get_string "tstats" values;
510518
cmpo_noeco = get_flag "no-eco" values;
511-
cmpo_script = get_flag "script" values;
512-
cmpo_doc = get_flag "doc" values; }
519+
cmpo_script = get_flag "script" values; }
513520

514521
let runtest_options_of_values ini values (input, scenarios) =
515522
{ runo_input = input;
@@ -519,6 +526,10 @@ let runtest_options_of_values ini values (input, scenarios) =
519526
runo_jobs = get_int "jobs" values;
520527
runo_rawargs = get_strings "raw-args" values; }
521528

529+
let doc_options_of_values values input =
530+
{ doco_input = input;
531+
doco_outdirp = get_string "odir" values; }
532+
522533
(* -------------------------------------------------------------------- *)
523534
let parse getini argv =
524535
let (command, values, anons) = parse specs argv in
@@ -578,8 +589,20 @@ let parse getini argv =
578589

579590
(cmd, ini, true)
580591

581-
| _ -> assert false
592+
| "gendoc" ->
593+
begin
594+
match anons with
595+
| [input] ->
596+
let ini = getini None in
597+
let cmd = `GenDoc (doc_options_of_values values input) in
598+
(cmd, ini, true)
582599

600+
| _ ->
601+
raise (Arg.Bad "this command takes a single input file as argument")
602+
end
603+
604+
| _ -> assert false
605+
583606
in {
584607
o_options = glb_options_of_values ~env ini values;
585608
o_command = command;

src/ecOptions.mli

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type command = [
55
| `Config
66
| `Runtest of run_option
77
| `Why3Config
8+
| `GenDoc of doc_option
89
]
910

1011
and options = {
@@ -20,7 +21,6 @@ and cmp_option = {
2021
cmpo_tstats : string option;
2122
cmpo_noeco : bool;
2223
cmpo_script : bool;
23-
cmpo_doc : bool;
2424
}
2525

2626
and cli_option = {
@@ -37,6 +37,11 @@ and run_option = {
3737
runo_rawargs : string list;
3838
}
3939

40+
and doc_option = {
41+
doco_input : string;
42+
doco_outdirp : string option;
43+
}
44+
4045
and prv_options = {
4146
prvo_maxjobs : int option;
4247
prvo_timeout : int option;

0 commit comments

Comments
 (0)