Skip to content

Driver: Fix monorepo mode #1299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
### Changed

- Drop support for OCaml < 4.08 (@jonludlam, #1300)
- Added suport for overriding tmp directories in odoc_driver_monorepo
(@jonludlam, #1304)

### Fixed

- Fix bug causing stack overflow in odoc_driver_monorepo (@jonludlam, #1304)

# 3.0.0~beta1

Expand Down
47 changes: 10 additions & 37 deletions src/driver/bin/odoc_driver.ml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
(* Odoc driver *)
open Odoc_driver_lib

let with_dir dir pat f =
match dir with
| None -> Bos.OS.Dir.with_tmp pat f () |> Result.get_ok
| Some dir -> f dir ()

let run_inner ~odoc_dir ~odocl_dir ~index_dir ~mld_dir ~compile_grep ~link_grep
~generate_grep ~index_grep ~remap ~index_mld packages
{
Expand All @@ -17,7 +12,7 @@ let run_inner ~odoc_dir ~odocl_dir ~index_dir ~mld_dir ~compile_grep ~link_grep
odoc_md_bin;
generate_json;
_;
} =
} () =
Option.iter (fun odoc_bin -> Odoc.odoc := Bos.Cmd.v odoc_bin) odoc_bin;
Option.iter
(fun odoc_md_bin -> Odoc.odoc_md := Bos.Cmd.v odoc_md_bin)
Expand Down Expand Up @@ -135,38 +130,16 @@ let run_inner ~odoc_dir ~odocl_dir ~index_dir ~mld_dir ~compile_grep ~link_grep

if stats then Stats.bench_results html_dir

let run odoc_dir odocl_dir index_dir mld_dir compile_grep link_grep
generate_grep index_grep remap packages index_mld common () =
with_dir odoc_dir "odoc-%s" @@ fun odoc_dir () ->
with_dir odocl_dir "odocl-%s" @@ fun odocl_dir () ->
with_dir index_dir "index-%s" @@ fun index_dir () ->
with_dir mld_dir "mld-%s" @@ fun mld_dir () ->
let () =
run_inner ~odoc_dir ~odocl_dir ~index_dir ~mld_dir ~compile_grep ~link_grep
~generate_grep ~index_grep ~remap ~index_mld packages common
let run dirs compile_grep link_grep generate_grep index_grep remap packages
index_mld common : unit =
let fn =
run_inner ~compile_grep ~link_grep ~generate_grep ~index_grep ~remap
~index_mld packages common
in
()
Common_args.with_dirs dirs fn

open Cmdliner

let odoc_dir =
let doc = "Directory in which the intermediate odoc files go" in
Arg.(value & opt (some Common_args.fpath_arg) None & info [ "odoc-dir" ] ~doc)

let odocl_dir =
let doc = "Directory in which the intermediate odocl files go" in
Arg.(
value & opt (some Common_args.fpath_arg) None & info [ "odocl-dir" ] ~doc)

let index_dir =
let doc = "Directory in which the intermediate index files go" in
Arg.(
value & opt (some Common_args.fpath_arg) None & info [ "index-dir" ] ~doc)

let mld_dir =
let doc = "Directory in which the auto-generated mld files go" in
Arg.(value & opt (some Common_args.fpath_arg) None & info [ "mld-dir" ] ~doc)

let compile_grep =
let doc = "Show compile commands containing the string" in
Arg.(
Expand Down Expand Up @@ -212,10 +185,10 @@ let index_mld =
& info [ "index-mld" ] ~docv:"INDEX" ~doc)

let cmd_term =
let module A = Common_args in
Term.(
const run $ odoc_dir $ odocl_dir $ index_dir $ mld_dir $ compile_grep
$ link_grep $ generate_grep $ index_grep $ remap $ packages $ index_mld
$ Common_args.term $ const ())
const run $ A.dirs_term $ compile_grep $ link_grep $ generate_grep
$ index_grep $ remap $ packages $ index_mld $ Common_args.term)

let cmd =
let doc =
Expand Down
17 changes: 10 additions & 7 deletions src/driver/bin/odoc_driver_monorepo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

open Odoc_driver_lib

let run path extra_pkgs extra_libs
let real_run ~odoc_dir ~odocl_dir ~index_dir ~mld_dir path extra_pkgs extra_libs
{
Common_args.verbose;
html_dir;
Expand All @@ -16,16 +16,12 @@ let run path extra_pkgs extra_libs
odoc_md_bin;
generate_json;
_;
} =
} () =
Option.iter (fun odoc_bin -> Odoc.odoc := Bos.Cmd.v odoc_bin) odoc_bin;
Option.iter
(fun odoc_md_bin -> Odoc.odoc_md := Bos.Cmd.v odoc_md_bin)
odoc_md_bin;

let odoc_dir = Fpath.v "_odoc" in
let odocl_dir = Fpath.v "_odocl" in
let mld_dir = Fpath.v "_mld" in
let index_dir = Fpath.v "_index" in
let _ = Voodoo.find_universe_and_version "foo" in
Eio_main.run @@ fun env ->
Eio.Switch.run @@ fun sw ->
Expand Down Expand Up @@ -86,6 +82,10 @@ let run path extra_pkgs extra_libs

if stats then Stats.bench_results html_dir

let run dirs path extra_pkgs extra_libs common : unit =
let fn = real_run path extra_pkgs extra_libs common in
Common_args.with_dirs dirs fn

open Cmdliner

let path =
Expand All @@ -106,7 +106,10 @@ let extra_libs =
let cmd =
let doc = "Generate documentation from a dune monorepo" in
let info = Cmd.info "odoc_driver_monorepo" ~doc in
let module A = Common_args in
Cmd.v info
Term.(const run $ path $ extra_pkgs $ extra_libs $ Common_args.term)
Term.(
const run $ A.dirs_term $ path $ extra_pkgs $ extra_libs
$ Common_args.term)

let _ = exit (Cmd.eval cmd)
47 changes: 44 additions & 3 deletions src/driver/common_args.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ let generate_json =
Arg.(
value & flag & info [ "json-output" ] ~doc ~docs:Manpage.s_common_options)

let odoc_dir =
let doc = "Directory in which the intermediate odoc files go" in
Arg.(value & opt (some fpath_arg) None & info [ "odoc-dir" ] ~doc)

let odocl_dir =
let doc = "Directory in which the intermediate odocl files go" in
Arg.(value & opt (some fpath_arg) None & info [ "odocl-dir" ] ~doc)

let index_dir =
let doc = "Directory in which the intermediate index files go" in
Arg.(value & opt (some fpath_arg) None & info [ "index-dir" ] ~doc)

let mld_dir =
let doc = "Directory in which the auto-generated mld files go" in
Arg.(value & opt (some fpath_arg) None & info [ "mld-dir" ] ~doc)

type t = {
verbose : bool;
html_dir : Fpath.t;
Expand All @@ -56,10 +72,35 @@ type t = {
generate_json : bool;
}

type dirs = {
odoc_dir : Fpath.t option;
odocl_dir : Fpath.t option;
mld_dir : Fpath.t option;
index_dir : Fpath.t option;
}

let with_dirs dirs fn : unit =
let with_dir = Util.with_dir in
let { odoc_dir; odocl_dir; mld_dir; index_dir } = dirs in
with_dir odoc_dir "odoc-%s" @@ fun odoc_dir () ->
with_dir odocl_dir "odocl-%s" @@ fun odocl_dir () ->
with_dir index_dir "index-%s" @@ fun index_dir () ->
with_dir mld_dir "mld-%s" @@ fun mld_dir () ->
fn ~odoc_dir ~odocl_dir ~index_dir ~mld_dir ()

open Term

let ( let+ ) t f = const f $ t
let ( and+ ) a b = const (fun x y -> (x, y)) $ a $ b

let dirs_term =
let+ odoc_dir = odoc_dir
and+ odocl_dir = odocl_dir
and+ mld_dir = mld_dir
and+ index_dir = index_dir in
{ odoc_dir; odocl_dir; mld_dir; index_dir }

let term =
let open Term in
let ( let+ ) t f = const f $ t in
let ( and+ ) a b = const (fun x y -> (x, y)) $ a $ b in
let+ verbose = verbose
and+ html_dir = html_dir
and+ stats = stats
Expand Down
14 changes: 7 additions & 7 deletions src/driver/monorepo_style.ml
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ let of_dune_build dir ~extra_pkgs ~extra_libs =
let all_lib_deps =
List.fold_left
(fun acc (l : library) ->
Util.StringMap.add l.name
("stdlib"
:: List.filter_map
(fun uid -> Util.StringMap.find_opt uid uid_to_libname)
l.requires
|> Util.StringSet.of_list)
acc)
let libs =
List.filter_map
(fun uid -> Util.StringMap.find_opt uid uid_to_libname)
l.requires
in
let libs = if l.name = "stdlib" then libs else "stdlib" :: libs in
Util.StringMap.add l.name (libs |> Util.StringSet.of_list) acc)
Util.StringMap.empty (local_libs @ global_libs)
in

Expand Down
5 changes: 5 additions & 0 deletions src/driver/util.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ open Bos
module StringSet = Set.Make (String)
module StringMap = Map.Make (String)

let with_dir dir pat f =
match dir with
| None -> OS.Dir.with_tmp pat f () |> Result.get_ok
| Some dir -> f dir ()

let lines_of_channel ic =
let rec inner acc =
try
Expand Down