When there are no <pkg>.opam files in parent directories, use the
whole workspace as scope
This commit is contained in:
Jeremie Dimino 2017-03-10 15:44:17 +00:00
parent df7658914d
commit dd6a23ec18
2 changed files with 8 additions and 5 deletions

View File

@ -656,9 +656,9 @@ always prefered to ones that are part of the installed world.
The scope of internal library names is not the whole workspace. It is The scope of internal library names is not the whole workspace. It is
restricted to the sub-tree starting from the closest parent containing restricted to the sub-tree starting from the closest parent containing
a =<package>.opam= file. Moreover, a sub-tree containing a =<package>.opam= file, or the whole workspace if no such directory
=<package>.opam= doesn' t inherit the internal names available in its exist. Moreover, a sub-tree containing =<package>.opam= doesn' t
parent scope. inherit the internal names available in its parent scope.
The idea behing this rule is that public library names must be The idea behing this rule is that public library names must be
universally unique, but internal ones don't need to. In particular you universally unique, but internal ones don't need to. In particular you

View File

@ -16,6 +16,8 @@ let rec internal_name_scope t ~dir =
match Hashtbl.find t.by_internal_name dir with match Hashtbl.find t.by_internal_name dir with
| Some scope -> scope | Some scope -> scope
| None -> | None ->
(* [create] ensures that [Hashtbl.find t.by_internal_name Path.root] is [Some _] so
this [Path.parent dir] is never called with [Path.root] *)
let scope = internal_name_scope t ~dir:(Path.parent dir) in let scope = internal_name_scope t ~dir:(Path.parent dir) in
Hashtbl.add t.by_internal_name ~key:dir ~data:scope; Hashtbl.add t.by_internal_name ~key:dir ~data:scope;
scope scope
@ -98,8 +100,9 @@ let create findlib ~dirs_with_dot_opam_files internal_libraries =
; instalable_internal_libs = String_map.empty ; instalable_internal_libs = String_map.empty
} }
in in
(* Initializes the scopes *) (* Initializes the scopes, including [Path.root] so that when there are no <pkg>.opam
Path.Set.iter dirs_with_dot_opam_files ~f:(fun dir -> files in parent directories, the scope is the whole workspace. *)
Path.Set.iter (Path.add Path.root dirs_with_dot_opam_files) ~f:(fun dir ->
Hashtbl.add t.by_internal_name ~key:dir Hashtbl.add t.by_internal_name ~key:dir
~data:(ref String_map.empty)); ~data:(ref String_map.empty));
List.iter internal_libraries ~f:(fun ((dir, lib) as internal) -> List.iter internal_libraries ~f:(fun ((dir, lib) as internal) ->