Skip to content

Commit 63894ba

Browse files
committed
Add a targets-impl command for implementations
1 parent f34ed8a commit 63894ba

File tree

4 files changed

+84
-20
lines changed

4 files changed

+84
-20
lines changed

src/odoc/bin/main.ml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,8 @@ 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
778+
777779
val generate : docs:string -> unit Term.t * Term.info
778780

779781
val generate_impl : docs:string -> unit Term.t * Term.info
@@ -936,6 +938,34 @@ end = struct
936938
end
937939

938940
let targets ~docs = Targets.(cmd, info ~docs)
941+
942+
module Targets_impl = struct
943+
let list_targets output_dir source_file extra odoc_file =
944+
let odoc_file = Fs.File.of_string odoc_file in
945+
let warnings_options =
946+
{ Odoc_model.Error.warn_error = false; print_warnings = false }
947+
in
948+
Rendering.targets_impl_odoc ~warnings_options ~syntax:OCaml
949+
~renderer:R.renderer ~output:output_dir ~extra ~source_file odoc_file
950+
951+
let source_file = Generate_impl.source_file
952+
953+
let cmd =
954+
Term.(
955+
const handle_error
956+
$ (const list_targets $ dst () $ source_file $ R.extra_args
957+
$ input_odocl))
958+
959+
let info ~docs =
960+
let doc =
961+
Format.sprintf
962+
"Print the files that would be generated by $(i,%s-generate)."
963+
R.renderer.name
964+
in
965+
Term.info (R.renderer.name ^ "-targets-impl") ~docs ~doc
966+
end
967+
968+
let targets_impl ~docs = Targets_impl.(cmd, info ~docs)
939969
end
940970

941971
module Odoc_latex_url : sig
@@ -1508,6 +1538,7 @@ let () =
15081538
Targets.Support_files.(cmd, info ~docs:section_support);
15091539
Odoc_error.(cmd, info ~docs:section_support);
15101540
Odoc_html.targets ~docs:section_support;
1541+
Odoc_html.targets_impl ~docs:section_support;
15111542
Odoc_manpage.targets ~docs:section_support;
15121543
Odoc_latex.targets ~docs:section_support;
15131544
Depends.Compile.(cmd, info ~docs:section_support);

src/odoc/rendering.ml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,38 @@ let targets_odoc ~resolver ~warnings_options ~syntax ~renderer ~output:root_dir
150150
Format.printf "%a\n" Fpath.pp filename))
151151
docs;
152152
Ok ()
153+
154+
let targets_impl_odoc ~syntax ~warnings_options ~renderer ~output:root_dir
155+
~extra ~source_file odoctree =
156+
Odoc_file.load odoctree >>= fun unit ->
157+
match unit.content with
158+
| Odoc_file.Impl_content impl ->
159+
documents_of_implementation ~warnings_options ~syntax impl source_file
160+
>>= fun docs ->
161+
List.iter
162+
(fun doc ->
163+
let pages = renderer.Renderer.render extra None doc in
164+
Renderer.traverse pages ~f:(fun filename _content ->
165+
let filename =
166+
Fpath.normalize @@ Fs.File.append root_dir filename
167+
in
168+
Format.printf "%a\n" Fpath.pp filename))
169+
docs;
170+
Ok ()
171+
| Page_content _ | Unit_content _ | Asset_content _ ->
172+
Error (`Msg "Expected an implementation unit")
173+
(* let docs = *)
174+
(* if Fpath.get_ext odoctree = ".odoc" then *)
175+
(* documents_of_input ~renderer ~extra ~resolver ~warnings_options ~syntax *)
176+
(* odoctree *)
177+
(* else documents_of_odocl ~warnings_options ~renderer ~extra ~syntax odoctree *)
178+
(* in *)
179+
(* docs >>= fun docs -> *)
180+
(* List.iter *)
181+
(* (fun doc -> *)
182+
(* let pages = renderer.Renderer.render extra None doc in *)
183+
(* Renderer.traverse pages ~f:(fun filename _content -> *)
184+
(* let filename = Fpath.normalize @@ Fs.File.append root_dir filename in *)
185+
(* Format.printf "%a\n" Fpath.pp filename)) *)
186+
(* docs; *)
187+
(* Ok () *)

src/odoc/rendering.mli

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,13 @@ val targets_odoc :
4242
extra:'a ->
4343
Fpath.t ->
4444
(unit, [> msg ]) result
45+
46+
val targets_impl_odoc :
47+
syntax:Renderer.syntax ->
48+
warnings_options:Odoc_model.Error.warnings_options ->
49+
renderer:'a Renderer.t ->
50+
output:Fs.directory ->
51+
extra:'a ->
52+
source_file:Fpath.t option ->
53+
Fs.file ->
54+
(unit, [> Or_error.msg ]) result

test/integration/json_expansion_with_sources.t/run.t

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,14 @@ 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 --source a.ml -o html impl-main__A.odocl
27-
odoc: unknown option '--source'.
28-
Usage: odoc html-targets [OPTION]… FILE.odocl
29-
Try 'odoc html-targets --help' or 'odoc --help' for more information.
30-
[2]
31-
$ odoc html-targets --source main.ml -o html impl-main.odocl
32-
odoc: unknown option '--source'.
33-
Usage: odoc html-targets [OPTION]… FILE.odocl
34-
Try 'odoc html-targets --help' or 'odoc --help' for more information.
35-
[2]
36-
$ odoc html-targets --source a.ml --as-json -o html impl-main__A.odocl
37-
odoc: unknown option '--source'.
38-
Usage: odoc html-targets [OPTION]… FILE.odocl
39-
Try 'odoc html-targets --help' or 'odoc --help' for more information.
40-
[2]
41-
$ odoc html-targets --source main.ml --as-json -o html impl-main.odocl
42-
odoc: unknown option '--source'.
43-
Usage: odoc html-targets [OPTION]… FILE.odocl
44-
Try 'odoc html-targets --help' or 'odoc --help' for more information.
45-
[2]
26+
$ odoc html-targets-impl --source a.ml -o html impl-main__A.odocl
27+
html/src/a.ml.html
28+
$ odoc html-targets-impl --source main.ml -o html impl-main.odocl
29+
html/src/main.ml.html
30+
$ odoc html-targets-impl --source a.ml --as-json -o html impl-main__A.odocl
31+
html/src/a.ml.html.json
32+
$ odoc html-targets-impl --source main.ml --as-json -o html impl-main.odocl
33+
html/src/main.ml.html.json
4634

4735
$ odoc html-generate-impl --source a.ml --as-json -o html impl-main__A.odocl
4836
$ odoc html-generate --as-json -o html main__A.odocl

0 commit comments

Comments
 (0)