Skip to content

Commit

Permalink
refactor: remove public_libs from artifacts (#8740)
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg authored Sep 23, 2023
1 parent 85a6b7e commit fa81f4e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 45 deletions.
22 changes: 2 additions & 20 deletions src/dune_rules/artifacts.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
10 changes: 1 addition & 9 deletions src/dune_rules/artifacts.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions src/dune_rules/artifacts_db.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;;
Expand Down
10 changes: 5 additions & 5 deletions src/dune_rules/expander.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/dune_rules/expander.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 13 additions & 7 deletions src/dune_rules/super_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fa81f4e

Please sign in to comment.