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

Hide private libraries in odoc listings #4945

Merged
merged 4 commits into from
Oct 10, 2021
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Unreleased
----------

- Do not list private libraries in package listings (#4945, fixes #4799,
@rgrinberg)

- Fix `foreign_stubs` inside a `tests` stanza. Previously, dune would crash
when this field was present (#4942, fix #4946, @rgrinberg)

Expand Down
63 changes: 31 additions & 32 deletions src/dune_rules/odoc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,11 @@ let odoc_include_flags ctx pkg requires =
(let open Resolve.O in
let+ libs = requires in
let paths =
libs
|> List.fold_left
~f:(fun paths lib ->
match Lib.Local.of_lib lib with
| None -> paths
| Some lib ->
Path.Set.add paths (Path.build (Paths.odocs ctx (Lib lib))))
~init:Path.Set.empty
List.fold_left libs ~init:Path.Set.empty ~f:(fun paths lib ->
match Lib.Local.of_lib lib with
| None -> paths
| Some lib ->
Path.Set.add paths (Path.build (Paths.odocs ctx (Lib lib))))
in
let paths =
match pkg with
Expand Down Expand Up @@ -357,8 +354,8 @@ let setup_toplevel_index_rule sctx =
| Some v -> sp {| <span class="version">%s</span>|} v
in
Some (sp "<li>%s%s</li>" link version_suffix))
|> String.concat ~sep:"\n "
in
let list_items = String.concat ~sep:"\n " list_items in
let html =
sp
{|<!DOCTYPE html>
Expand Down Expand Up @@ -586,13 +583,12 @@ let setup_package_aliases sctx (pkg : Package.t) =
let dir = Path.Build.append_source ctx.build_dir pkg_dir in
Alias.doc ~dir
in
Rules.Produce.Alias.add_deps alias
(Action_builder.deps
(Dep.html_alias ctx (Pkg name)
:: (libs_of_pkg sctx ~pkg:name
|> List.map ~f:(fun lib -> Dep.html_alias ctx (Lib lib)))
|> Dune_engine.Dep.Set.of_list_map ~f:(fun f -> Dune_engine.Dep.alias f)
))
Dep.html_alias ctx (Pkg name)
:: (libs_of_pkg sctx ~pkg:name
|> List.map ~f:(fun lib -> Dep.html_alias ctx (Lib lib)))
|> Dune_engine.Dep.Set.of_list_map ~f:(fun f -> Dune_engine.Dep.alias f)
|> Action_builder.deps
|> Rules.Produce.Alias.add_deps alias

let entry_modules_by_lib sctx lib =
let info = Lib.Local.info lib in
Expand All @@ -603,7 +599,12 @@ let entry_modules_by_lib sctx lib =
>>| Modules.entry_modules

let entry_modules sctx ~pkg =
let l = libs_of_pkg sctx ~pkg in
let l =
libs_of_pkg sctx ~pkg
|> List.filter ~f:(fun lib ->
Lib.Local.info lib |> Lib_info.status |> Lib_info.Status.is_private
|> not)
in
let+ l =
Memo.Build.parallel_map l ~f:(fun l ->
let+ m = entry_modules_by_lib sctx l in
Expand Down Expand Up @@ -665,9 +666,8 @@ let setup_package_odoc_rules_def =
if String.Map.mem mlds "index" then
Memo.Build.return mlds
else
let entry_modules = entry_modules ~pkg in
let gen_mld = Paths.gen_mld_dir ctx pkg ++ "index.mld" in
let* entry_modules = entry_modules sctx in
let* entry_modules = entry_modules sctx ~pkg in
let+ () =
add_rule sctx
(Action_builder.write_file gen_mld
Expand Down Expand Up @@ -696,19 +696,18 @@ let global_rules sctx =
setup_package_aliases sctx pkg)
in
let* action =
stanzas
|> Memo.Build.List.concat_map ~f:(fun (w : _ Dir_with_dune.t) ->
Memo.Build.List.filter_map w.data ~f:(function
| Dune_file.Library (l : Dune_file.Library.t) -> (
match l.visibility with
| Public _ -> Memo.Build.return None
| Private _ ->
let scope = SC.find_scope_by_dir sctx w.ctx_dir in
Library.best_name l
|> Lib.DB.find_even_when_hidden (Scope.libs scope)
>>| fun lib ->
Option.value_exn lib |> Lib.Local.of_lib_exn |> Option.some)
| _ -> Memo.Build.return None))
Memo.Build.List.concat_map stanzas ~f:(fun (w : _ Dir_with_dune.t) ->
Memo.Build.List.filter_map w.data ~f:(function
| Dune_file.Library (l : Dune_file.Library.t) -> (
match l.visibility with
| Public _ -> Memo.Build.return None
| Private _ ->
let scope = SC.find_scope_by_dir sctx w.ctx_dir in
Library.best_name l
|> Lib.DB.find_even_when_hidden (Scope.libs scope)
>>| fun lib ->
Option.value_exn lib |> Lib.Local.of_lib_exn |> Option.some)
| _ -> Memo.Build.return None))
>>| Dune_engine.Dep.Set.of_list_map ~f:(fun (lib : Lib.Local.t) ->
Lib lib |> Dep.html_alias ctx |> Dune_engine.Dep.alias)
in
Expand Down
2 changes: 2 additions & 0 deletions test/blackbox-tests/test-cases/dune
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
(subdir
odoc
(cram
;; XXX (package odoc) doesn't seem to work for some reason
(deps %{bin:odoc})
(enabled_if
(<> %{ocaml_version} 4.02.3))))

Expand Down
17 changes: 17 additions & 0 deletions test/blackbox-tests/test-cases/odoc/gh4799.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Private libraries attached to packages shouldn't be displayed in the index

$ cat <<EOF > dune-project
> (lang dune 3.0)
> (package (name foo))
> EOF

$ cat <<EOF > dune
> (library
> (name foo)
> (package foo))
> EOF
> touch foo.ml bar.ml

$ dune build @doc
$ cat _build/default/_doc/_mlds/foo/index.mld
{0 foo index}