Skip to content
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

Driver: New hierarchy #1236

Merged
merged 9 commits into from
Nov 8, 2024
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Odoc driver output.
_odoc
_html
_indexes
_mlds

# Dune output.
_build
Expand Down
2 changes: 1 addition & 1 deletion src/driver/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ let link : compiled list -> _ =
let pages = Odoc_unit.Pkg_args.compiled_pages c.pkg_args in
let includes = c.include_dirs in
Odoc.link ~input_file ~output_file ~includes ~libs ~docs:pages
~current_package:c.pkgname ()
?current_package:c.pkgname ()
in
match c.kind with
| `Intf { hidden = true; _ } ->
Expand Down
146 changes: 38 additions & 108 deletions src/driver/landing_pages.ml
Original file line number Diff line number Diff line change
@@ -1,129 +1,59 @@
open Packages
open Odoc_unit

let fpf = Format.fprintf

let make_unit ~odoc_dir ~odocl_dir ~mld_dir rel_path ~content
?(include_dirs = Fpath.Set.empty) ~pkgname ~pkg_args () =
let input_file = Fpath.(mld_dir // rel_path / "index.mld") in
let odoc_file = Fpath.(odoc_dir // rel_path / "page-index.odoc") in
let odocl_file = Fpath.(odocl_dir // rel_path / "page-index.odocl") in
let make_index ~dirs ~rel_dir ?index ~content () =
let { odoc_dir; odocl_dir; mld_dir; _ } = dirs in
let input_file = Fpath.(mld_dir // rel_dir / "index.mld") in
let odoc_file = Fpath.(odoc_dir // rel_dir / "page-index.odoc") in
let odocl_file = Fpath.(odocl_dir // rel_dir / "page-index.odocl") in
let parent_id = rel_dir |> Odoc.Id.of_fpath in
Util.with_out_to input_file (fun oc ->
fpf (Format.formatter_of_out_channel oc) "%t@?" content)
Format.fprintf (Format.formatter_of_out_channel oc) "%t@?" content)
|> Result.get_ok;
let parent_id = rel_path |> Odoc.Id.of_fpath in
{
output_dir = dirs.odoc_dir;
pkgname = None;
pkg_args = { Pkg_args.pages = []; libs = []; odoc_dir; odocl_dir };
parent_id;
input_file;
output_dir = odoc_dir;
odoc_file;
odocl_file;
pkg_args;
pkgname;
include_dirs;
index = None;
include_dirs = Fpath.Set.empty;
kind = `Mld;
index;
}

module PackageLanding = struct
let content pkg ppf =
fpf ppf "{0 %s}\n" pkg.name;
if not (List.is_empty pkg.mlds) then
fpf ppf
"{1 Documentation pages}@\n@\n{{!/%s/doc/index}Documentation for %s}@\n"
pkg.name pkg.name;
if not (List.is_empty pkg.libraries) then
fpf ppf "{1 Libraries}@\n@\n{{!/%s/lib/index}Libraries for %s}@\n"
pkg.name pkg.name

let page ~odoc_dir ~odocl_dir ~mld_dir ~pkg =
let content = content pkg in
let rel_path = pkg.pkg_dir in
let pages_rel = [ (pkg.name, rel_path) ] in
let pkg_args =
{ Pkg_args.pages = pages_rel; libs = []; odoc_dir; odocl_dir }
let library ~dirs ~pkg ~index lib =
let content ppf =
Format.fprintf ppf "{0 Library %s}@\n" lib.Packages.lib_name;
let print_module m =
if not m.Packages.m_hidden then
Format.fprintf ppf "- {!%s}@\n" m.Packages.m_name
in
make_unit ~odoc_dir ~odocl_dir ~mld_dir rel_path ~content ~pkgname:pkg.name
~pkg_args ()
end
List.iter print_module lib.modules
in
let rel_dir = lib_dir pkg lib in
make_index ~dirs ~rel_dir ~index ~content ()

let package ~dirs ~pkg ~index =
let content ppf =
Format.fprintf ppf "{0 %s}@\nUse sidebar to navigate." pkg.Packages.name
in
let rel_dir = doc_dir pkg in
make_index ~dirs ~rel_dir ~index ~content ()

module PackageList = struct
let package_list ~dirs all =
let content all ppf =
let sorted_packages =
all |> List.sort (fun n1 n2 -> String.compare n1.name n2.name)
all
|> List.sort (fun n1 n2 ->
String.compare n1.Packages.name n2.Packages.name)
in
fpf ppf "{0 List of all packages}@\n";
Format.fprintf ppf "{0 List of all packages}@\n";
let print_pkg pkg =
fpf ppf "- {{!/__driver/%s/index}%s}@\n" pkg.name pkg.name
Format.fprintf ppf "- {{:%s/index.html}%s}@\n" pkg.Packages.name pkg.name
in
List.iter print_pkg sorted_packages

let page ~mld_dir ~odoc_dir ~odocl_dir all =
let content = content all in
let rel_path = Fpath.v "./" in
let pkgname = "__driver" in
let pages_rel = [ (pkgname, rel_path) ] in
let pkg_args =
{ Pkg_args.pages = pages_rel; libs = []; odoc_dir; odocl_dir }
in
make_unit ~odoc_dir ~odocl_dir ~mld_dir ~content ~pkgname ~pkg_args rel_path
()
end

module LibraryLanding = struct
let content lib ppf =
fpf ppf "{0 %s}@\n" lib.lib_name;
let print_module m =
if not m.m_hidden then fpf ppf "- {!%s}@\n" m.Packages.m_name
in
List.iter print_module lib.modules

let page ~pkg ~odoc_dir ~odocl_dir ~mld_dir ~pkg_dir lib =
let content = content lib in
let rel_path = Fpath.(pkg_dir / "lib" / lib.lib_name) in
let pages_rel = [ (pkg.name, rel_path) ] in
let pkg_args =
{ Pkg_args.pages = pages_rel; libs = []; odocl_dir; odoc_dir }
in
let include_dirs = Fpath.Set.singleton Fpath.(odoc_dir // rel_path) in
make_unit ~odoc_dir ~odocl_dir ~mld_dir rel_path ~content ~pkgname:pkg.name
~include_dirs ~pkg_args ()
end

module PackageLibLanding = struct
let content pkg ppf =
fpf ppf "{0 %s}@\n" pkg.name;
let print_lib (lib : Packages.libty) =
fpf ppf "- {{!/%s/%s/index}%s}@\n" pkg.name lib.lib_name lib.lib_name
in
List.iter print_lib pkg.libraries

let page ~pkg ~odoc_dir ~odocl_dir ~mld_dir =
let content = content pkg in
let rel_path = Fpath.(pkg.pkg_dir / "lib") in
let pages_rel = [ (pkg.name, rel_path) ] in
let pkg_args =
{ Pkg_args.pages = pages_rel; libs = []; odoc_dir; odocl_dir }
in
make_unit ~odoc_dir ~odocl_dir ~mld_dir rel_path ~content ~pkgname:pkg.name
~pkg_args ()
end

let of_package ~mld_dir ~odoc_dir ~odocl_dir pkg =
let library_pages =
List.map
(LibraryLanding.page ~pkg ~odoc_dir ~odocl_dir ~mld_dir
~pkg_dir:pkg.pkg_dir)
pkg.libraries
in
let package_landing_page =
PackageLanding.page ~odoc_dir ~odocl_dir ~mld_dir ~pkg
in
let library_list_page =
PackageLibLanding.page ~odoc_dir ~odocl_dir ~mld_dir ~pkg
in
package_landing_page :: library_list_page :: library_pages

let of_packages ~mld_dir ~odoc_dir ~odocl_dir all =
PackageList.page ~mld_dir ~odoc_dir ~odocl_dir all
:: List.concat_map (of_package ~mld_dir ~odoc_dir ~odocl_dir) all
let content = content all in
let rel_dir = Fpath.v "./" in
make_index ~dirs ~rel_dir ~content ()
14 changes: 8 additions & 6 deletions src/driver/landing_pages.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
val of_packages :
mld_dir:Fpath.t ->
odoc_dir:Fpath.t ->
odocl_dir:Fpath.t ->
Packages.t list ->
[> `Mld ] Odoc_unit.unit list
open Odoc_unit

val library :
dirs:dirs -> pkg:Packages.t -> index:index -> Packages.libty -> mld unit

val package : dirs:dirs -> pkg:Packages.t -> index:index -> mld unit

val package_list : dirs:dirs -> Packages.t list -> mld unit
9 changes: 7 additions & 2 deletions src/driver/odoc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ let lib_args libs =
Cmd.empty libs

let link ?(ignore_output = false) ~input_file:file ?output_file ~includes ~docs
~libs ~current_package () =
~libs ?current_package () =
let open Cmd in
let output_file =
match output_file with Some f -> f | None -> Fpath.set_ext "odocl" file
Expand All @@ -124,9 +124,14 @@ let link ?(ignore_output = false) ~input_file:file ?output_file ~includes ~docs
in
let docs = doc_args docs in
let libs = lib_args libs in
let current_package =
match current_package with
| None -> Cmd.empty
| Some c -> Cmd.(v "--current-package" % c)
in
let cmd =
!odoc % "link" % p file % "-o" % p output_file %% includes %% docs %% libs
% "--current-package" % current_package % "--enable-missing-root-warning"
%% current_package % "--enable-missing-root-warning"
in
let cmd =
if Fpath.to_string file = "stdlib.odoc" then cmd % "--open=\"\"" else cmd
Expand Down
2 changes: 1 addition & 1 deletion src/driver/odoc.mli
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ val link :
includes:Fpath.set ->
docs:(string * Fpath.t) list ->
libs:(string * Fpath.t) list ->
current_package:string ->
?current_package:string ->
unit ->
unit

Expand Down
32 changes: 18 additions & 14 deletions src/driver/odoc_driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,9 @@ let remap_virtual_interfaces duplicate_hashes pkgs =
})
pkgs

let run libs verbose packages_dir odoc_dir odocl_dir html_dir stats nb_workers
odoc_bin voodoo package_name blessed dune_style compile_grep link_grep
generate_grep =
let run libs verbose packages_dir odoc_dir odocl_dir index_dir mld_dir html_dir
stats nb_workers odoc_bin voodoo package_name blessed dune_style
compile_grep link_grep generate_grep =
Option.iter (fun odoc_bin -> Odoc.odoc := Bos.Cmd.v odoc_bin) odoc_bin;
let _ = Voodoo.find_universe_and_version "foo" in
Eio_main.run @@ fun env ->
Expand Down Expand Up @@ -614,7 +614,7 @@ let run libs verbose packages_dir odoc_dir odocl_dir html_dir stats nb_workers
if voodoo then
match Util.StringMap.to_list all with
| [ (_, p) ] ->
let output_path = Fpath.(odoc_dir // p.pkg_dir / "doc") in
let output_path = Fpath.(odoc_dir // p.pkg_dir) in
Some output_path
| _ -> failwith "Error, expecting singleton library in voodoo mode"
else None
Expand All @@ -624,16 +624,11 @@ let run libs verbose packages_dir odoc_dir odocl_dir html_dir stats nb_workers
(fun () ->
let all =
let all = Util.StringMap.bindings all |> List.map snd in
let internal =
Odoc_unit.of_packages ~odoc_dir ~odocl_dir ~index_dir:None
~extra_libs_paths all
in
let external_ =
let mld_dir = odoc_dir in
let dirs =
let odocl_dir = Option.value odocl_dir ~default:odoc_dir in
Landing_pages.of_packages ~mld_dir ~odoc_dir ~odocl_dir all
{ Odoc_unit.odoc_dir; odocl_dir; index_dir; mld_dir }
in
internal @ external_
Odoc_units_of.packages ~dirs ~extra_libs_paths all
in
Compile.init_stats all;
let compiled = Compile.compile ?partial ~partial_dir:odoc_dir all in
Expand Down Expand Up @@ -678,6 +673,14 @@ 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 index files go" in
Arg.(value & opt fpath_arg (Fpath.v "_indexes/") & info [ "index-dir" ] ~doc)

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

let html_dir =
let doc = "Directory in which the generated HTML files go" in
Arg.(value & opt fpath_arg (Fpath.v "_html/") & info [ "html-dir" ] ~doc)
Expand Down Expand Up @@ -741,8 +744,9 @@ let cmd =
Cmd.v info
Term.(
const run $ packages $ verbose $ packages_dir $ odoc_dir $ odocl_dir
$ html_dir $ stats $ nb_workers $ odoc_bin $ voodoo $ package_name
$ blessed $ dune_style $ compile_grep $ link_grep $ generate_grep)
$ index_dir $ mld_dir $ html_dir $ stats $ nb_workers $ odoc_bin $ voodoo
$ package_name $ blessed $ dune_style $ compile_grep $ link_grep
$ generate_grep)

(* let map = Ocamlfind.package_to_dir_map () in
let _dirs = List.map (fun lib -> List.assoc lib map) deps in
Expand Down
Loading
Loading