From 877dbbed6e90924aa7da25990516861050241451 Mon Sep 17 00:00:00 2001 From: Etienne Marais Date: Wed, 6 Nov 2024 18:27:28 +0100 Subject: [PATCH] feat: use pkg-install to build the deps Attached it to the workspace. Signed-off-by: Etienne Marais --- src/dune_rules/alias0.ml | 2 +- src/dune_rules/alias0.mli | 2 +- src/dune_rules/gen_rules.ml | 11 +++++++++++ src/dune_rules/pkg_rules.ml | 27 +++++++++++++++++++++------ src/dune_rules/pkg_rules.mli | 3 +++ 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/dune_rules/alias0.ml b/src/dune_rules/alias0.ml index b4f5e5e4a30..6bbea99ff38 100644 --- a/src/dune_rules/alias0.ml +++ b/src/dune_rules/alias0.ml @@ -25,5 +25,5 @@ let check = standard "check" let install = standard "install" let ocaml_index = standard "ocaml-index" let runtest = standard "runtest" -let pkg_deps = standard "pkg-deps" +let pkg_install = standard "pkg-install" let all = standard "all" diff --git a/src/dune_rules/alias0.mli b/src/dune_rules/alias0.mli index a0d3b296a79..448b1e9becf 100644 --- a/src/dune_rules/alias0.mli +++ b/src/dune_rules/alias0.mli @@ -14,7 +14,7 @@ val check : Name.t val ocaml_index : Name.t val install : Name.t val runtest : Name.t -val pkg_deps : Name.t +val pkg_install : Name.t val all : Name.t val is_standard : Name.t -> bool val register_as_standard : Name.t -> unit diff --git a/src/dune_rules/gen_rules.ml b/src/dune_rules/gen_rules.ml index 0c98ce1287e..b379423a893 100644 --- a/src/dune_rules/gen_rules.ml +++ b/src/dune_rules/gen_rules.ml @@ -355,6 +355,17 @@ let gen_project_rules = and+ () = Odoc.gen_project_rules sctx project and+ () = Odoc_new.gen_project_rules sctx project and+ () = Ocaml_index.project_rule sctx project + and+ () = + let ctx = Super_context.context sctx in + let ctx_name = Context.name ctx in + let* is_lock_dir_active = Lock_dir.lock_dir_active ctx_name in + if is_lock_dir_active + then ( + let dir = + Path.Build.append_source (Context.build_dir ctx) @@ Dune_project.root project + in + Pkg_rules.gen_rule_from_universe ~dir ctx_name) + else Memo.return () and+ () = let version = 2, 8 in match Dune_project.allow_approximate_merlin project with diff --git a/src/dune_rules/pkg_rules.ml b/src/dune_rules/pkg_rules.ml index a6b456f4a6a..ecdf19fd997 100644 --- a/src/dune_rules/pkg_rules.ml +++ b/src/dune_rules/pkg_rules.ml @@ -1937,14 +1937,29 @@ let build_rule context_name ~source_deps (pkg : Pkg.t) = ~directory_targets:[ pkg.write_paths.target_dir ] ;; -let gen_package_alias_rules ~dir source_deps = - let alias = Alias.make Alias0.pkg_deps ~dir in - Action_builder.deps source_deps |> Rules.Produce.Alias.add_deps alias +let gen_rule_from_universe ~dir ctx_name = + let to_target_path pkg = + let pkg_name = Dune_lang.Package_name.to_string pkg in + let path = + Path.Build.L.relative + Private_context.t.build_dir + [ Context_name.to_string ctx_name; ".pkg"; pkg_name; "target" ] + |> Path.build + in + path + in + let* packages = + Package_universe.lock_dir (Project_dependencies ctx_name) + >>| (fun lock_dir -> lock_dir.packages) + >>| Dune_lang.Package_name.Map.keys + in + let alias = Alias.make Alias0.pkg_install ~dir in + let package_targets = List.map ~f:to_target_path packages in + Action_builder.paths package_targets |> Rules.Produce.Alias.add_deps alias ;; -let gen_rules ~dir context_name (pkg : Pkg.t) = +let gen_rules context_name (pkg : Pkg.t) = let* source_deps, copy_rules = source_rules pkg in - let* () = gen_package_alias_rules ~dir source_deps in let* () = copy_rules and* build_rule = build_rule context_name pkg ~source_deps in rule ~loc:Loc.none (* TODO *) build_rule @@ -1986,7 +2001,7 @@ let setup_package_rules ~package_universe ~dir ~pkg_name : Gen_rules.result Memo Gen_rules.Build_only_sub_dirs.singleton ~dir Subdir_set.empty in let context_name = Package_universe.context_name package_universe in - let rules = Rules.collect_unit (fun () -> gen_rules ~dir context_name pkg) in + let rules = Rules.collect_unit (fun () -> gen_rules context_name pkg) in Gen_rules.make ~directory_targets ~build_dir_only_sub_dirs rules ;; diff --git a/src/dune_rules/pkg_rules.mli b/src/dune_rules/pkg_rules.mli index 546503d698d..bc108d4b2e1 100644 --- a/src/dune_rules/pkg_rules.mli +++ b/src/dune_rules/pkg_rules.mli @@ -22,3 +22,6 @@ val which : Context_name.t -> (Filename.t -> Path.t option Memo.t) Staged.t val exported_env : Context_name.t -> Env.t Memo.t val ocamlpath : Context_name.t -> Path.t list Memo.t val find_package : Context_name.t -> Package.Name.t -> unit Action_builder.t option Memo.t + +(** TODO: Give me a better description. *) +val gen_rule_from_universe : dir:Path.Build.t -> Context_name.t -> unit Memo.t