From dd6a23ec182fdbbfc07a3abe078dbf389d49e9b9 Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Fri, 10 Mar 2017 15:44:17 +0000 Subject: [PATCH] Fix #15 When there are no .opam files in parent directories, use the whole workspace as scope --- doc/manual.org | 6 +++--- src/lib_db.ml | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/doc/manual.org b/doc/manual.org index cd04c40f..74436b58 100644 --- a/doc/manual.org +++ b/doc/manual.org @@ -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 restricted to the sub-tree starting from the closest parent containing -a =.opam= file. Moreover, a sub-tree containing -=.opam= doesn' t inherit the internal names available in its -parent scope. +a =.opam= file, or the whole workspace if no such directory +exist. Moreover, a sub-tree containing =.opam= doesn' t +inherit the internal names available in its parent scope. The idea behing this rule is that public library names must be universally unique, but internal ones don't need to. In particular you diff --git a/src/lib_db.ml b/src/lib_db.ml index 7394316a..f647dbcc 100644 --- a/src/lib_db.ml +++ b/src/lib_db.ml @@ -16,6 +16,8 @@ let rec internal_name_scope t ~dir = match Hashtbl.find t.by_internal_name dir with | Some scope -> scope | 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 Hashtbl.add t.by_internal_name ~key:dir ~data:scope; scope @@ -98,8 +100,9 @@ let create findlib ~dirs_with_dot_opam_files internal_libraries = ; instalable_internal_libs = String_map.empty } in - (* Initializes the scopes *) - Path.Set.iter dirs_with_dot_opam_files ~f:(fun dir -> + (* Initializes the scopes, including [Path.root] so that when there are no .opam + 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 ~data:(ref String_map.empty)); List.iter internal_libraries ~f:(fun ((dir, lib) as internal) ->