Skip to content

Commit

Permalink
Follow-up from review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jonludlam committed Jan 16, 2025
1 parent 09d16f1 commit 4382f4c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/driver/bin/odoc_driver_monorepo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ let run path
(fun () ->
let units =
let dirs = { Odoc_unit.odoc_dir; odocl_dir; index_dir; mld_dir } in
Odoc_units_of.packages ~dirs ~indices_style:Odoc_units_of.Custom
Odoc_units_of.packages ~dirs ~indices_style:Odoc_units_of.Automatic
~extra_paths ~remap:false all
in
Compile.init_stats units;
Expand Down
39 changes: 20 additions & 19 deletions src/driver/monorepo_style.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
open Bos
open Sexplib.Std
[@@@warning "-69-30"]

let monorepo_pkg_name = "__pkg__"

let dune = ref (Cmd.v "dune")

type item = Library of library
Expand Down Expand Up @@ -31,7 +34,7 @@ and library_list = library list
and uid = string [@@deriving sexp]

(* Eurgh *)
let internal_name_of_library : library -> string option =
let internal_name_of_library : library -> (string * Fpath.t) option =
fun l ->
match l.modules with
| [] -> None
Expand All @@ -42,9 +45,11 @@ let internal_name_of_library : library -> string option =
| p :: _ -> (
let p' = Fpath.relativize ~root:(Fpath.v l.source_dir) (Fpath.v p) in
match Option.map Fpath.segs p' with
| Some (objdir :: _ :: _) -> (
| Some (objdir :: "byte" :: _) -> (
(* cmt files are expected to be in [library_path/.libname.objs/byte/name.cmt]. *)
match Astring.String.fields ~is_sep:(fun c -> c = '.') objdir with
| [ ""; libname; _ ] -> Some libname
| [ ""; libname; "objs" ] ->
Some (libname, Fpath.(parent (v p) |> rem_empty_seg))
| _ -> None)
| _ -> None))

Expand All @@ -71,6 +76,7 @@ let of_dune_build dir =
match contents with
| Error _ -> []
| Ok c ->
let cset = Fpath.Set.of_list c in
let libs = dune_describe dir in
let local_libs =
List.filter_map
Expand All @@ -87,8 +93,8 @@ let of_dune_build dir =
List.iter
(fun (lib : library) ->
Logs.debug (fun m ->
m "lib %s internal name: %a" lib.name
Fmt.(option string)
m "lib %s internal name: (%a)" lib.name
Fmt.(option (pair string Fpath.pp))
(internal_name_of_library lib)))
local_libs;
let uid_to_libname =
Expand All @@ -100,9 +106,10 @@ let of_dune_build dir =
List.fold_left
(fun acc (l : library) ->
Util.StringMap.add l.name
(List.filter_map
(fun uid -> Util.StringMap.find_opt uid uid_to_libname)
l.requires
("stdlib"
:: List.filter_map
(fun uid -> Util.StringMap.find_opt uid uid_to_libname)
l.requires
|> Util.StringSet.of_list)
acc)
Util.StringMap.empty local_libs
Expand All @@ -121,7 +128,7 @@ let of_dune_build dir =
| Library lib -> (
let libname_opt = internal_name_of_library lib in
match libname_opt with
| Some libname ->
| Some (libname, _) ->
let archive =
Fpath.(append dir (v lib.source_dir / libname))
in
Expand All @@ -137,14 +144,8 @@ let of_dune_build dir =
(fun (Library lib) ->
match internal_name_of_library lib with
| None -> None
| Some libname ->
let cmtidir =
Fpath.(
append dir
(v lib.source_dir
/ Printf.sprintf ".%s.objs" libname
/ "byte"))
in
| Some (_, cmtidir) ->
let cmtidir = Fpath.(append dir cmtidir) in
let id_override =
Fpath.relativize
~root:Fpath.(v "_build/default")
Expand All @@ -155,7 +156,7 @@ let of_dune_build dir =
m "this should never be 'None': %a"
Fmt.Dump.(option string)
id_override);
if List.mem cmtidir c then
if Fpath.Set.mem cmtidir cset then
Some
(Packages.Lib.v ~libname_of_archive ~pkg_name:lib.name
~dir:(Fpath.append dir (Fpath.v lib.source_dir))
Expand Down Expand Up @@ -186,7 +187,7 @@ let of_dune_build dir =
let local =
[
{
Packages.name = "pkg";
Packages.name = monorepo_pkg_name;
version = "1.0";
libraries = libs;
mlds;
Expand Down
2 changes: 2 additions & 0 deletions src/driver/monorepo_style.mli
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
val monorepo_pkg_name : string

val of_dune_build : Fpath.t -> Packages.t list
27 changes: 11 additions & 16 deletions src/driver/odoc_units_of.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
open Odoc_unit

type indices_style = Voodoo | Normal | Custom
type indices_style =
| Voodoo
| Normal
| Automatic

let packages ~dirs ~extra_paths ~remap ~indices_style (pkgs : Packages.t list) :
t list =
Expand Down Expand Up @@ -273,22 +276,14 @@ let packages ~dirs ~extra_paths ~remap ~indices_style (pkgs : Packages.t list) :
[ Landing_pages.src ~dirs ~pkg ~index ]
else []
in
let std_units = mld_units @ asset_units @ md_units @ lib_units in
match indices_style with
| Normal | Voodoo ->
List.concat
((pkg_index () :: src_index () :: lib_units)
@ mld_units @ asset_units @ md_units)
| Custom ->
if pkg.name = "pkg" then
let others :> t list =
Landing_pages.make_custom dirs index_of
(List.find (fun p -> p.Packages.name = "pkg") pkgs)
in
others @ List.concat (mld_units @ asset_units @ md_units @ lib_units)
else
List.concat
((pkg_index () :: src_index () :: lib_units)
@ mld_units @ asset_units @ md_units)
| Automatic when pkg.name = Monorepo_style.monorepo_pkg_name ->
let others :> t list = Landing_pages.make_custom dirs index_of (List.find (fun p -> p.Packages.name = Monorepo_style.monorepo_pkg_name) pkgs) in
others @ List.concat std_units
| Normal | Voodoo | Automatic ->
List.concat
(pkg_index () :: src_index () :: std_units)
in
if indices_style = Normal then
let gen_indices :> t = Landing_pages.package_list ~dirs ~remap pkgs in
Expand Down
2 changes: 1 addition & 1 deletion src/driver/odoc_units_of.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Odoc_unit

type indices_style = Voodoo | Normal | Custom
type indices_style = Voodoo | Normal | Automatic

val packages :
dirs:dirs ->
Expand Down
14 changes: 6 additions & 8 deletions src/markdown/doc_of_md.ml
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,12 @@ let rec link_reference_to_inline_element ~locator defs l m (is, warns) =
(text @ is, warns)
| Some ld ->
let replace_md_mdx s =
let root =
if String.ends_with ~suffix:".md" s then
String.sub s 0 (String.length s - 3)
else if String.ends_with ~suffix:".mdx" s then
String.sub s 0 (String.length s - 4)
else s
in
root ^ ".html"
let add_html x = x ^ ".html" in
if String.ends_with ~suffix:".md" s then
String.sub s 0 (String.length s - 3) |> add_html
else if String.ends_with ~suffix:".mdx" s then
String.sub s 0 (String.length s - 4) |> add_html
else s
in
let link =
match Link_definition.dest ld with
Expand Down

0 comments on commit 4382f4c

Please sign in to comment.