Skip to content

Commit

Permalink
wip bugfix of old flags
Browse files Browse the repository at this point in the history
  • Loading branch information
EmileTrotignon committed May 21, 2024
1 parent da4e756 commit b519ac0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
7 changes: 4 additions & 3 deletions src/odoc/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 _, _, _ ->
Expand Down
24 changes: 14 additions & 10 deletions src/odoc/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/odoc/compile.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 }


Expand Down
1 change: 1 addition & 0 deletions test/pages/assets.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 4 additions & 7 deletions test/pages/errors.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,30 @@ 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]

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.
Expand Down

0 comments on commit b519ac0

Please sign in to comment.