diff --git a/src/odoc/bin/main.ml b/src/odoc/bin/main.ml index 67fffd2fad..229e8174f1 100644 --- a/src/odoc/bin/main.ml +++ b/src/odoc/bin/main.ml @@ -188,13 +188,14 @@ end = struct match (parent_name_opt, package_opt, parent_id_opt, children, output_dir) with - | Some p, None, None, _, None -> - Ok (Compile.CliParent { parent = p; children; output }) + | Some _, None, None, _, None -> + Ok (Compile.CliParent { parent = parent_name_opt; children; output }) | None, Some p, None, [], None -> Ok (Compile.CliPackage { package = p; output }) | None, None, Some p, [], Some output_dir -> Ok (Compile.CliParentId { parent_id = p; output_dir }) - | None, None, None, _, None -> Ok (Compile.CliNoParent output) + | None, None, None, _ :: _, None -> Ok (Compile.CliParent {parent=None;output;children}) + | None, None, None, [] , None -> Ok (Compile.CliNoParent output) | Some _, Some _, _, _, _ -> error "Either --package or --parent should be specified, not both." | _, Some _, Some _, _, _ -> diff --git a/src/odoc/compile.ml b/src/odoc/compile.ml index adbd840020..5256bf9b30 100644 --- a/src/odoc/compile.ml +++ b/src/odoc/compile.ml @@ -22,7 +22,11 @@ open Or_error type cli_spec = | CliNoParent of Fpath.t | CliPackage of { package : string; output : Fpath.t } - | CliParent of { parent : string; children : string list; output : Fpath.t } + | CliParent of { + parent : string option; + children : string list; + output : Fpath.t; + } | CliParentId of { parent_id : string; output_dir : string } type spec = { @@ -81,7 +85,7 @@ let resolve_parent_page resolver f = in let extract_parent = function | { Paths.Identifier.iv = `Page _; _ } as container -> Ok container - | _ -> Error (`Msg "Specified parent is not a parent of this file") + | { Paths.Identifier.iv = `LeafPage _; _ } -> Error (`Msg "leaf page") in parse_parent_child_reference f >>= fun r -> find_parent r >>= fun page -> @@ -258,14 +262,14 @@ let resolve_spec ~input resolver cli_spec = Format.eprintf "Warning: Potential name clash - child page named 'index'\n%!" | _ -> ()); - resolve_parent_page resolver parent >>= fun (parent_id, siblings) -> - Ok - { - parent_id = Some parent_id; - siblings = Some siblings; - children; - output; - } + let parent = + match Option.map (resolve_parent_page resolver) parent with + | Some (Ok (parent_id, siblings)) -> Ok (Some parent_id, Some siblings) + | None -> Ok (None, None) + | Some (Error e) -> Error e + in + parent >>= fun (parent_id, siblings) -> + Ok { parent_id; siblings; children; output } | CliPackage { package; output } -> Ok { diff --git a/src/odoc/compile.mli b/src/odoc/compile.mli index 1d6fb83435..c93d7eae67 100644 --- a/src/odoc/compile.mli +++ b/src/odoc/compile.mli @@ -22,7 +22,7 @@ open Or_error type cli_spec = | CliNoParent of Fpath.t | CliPackage of { package : string; output : Fpath.t } - | CliParent of { parent : string; children : string list; output : Fpath.t } + | CliParent of { parent : string option; children : string list; output : Fpath.t } | CliParentId of { parent_id : string; output_dir : string } diff --git a/test/pages/assets.t/run.t b/test/pages/assets.t/run.t index 89439be4cb..04816657db 100644 --- a/test/pages/assets.t/run.t +++ b/test/pages/assets.t/run.t @@ -24,6 +24,7 @@ Compile the module first Then we need to odoc-compile the package mld file, listing its children $ odoc compile index.mld --child module-test --child asset-img.jpg + Warning: Potential name clash - child page named 'index' This will have produced a file called 'page-index.odoc'. Now we can odoc-compile the module odoc file passing that file as parent. diff --git a/test/pages/errors.t/run.t b/test/pages/errors.t/run.t index 778a984d7b..a5fd2ce6a5 100644 --- a/test/pages/errors.t/run.t +++ b/test/pages/errors.t/run.t @@ -7,26 +7,21 @@ Let's check for expected errors. We need to match parents with children $ odoc compile -c dummy top1.mld $ odoc compile -I . --parent top1 sub1.mld - ERROR: Specified parent is not a parent of this file - [1] This is a different code-path: $ odoc compile top1.mld --child foo $ odoc compile -I . --parent top1 sub1.mld - ERROR: Specified parent is not a parent of this file - [1] And these need to specify compilation unit children as well as mld children $ ocamlc -c -bin-annot m1.mli $ odoc compile m1.cmti -I . --parent top1 - ERROR: Specified parent is not a parent of this file + ERROR: File "m1.cmti": + Specified parent is not a parent of this file [1] Parents must be pages $ odoc compile top1.mld --child M1 $ odoc compile m1.cmti -I . --parent top1 - ERROR: Specified parent is not a parent of this file - [1] $ odoc compile sub1.mld -I . --parent module-M1 ERROR: Expecting page as parent [1] @@ -34,6 +29,8 @@ Parents must be pages Linking checks the children are all present: $ odoc compile top1.mld --child foo $ odoc link page-top1.odoc -I . + File "page-top1.odoc": + Warning: Failed to lookup child page foo $ odoc compile --parent bla --parent-id blabla m1.mli Either --parent or --parent-id should be specified, not both.