From fa81f4e3da077f261152d755bf0d90630f033234 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sat, 23 Sep 2023 08:27:59 +0100 Subject: [PATCH] refactor: remove public_libs from artifacts (#8740) Signed-off-by: Rudi Grinberg --- src/dune_rules/artifacts.ml | 22 ++-------------------- src/dune_rules/artifacts.mli | 10 +--------- src/dune_rules/artifacts_db.ml | 3 +-- src/dune_rules/expander.ml | 10 +++++----- src/dune_rules/expander.mli | 4 ++-- src/dune_rules/super_context.ml | 20 +++++++++++++------- 6 files changed, 24 insertions(+), 45 deletions(-) diff --git a/src/dune_rules/artifacts.ml b/src/dune_rules/artifacts.ml index 87668448807..b460f365aa8 100644 --- a/src/dune_rules/artifacts.ml +++ b/src/dune_rules/artifacts.ml @@ -79,25 +79,7 @@ module Bin = struct let create ~(context : Context.t) ~local_bins = { context; local_bins } end -module Public_libs = struct - type t = - { context : Context.t - ; public_libs : Lib.DB.t - } - - let create ~context ~public_libs = { context; public_libs } -end - -type t = - { public_libs : Public_libs.t - ; bin : Bin.t - } +type t = { bin : Bin.t } let bin t = t.bin -let public_libs t = t.public_libs - -let create (context : Context.t) ~public_libs ~local_bins = - { public_libs = Public_libs.create ~context ~public_libs - ; bin = Bin.create ~context ~local_bins - } -;; +let create (context : Context.t) ~local_bins = { bin = Bin.create ~context ~local_bins } diff --git a/src/dune_rules/artifacts.mli b/src/dune_rules/artifacts.mli index 7d66a6ada98..c3ae03fca8e 100644 --- a/src/dune_rules/artifacts.mli +++ b/src/dune_rules/artifacts.mli @@ -29,15 +29,7 @@ module Bin : sig val add_binaries : t -> dir:Path.Build.t -> File_binding.Expanded.t list -> t end -module Public_libs : sig - type t = - { context : Context.t - ; public_libs : Lib.DB.t - } -end - type t val bin : t -> Bin.t -val public_libs : t -> Public_libs.t -val create : Context.t -> public_libs:Lib.DB.t -> local_bins:Bin.Local.t Memo.Lazy.t -> t +val create : Context.t -> local_bins:Bin.Local.t Memo.Lazy.t -> t diff --git a/src/dune_rules/artifacts_db.ml b/src/dune_rules/artifacts_db.ml index c207abe945d..ff7c7dce5c9 100644 --- a/src/dune_rules/artifacts_db.ml +++ b/src/dune_rules/artifacts_db.ml @@ -99,13 +99,12 @@ let all = let artifacts = Memo.lazy_ @@ fun () -> - let* public_libs = Scope.DB.public_libs context in let+ stanzas = Only_packages.filtered_stanzas context in let local_bins = Memo.lazy_ ~name:"get_installed_binaries" (fun () -> get_installed_binaries ~context stanzas) in - Artifacts.create context ~public_libs ~local_bins + Artifacts.create context ~local_bins in Context.name context, artifacts) ;; diff --git a/src/dune_rules/expander.ml b/src/dune_rules/expander.ml index eda624ab7c2..445e0c934e2 100644 --- a/src/dune_rules/expander.ml +++ b/src/dune_rules/expander.ml @@ -48,8 +48,8 @@ type t = { dir : Path.Build.t ; env : Env.t ; local_env : string Action_builder.t Env.Var.Map.t - ; lib_artifacts : Artifacts.Public_libs.t - ; lib_artifacts_host : Artifacts.Public_libs.t + ; lib_artifacts : Lib.DB.t + ; lib_artifacts_host : Lib.DB.t ; bin_artifacts_host : Artifacts.Bin.t ; bindings : value Pform.Map.t ; scope : Scope.t @@ -274,9 +274,9 @@ let expand_read_macro ~dir ~source s ~read ~pack = With (Action_builder.of_memo read)) ;; -let file_of_lib { Artifacts.Public_libs.context; public_libs } ~loc ~lib ~file = +let file_of_lib db context ~loc ~lib ~file = let open Resolve.Memo.O in - let+ lib = Lib.DB.resolve public_libs (loc, lib) in + let+ lib = Lib.DB.resolve db (loc, lib) in let dir = let info = Lib.info lib in match Lib.is_local lib with @@ -330,7 +330,7 @@ let expand_lib_variable t source ~lib ~file ~lib_exec ~lib_private = ]) else ( let artifacts = if lib_exec then t.lib_artifacts_host else t.lib_artifacts in - file_of_lib artifacts ~loc ~lib ~file) + file_of_lib artifacts (Context.host t.context) ~loc ~lib ~file) in let p = let open Memo.O in diff --git a/src/dune_rules/expander.mli b/src/dune_rules/expander.mli index f4464655bd2..889d66dade1 100644 --- a/src/dune_rules/expander.mli +++ b/src/dune_rules/expander.mli @@ -13,8 +13,8 @@ val make_root -> scope_host:Scope.t -> context:Context.t -> env:Env.t - -> lib_artifacts:Artifacts.Public_libs.t - -> lib_artifacts_host:Artifacts.Public_libs.t + -> lib_artifacts:Lib.DB.t + -> lib_artifacts_host:Lib.DB.t -> bin_artifacts_host:Artifacts.Bin.t -> t diff --git a/src/dune_rules/super_context.ml b/src/dune_rules/super_context.ml index 6621fec3a63..055dbcd185c 100644 --- a/src/dune_rules/super_context.ml +++ b/src/dune_rules/super_context.ml @@ -488,25 +488,31 @@ let create ~(context : Context.t) ~(host : t option) ~packages ~stanzas = ~default_ocamlpath:(Context.default_ocamlpath context) ~stdlib:(Context.ocaml context).lib_config.stdlib_dir) in - let* artifacts = Artifacts_db.get context in + let public_libs = Scope.DB.public_libs context in + let artifacts = Artifacts_db.get context in let+ root_expander = - let* artifacts_host, context_host = + let artifacts_host, public_libs_host, context_host = match Context.for_host context with - | None -> Memo.return (artifacts, context) + | None -> artifacts, public_libs, context | Some host -> - let+ artifacts = Artifacts_db.get host in - artifacts, host + let artifacts = Artifacts_db.get host in + let public_libs = Scope.DB.public_libs host in + artifacts, public_libs, host in let+ scope = Scope.DB.find_by_dir (Context.build_dir context) + and+ public_libs = public_libs + and+ artifacts_host = artifacts_host + and+ public_libs_host = public_libs_host and+ scope_host = Scope.DB.find_by_dir (Context.build_dir context_host) in Expander.make_root ~scope ~scope_host ~context ~env:expander_env - ~lib_artifacts:(Artifacts.public_libs artifacts) + ~lib_artifacts:public_libs ~bin_artifacts_host:(Artifacts.bin artifacts_host) - ~lib_artifacts_host:(Artifacts.public_libs artifacts_host) + ~lib_artifacts_host:public_libs_host + and+ artifacts = artifacts and+ root_env = add_packages_env (Context.name context) ~base:expander_env stanzas packages in