From fcb70278c6209fce05b7ef68812d19cfc1e67e42 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sat, 15 Feb 2020 16:07:46 +0000 Subject: [PATCH] Fix creating dummy package Used in --external-libs-deps Signed-off-by: Rudi Grinberg --- src/dune/findlib/findlib.ml | 28 ++++++++++----- src/dune/findlib/findlib.mli | 2 +- src/dune/lib.ml | 2 +- .../external-lib-deps/github3143/run.t | 34 ++----------------- 4 files changed, 24 insertions(+), 42 deletions(-) diff --git a/src/dune/findlib/findlib.ml b/src/dune/findlib/findlib.ml index 6848e0b3cbc..318820feb4c 100644 --- a/src/dune/findlib/findlib.ml +++ b/src/dune/findlib/findlib.ml @@ -184,7 +184,7 @@ module Loader : sig val lookup_and_load : db -> Package.Name.t -> (Dune_package.t, Unavailable_reason.t) result - val dummy_package : db -> Package.Name.t -> Dune_package.t + val dummy_package : db -> Lib_name.t -> Dune_package.t end = struct module Findlib_package : sig type t = @@ -439,12 +439,22 @@ end = struct ~meta_file:(Path.of_string "") ~meta - let dummy_package db name = - load_builtin db - { name = Some (Lib_name.of_package_name name) - ; vars = String.Map.empty - ; subs = [] - } + let dummy_package db lib_name = + let pkg, names = Lib_name.split lib_name in + let top_lib = Lib_name.of_package_name pkg in + let dummy name subs = + { Meta.Simplified.name = Some name; vars = String.Map.empty; subs } + in + let subs : Meta.Simplified.t list = + let rec loop = function + | [] -> [] + | name :: names -> + [ dummy (Lib_name.of_string_exn ~loc:None name) (loop names) ] + in + loop names + in + let meta = dummy top_lib subs in + load_builtin db meta let lookup_and_load_one_dir db ~dir ~name = let meta_file = Path.relative dir meta_fn in @@ -493,8 +503,8 @@ end type t = db -let dummy_package t ~name = - let p = Loader.dummy_package t (Lib_name.package_name name) in +let dummy_lib t ~name = + let p = Loader.dummy_package t name in match Lib_name.Map.find_exn p.entries name with | Library lib -> lib | _ -> assert false diff --git a/src/dune/findlib/findlib.mli b/src/dune/findlib/findlib.mli index 1e130079f12..de64220a65b 100644 --- a/src/dune/findlib/findlib.mli +++ b/src/dune/findlib/findlib.mli @@ -47,7 +47,7 @@ val all_packages : t -> Dune_package.Entry.t list val all_broken_packages : t -> (Package.Name.t * exn) list (** A dummy package. This is used to implement [external-lib-deps] *) -val dummy_package : t -> name:Lib_name.t -> Dune_package.Lib.t +val dummy_lib : t -> name:Lib_name.t -> Dune_package.Lib.t module Config : sig type t diff --git a/src/dune/lib.ml b/src/dune/lib.ml index dd1600198b0..7c73088b057 100644 --- a/src/dune/lib.ml +++ b/src/dune/lib.ml @@ -1840,7 +1840,7 @@ module DB = struct | Invalid_dune_package why -> Invalid why | Not_found -> if external_lib_deps_mode then - let pkg = Findlib.dummy_package findlib ~name in + let pkg = Findlib.dummy_lib findlib ~name in Found (Dune_package.Lib.info pkg) else Not_found )) diff --git a/test/blackbox-tests/test-cases/external-lib-deps/github3143/run.t b/test/blackbox-tests/test-cases/external-lib-deps/github3143/run.t index 1d16c0ff803..2b4cbf68d1a 100644 --- a/test/blackbox-tests/test-cases/external-lib-deps/github3143/run.t +++ b/test/blackbox-tests/test-cases/external-lib-deps/github3143/run.t @@ -8,34 +8,6 @@ Reproduce #3143 > (libraries base doesnotexist.foo)) > EOF $ dune external-lib-deps @install - Internal error, please report upstream including the contents of _build/log. - Description: - ("Map.find_exn: failed to find key", - { key = "doesnotexist.foo"; keys = [ "doesnotexist" ] }) - Backtrace: - Raised at file "src/stdune/code_error.ml", line 9, characters 30-62 - Called from file "src/dune/findlib/findlib.ml", line 498, characters 8-44 - Called from file "src/dune/lib.ml", line 1843, characters 24-59 - Called from file "src/dune/lib.ml", line 1189, characters 10-25 - Called from file "src/dune/lib.ml", line 1203, characters 21-49 - Called from file "src/dune/lib.ml", line 1203, characters 21-49 - Called from file "src/dune/lib.ml", line 1181, characters 10-38 - Called from file "src/dune/lib.ml", line 1287, characters 25-76 - Called from file "list.ml", line 121, characters 24-34 - Called from file "src/dune/lib.ml", line 1269, characters 6-1023 - Called from file "src/dune/lib.ml" (inlined), line 1110, characters 9-75 - Called from file "src/dune/lib.ml", line 1109, characters 6-104 - Called from file "src/dune/lib.ml", line 1192, characters 12-42 - Called from file "src/dune/lib.ml", line 1851, characters 10-61 - Called from file "src/dune/super_context.ml", line 529, characters 18-56 - Called from file "src/dune/dir_with_dune.ml", line 23, characters 55-67 - Called from file "src/dune/super_context.ml", line 526, characters 6-692 - Called from file "src/dune/gen_rules.ml", line 412, characters 6-102 - Called from file "src/fiber/fiber.ml", line 102, characters 8-15 - - I must not segfault. Uncertainty is the mind-killer. Exceptions are - the little-death that brings total obliteration. I will fully express - my cases. Execution will pass over me and through me. And when it - has gone past, I will unwind the stack along its path. Where the - cases are handled there will be nothing. Only I will remain. - [1] + These are the external library dependencies in the default context: + - base + - doesnotexist.foo