Skip to content

Commit

Permalink
Record the fact that odoc reads ODOC_SYNTAX
Browse files Browse the repository at this point in the history
This controls the syntax of the output.

Closes ocaml#1117

Signed-off-by: Etienne Millon <[email protected]>
  • Loading branch information
emillon committed Jul 26, 2022
1 parent ba17d11 commit 29f9a6e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/dune_rules/odoc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,18 @@ end = struct
let odoc_input t = t
end

let odoc sctx =
let run_odoc sctx =
let dir = (Super_context.context sctx).build_dir in
SC.resolve_program sctx ~dir "odoc" ~loc:None ~hint:"opam install odoc"
let open Memo.O in
let+ program =
SC.resolve_program sctx ~dir "odoc" ~loc:None ~hint:"opam install odoc"
in
let deps = Action_builder.env_var "ODOC_SYNTAX" in
let run ~dir args =
let open Action_builder.With_targets.O in
Action_builder.with_no_targets deps >>> Command.run ~dir program args
in
run

let odoc_base_flags sctx build_dir =
let open Memo.O in
Expand All @@ -216,12 +225,12 @@ let compile_module sctx ~obj_dir (m : Module.t) ~includes:(file_deps, iflags)
let+ () =
let* action_with_targets =
let doc_dir = Path.build (Obj_dir.odoc_dir obj_dir) in
let* odoc = odoc sctx in
let* run_odoc = run_odoc sctx in
let+ odoc_base_flags = odoc_base_flags sctx odoc_file in
let open Action_builder.With_targets.O in
Action_builder.with_no_targets file_deps
>>> Action_builder.with_no_targets (module_deps m ~obj_dir ~dep_graphs)
>>> Command.run ~dir:doc_dir odoc
>>> run_odoc ~dir:doc_dir
[ A "compile"
; odoc_base_flags
; A "-I"
Expand All @@ -241,11 +250,11 @@ let compile_mld sctx (m : Mld.t) ~includes ~doc_dir ~pkg =
let open Memo.O in
let odoc_file = Mld.odoc_file m ~doc_dir in
let odoc_input = Mld.odoc_input m in
let* odoc = odoc sctx in
let* run_odoc = run_odoc sctx in
let* odoc_base_flags = odoc_base_flags sctx odoc_input in
let+ () =
add_rule sctx
(Command.run ~dir:(Path.build doc_dir) odoc
(run_odoc ~dir:(Path.build doc_dir)
[ A "compile"
; odoc_base_flags
; Command.Args.dyn includes
Expand Down Expand Up @@ -281,14 +290,13 @@ let link_odoc_rules sctx (odoc_file : odoc_artefact) ~pkg ~requires =
let ctx = Super_context.context sctx in
let deps = Dep.deps ctx pkg requires in
let open Memo.O in
let* odoc = odoc sctx
let* run_odoc = run_odoc sctx
and* odoc_base_flags = odoc_base_flags sctx odoc_file.odoc_file in
add_rule sctx
(let open Action_builder.With_targets.O in
Action_builder.with_no_targets deps
>>> Command.run
>>> run_odoc
~dir:(Path.build (Paths.html_root ctx))
odoc
[ A "link"
; odoc_base_flags
; odoc_include_flags ctx pkg requires
Expand Down Expand Up @@ -339,7 +347,7 @@ let setup_html sctx (odoc_file : odoc_artefact) =
(odoc_file.html_dir, [ dummy ])
in
let open Memo.O in
let* odoc = odoc sctx in
let* run_odoc = run_odoc sctx in
add_rule sctx
(Action_builder.progn
(Action_builder.with_no_targets
Expand All @@ -349,9 +357,8 @@ let setup_html sctx (odoc_file : odoc_artefact) =
[ Action.Remove_tree to_remove
; Action.Mkdir (Path.build odoc_file.html_dir)
])))
:: Command.run
:: run_odoc
~dir:(Path.build (Paths.html_root ctx))
odoc
[ A "html-generate"
; A "-o"
; Path (Path.build (Paths.html_root ctx))
Expand All @@ -363,9 +370,9 @@ let setup_html sctx (odoc_file : odoc_artefact) =
let setup_css_rule sctx =
let open Memo.O in
let ctx = Super_context.context sctx in
let* odoc = odoc sctx in
let* run_odoc = run_odoc sctx in
add_rule sctx
(Command.run ~dir:(Path.build ctx.build_dir) odoc
(run_odoc ~dir:(Path.build ctx.build_dir)
[ A "support-files"
; A "-o"
; Path (Path.build (Paths.html_root ctx))
Expand Down
34 changes: 34 additions & 0 deletions test/blackbox-tests/test-cases/odoc/github1117.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
The rules that call odoc know that it is going to read the ODOC_SYNTAX
variable, and can rebuild as needed.

$ cat > dune-project << EOF
> (lang dune 1.1)
> (package (name l))
> EOF

$ cat > dune << EOF
> (library
> (public_name l))
> EOF

$ cat > l.ml << EOF
> module type X = sig end
> EOF

$ detect () {
> if grep -q '>sig<' $1 ; then
> echo it is ocaml
> elif grep -q '{ ... }' $1 ; then
> echo it is reason
> else
> echo it is unknown
> fi
> }

$ dune build @doc
$ detect _build/default/_doc/_html/l/L/index.html
it is ocaml

$ ODOC_SYNTAX=re dune build @doc
$ detect _build/default/_doc/_html/l/L/index.html
it is reason

0 comments on commit 29f9a6e

Please sign in to comment.