Skip to content

Commit 6eb6b25

Browse files
committed
CLI for generating source: invert source and impl order
Source is now the positional argument, while impl is passed as an argument. When we generate source for other files (such as dune or .mli or Makefiles or ...) this will come handy.
1 parent 7272a4c commit 6eb6b25

File tree

13 files changed

+83
-63
lines changed

13 files changed

+83
-63
lines changed

src/odoc/bin/main.ml

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -774,11 +774,11 @@ module Make_renderer (R : S) : sig
774774

775775
val targets : docs:string -> unit Term.t * Term.info
776776

777-
val targets_impl : docs:string -> unit Term.t * Term.info
777+
val targets_source : docs:string -> unit Term.t * Term.info
778778

779779
val generate : docs:string -> unit Term.t * Term.info
780780

781-
val generate_impl : docs:string -> unit Term.t * Term.info
781+
val generate_source : docs:string -> unit Term.t * Term.info
782782
end = struct
783783
let input_odoc =
784784
let doc = "Input file." in
@@ -862,19 +862,25 @@ end = struct
862862

863863
let generate ~docs = Generate.(cmd, info ~docs)
864864

865-
module Generate_impl = struct
865+
module Generate_source = struct
866866
let generate extra _hidden output_dir syntax extra_suffix input_file
867867
warnings_options source_file =
868-
let file = Fs.File.of_string input_file in
869-
Rendering.generate_impl_odoc ~renderer:R.renderer ~warnings_options
870-
~syntax ~output:output_dir ~extra_suffix ~source_file extra file
868+
Rendering.generate_source_odoc ~renderer:R.renderer ~warnings_options
869+
~syntax ~output:output_dir ~extra_suffix ~source_file extra input_file
870+
871+
let input_odocl =
872+
let doc = "Linked implementation file." in
873+
Arg.(
874+
required
875+
& opt (some convert_fpath) None
876+
& info [ "impl" ] ~doc ~docv:"impl-file.odocl")
871877

872878
let source_file =
873879
let doc = "Source code for the implementation unit." in
874880
Arg.(
875-
value
876-
& opt (some convert_fpath) None
877-
& info [ "source" ] ~doc ~docv:"file.ml")
881+
required
882+
& pos 0 (some convert_fpath) None
883+
& info ~doc ~docv:"FILE.ml" [])
878884

879885
let cmd =
880886
let syntax =
@@ -895,10 +901,10 @@ end = struct
895901
Format.sprintf "Generate %s files from a $(i,impl-*.odocl)."
896902
R.renderer.name
897903
in
898-
Term.info ~docs ~doc (R.renderer.name ^ "-generate-impl")
904+
Term.info ~docs ~doc (R.renderer.name ^ "-generate-source")
899905
end
900906

901-
let generate_impl ~docs = Generate_impl.(cmd, info ~docs)
907+
let generate_source ~docs = Generate_source.(cmd, info ~docs)
902908

903909
module Targets = struct
904910
let list_targets output_dir directories extra odoc_file =
@@ -940,16 +946,16 @@ end = struct
940946

941947
let targets ~docs = Targets.(cmd, info ~docs)
942948

943-
module Targets_impl = struct
949+
module Targets_source = struct
944950
let list_targets output_dir source_file extra odoc_file =
945-
let odoc_file = Fs.File.of_string odoc_file in
946951
let warnings_options =
947952
{ Odoc_model.Error.warn_error = false; print_warnings = false }
948953
in
949-
Rendering.targets_impl_odoc ~warnings_options ~syntax:OCaml
954+
Rendering.targets_source_odoc ~warnings_options ~syntax:OCaml
950955
~renderer:R.renderer ~output:output_dir ~extra ~source_file odoc_file
951956

952-
let source_file = Generate_impl.source_file
957+
let source_file = Generate_source.source_file
958+
let input_odocl = Generate_source.input_odocl
953959

954960
let cmd =
955961
Term.(
@@ -960,13 +966,13 @@ end = struct
960966
let info ~docs =
961967
let doc =
962968
Format.sprintf
963-
"Print the files that would be generated by $(i,%s-generate-impl)."
969+
"Print the files that would be generated by $(i,%s-generate-source)."
964970
R.renderer.name
965971
in
966-
Term.info (R.renderer.name ^ "-targets-impl") ~docs ~doc
972+
Term.info (R.renderer.name ^ "-targets-source") ~docs ~doc
967973
end
968974

969-
let targets_impl ~docs = Targets_impl.(cmd, info ~docs)
975+
let targets_source ~docs = Targets_source.(cmd, info ~docs)
970976
end
971977

972978
module Odoc_latex_url : sig
@@ -1528,7 +1534,7 @@ let () =
15281534
Compile_asset.(cmd, info ~docs:section_pipeline);
15291535
Odoc_link.(cmd, info ~docs:section_pipeline);
15301536
Odoc_html.generate ~docs:section_pipeline;
1531-
Odoc_html.generate_impl ~docs:section_pipeline;
1537+
Odoc_html.generate_source ~docs:section_pipeline;
15321538
Support_files_command.(cmd, info ~docs:section_pipeline);
15331539
Compile_impl.(cmd, info ~docs:section_pipeline);
15341540
Indexing.(cmd, info ~docs:section_pipeline);
@@ -1539,7 +1545,7 @@ let () =
15391545
Targets.Support_files.(cmd, info ~docs:section_support);
15401546
Odoc_error.(cmd, info ~docs:section_support);
15411547
Odoc_html.targets ~docs:section_support;
1542-
Odoc_html.targets_impl ~docs:section_support;
1548+
Odoc_html.targets_source ~docs:section_support;
15431549
Odoc_manpage.targets ~docs:section_support;
15441550
Odoc_latex.targets ~docs:section_support;
15451551
Depends.Compile.(cmd, info ~docs:section_support);

src/odoc/rendering.ml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ let generate_odoc ~syntax ~warnings_options ~renderer ~output ~extra_suffix
9696
docs;
9797
Ok ()
9898

99-
let documents_of_implementation ~warnings_options:_ ~syntax impl source =
100-
match (source, impl.Lang.Implementation.id) with
101-
| Some source_file, Some _ -> (
99+
let documents_of_implementation ~warnings_options:_ ~syntax impl source_file =
100+
match impl.Lang.Implementation.id with
101+
| Some _ -> (
102102
match Fs.File.read source_file with
103103
| Error (`Msg msg) ->
104104
Error (`Msg (Format.sprintf "Couldn't load source file: %s" msg))
@@ -111,16 +111,11 @@ let documents_of_implementation ~warnings_options:_ ~syntax impl source =
111111
syntax_info source_code
112112
in
113113
Ok rendered)
114-
| _, None ->
114+
| None ->
115115
Error (`Msg "The implementation unit was not compiled with --source-id.")
116-
| None, _ ->
117-
Error
118-
(`Msg
119-
"--source should be passed when generating documents for an \
120-
implementation.")
121116

122-
let generate_impl_odoc ~syntax ~warnings_options ~renderer ~output ~source_file
123-
~extra_suffix extra file =
117+
let generate_source_odoc ~syntax ~warnings_options ~renderer ~output
118+
~source_file ~extra_suffix extra file =
124119
Odoc_file.load file >>= fun unit ->
125120
match unit.content with
126121
| Odoc_file.Impl_content impl ->
@@ -151,7 +146,7 @@ let targets_odoc ~resolver ~warnings_options ~syntax ~renderer ~output:root_dir
151146
docs;
152147
Ok ()
153148

154-
let targets_impl_odoc ~syntax ~warnings_options ~renderer ~output:root_dir
149+
let targets_source_odoc ~syntax ~warnings_options ~renderer ~output:root_dir
155150
~extra ~source_file odoctree =
156151
Odoc_file.load odoctree >>= fun unit ->
157152
match unit.content with

src/odoc/rendering.mli

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ val generate_odoc :
2222
Fpath.t ->
2323
(unit, [> msg ]) result
2424

25-
val generate_impl_odoc :
25+
val generate_source_odoc :
2626
syntax:Renderer.syntax ->
2727
warnings_options:Odoc_model.Error.warnings_options ->
2828
renderer:'a Renderer.t ->
2929
output:Fs.directory ->
30-
source_file:Fpath.t option ->
30+
source_file:Fpath.t ->
3131
extra_suffix:string option ->
3232
'a ->
3333
Fpath.t ->
@@ -43,12 +43,12 @@ val targets_odoc :
4343
Fpath.t ->
4444
(unit, [> msg ]) result
4545

46-
val targets_impl_odoc :
46+
val targets_source_odoc :
4747
syntax:Renderer.syntax ->
4848
warnings_options:Odoc_model.Error.warnings_options ->
4949
renderer:'a Renderer.t ->
5050
output:Fs.directory ->
5151
extra:'a ->
52-
source_file:Fpath.t option ->
52+
source_file:Fpath.t ->
5353
Fs.file ->
5454
(unit, [> Or_error.msg ]) result

test/integration/json_expansion_with_sources.t/run.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ Test the JSON output in the presence of expanded modules.
2323
html/Main/index.html.json
2424
html/Main/A/index.html.json
2525
html/Main/A/B/index.html.json
26-
$ odoc html-targets-impl --source a.ml -o html impl-main__A.odocl
26+
$ odoc html-targets-source --impl impl-main__A.odocl -o html a.ml
2727
html/src/a.ml.html
28-
$ odoc html-targets-impl --source main.ml -o html impl-main.odocl
28+
$ odoc html-targets-source --impl impl-main.odocl -o html main.ml
2929
html/src/main.ml.html
30-
$ odoc html-targets-impl --source a.ml --as-json -o html impl-main__A.odocl
30+
$ odoc html-targets-source --impl impl-main__A.odocl --as-json -o html a.ml
3131
html/src/a.ml.html.json
32-
$ odoc html-targets-impl --source main.ml --as-json -o html impl-main.odocl
32+
$ odoc html-targets-source --impl impl-main.odocl --as-json -o html main.ml
3333
html/src/main.ml.html.json
3434

35-
$ odoc html-generate-impl --source a.ml --as-json -o html impl-main__A.odocl
35+
$ odoc html-generate-source --impl impl-main__A.odocl --as-json -o html a.ml
3636
$ odoc html-generate --as-json -o html main__A.odocl
37-
$ odoc html-generate-impl --source main.ml --as-json -o html impl-main.odocl
37+
$ odoc html-generate-source --impl impl-main.odocl --as-json -o html main.ml
3838
$ odoc html-generate --as-json -o html main.odocl
3939

4040
$ cat html/Main/index.html.json

test/sources/double_wrapped.t/run.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Similar to the lookup_def_wrapped test.
2020
$ odoc link -I . main__.odoc
2121

2222
$ odoc html-generate --indent -o html main.odocl
23-
$ odoc html-generate-impl --source main.ml --indent -o html impl-main.odocl
24-
$ odoc html-generate-impl --source a.ml --indent -o html impl-main__A.odocl
23+
$ odoc html-generate-source --impl impl-main.odocl --indent -o html main.ml
24+
$ odoc html-generate-source --impl impl-main__A.odocl --indent -o html a.ml
2525

2626
Look if all the source files are generated:
2727

test/sources/functor.t/run.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ Verify the behavior on functors.
1515
$ odoc link -I . impl-s.odoc
1616
$ odoc link -I . impl-a.odoc
1717
$ odoc link -I . impl-b.odoc
18-
$ odoc html-generate-impl --source s.ml --indent -o html impl-s.odocl
18+
$ odoc html-generate-source --impl impl-s.odocl --indent -o html s.ml
1919
$ odoc html-generate --indent -o html s.odocl
20-
$ odoc html-generate-impl --source a.ml --indent -o html impl-a.odocl
20+
$ odoc html-generate-source --impl impl-a.odocl --indent -o html a.ml
2121
$ odoc html-generate --indent -o html a.odocl
22-
$ odoc html-generate-impl --source b.ml --indent -o html impl-b.odocl
22+
$ odoc html-generate-source --impl impl-b.odocl --indent -o html b.ml
2323
$ odoc html-generate --indent -o html b.odocl
2424

2525
$ find html | sort

test/sources/include_in_expansion.t/run.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ Checking that source parents are kept, using include.
1818
$ odoc link -I . impl-main.odoc
1919
$ odoc link -I . impl-main__A.odoc
2020

21-
$ odoc html-generate-impl --source main.ml --indent -o html impl-main.odocl
21+
$ odoc html-generate-source --impl impl-main.odocl --indent -o html main.ml
2222
$ odoc html-generate --indent -o html main.odocl
23-
$ odoc html-generate-impl --source a.ml --hidden --indent -o html impl-main__A.odocl
23+
$ odoc html-generate-source --impl impl-main__A.odocl --hidden --indent -o html a.ml
2424
$ odoc html-generate --hidden --indent -o html main__A.odocl
2525

2626
In Main.A, the source parent of value x should be to Main__A, while the

test/sources/lookup_def_wrapped.t/run.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ It's a simpler case than Dune's wrapping.
2121
$ odoc link -I . impl-main.odoc
2222
$ odoc link -I . main.odoc
2323

24-
$ odoc html-generate-impl --source main.ml --indent -o html impl-main.odocl
24+
$ odoc html-generate-source --impl impl-main.odocl --indent -o html main.ml
2525
$ odoc html-generate --indent -o html main.odocl
26-
$ odoc html-generate-impl --source a.ml --indent -o html impl-main__A.odocl
26+
$ odoc html-generate-source --impl impl-main__A.odocl --indent -o html a.ml
2727
$ odoc html-generate --hidden --indent -o html main__A.odocl
28-
$ odoc html-generate-impl --source b.ml --indent -o html impl-main__B.odocl
28+
$ odoc html-generate-source --impl impl-main__B.odocl --indent -o html b.ml
2929
$ odoc html-generate --hidden --indent -o html main__B.odocl
3030

3131
Look if all the source files are generated:

test/sources/recursive_module.t/run.t

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Checking that source links exists inside recursive modules.
77
$ odoc link -I . main.odoc
88
$ odoc html-generate --indent -o html main.odocl
99
$ odoc html-generate-impl --source main.ml --indent -o html impl-main.odocl
10+
odoc: unknown command 'html-generate-impl', must be one of 'aggregate-occurrences', 'classify', 'compile', 'compile-asset', 'compile-deps', 'compile-impl', 'compile-index', 'compile-targets', 'count-occurrences', 'css', 'errors', 'html', 'html-deps', 'html-fragment', 'html-generate', 'html-generate-source', 'html-targets', 'html-targets-source', 'html-url', 'latex', 'latex-generate', 'latex-targets', 'latex-url', 'link', 'link-deps', 'man', 'man-generate', 'man-targets', 'support-files' or 'support-files-targets'.
11+
Usage: odoc [COMMAND] …
12+
Try 'odoc --help' for more information.
13+
[2]
1014

1115
Both modules should contain source links
1216

test/sources/single_mli.t/run.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ Similar to Astring library.
1414
$ odoc link -I . impl-a.odoc
1515
$ odoc link -I . a.odoc
1616

17-
$ odoc html-generate-impl --source a_x.ml --indent -o html impl-a_x.odocl
17+
$ odoc html-generate-source --impl impl-a_x.odocl --indent -o html a_x.ml
1818
$ odoc html-generate --indent -o html a_x.odocl
19-
$ odoc html-generate-impl --source a.ml --indent -o html impl-a.odocl
19+
$ odoc html-generate-source --impl impl-a.odocl --indent -o html a.ml
2020
$ odoc html-generate --indent -o html a.odocl
2121

2222
Look if all the source files are generated:

0 commit comments

Comments
 (0)