Skip to content

Commit

Permalink
refactor(pkg): unify concrete deps of local package
Browse files Browse the repository at this point in the history
the with/without versions just differ in error message, so they're easy
to unify

Signed-off-by: Rudi Grinberg <me@rgrinberg.com>

<!-- ps-id: 861bdf8a-6f35-4578-8f02-0ee0d3ef70bc -->
  • Loading branch information
rgrinberg committed May 15, 2024
1 parent 10c4c64 commit 2c004f3
Showing 1 changed file with 19 additions and 29 deletions.
48 changes: 19 additions & 29 deletions src/dune_pkg/package_universe.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,37 @@ let version_by_package_name local_packages (lock_dir : Lock_dir.t) =
])
;;

let concrete_dependencies_of_local_package_with_test t local_package_name =
let concrete_dependencies_of_local_package t local_package_name ~with_test =
let local_package = Package_name.Map.find_exn t.local_packages local_package_name in
Local_package.(for_solver local_package |> For_solver.opam_filtered_dependency_formula)
|> Resolve_opam_formula.filtered_formula_to_package_names
~with_test:true
~with_test
(Solver_env.to_env t.solver_env)
t.version_by_package_name
|> Result.map_error ~f:(function
| `Formula_could_not_be_satisfied unsatisfied_formula_hints ->
let hints = if with_test then None else Some lockdir_regenerate_hints in
User_message.make
~hints:lockdir_regenerate_hints
?hints
~loc:local_package.loc
(Pp.textf
"The dependencies of local package %S could not be satisfied from the lockdir:"
"The dependencies of local package %S could not be satisfied from the lockdir%s:"
(Package_name.to_string local_package.name)
(if with_test
then ""
else " when the solver variable 'with_test' is set to 'false'")
:: List.map
unsatisfied_formula_hints
~f:Resolve_opam_formula.Unsatisfied_formula_hint.pp))
|> Result.map ~f:Package_name.Set.of_list
;;
let all_non_local_dependencies_of_local_packages t =
let open Result.O in
let+ all_dependencies_of_local_packages =
Package_name.Map.keys t.local_packages
|> Result.List.map ~f:(concrete_dependencies_of_local_package_with_test t)
|> Result.List.map ~f:(fun p ->
concrete_dependencies_of_local_package ~with_test:true t p
|> Result.map ~f:Package_name.Set.of_list)
|> Result.map ~f:Package_name.Set.union_all
in
Package_name.Set.diff
Expand Down Expand Up @@ -205,31 +210,14 @@ let create local_packages lock_dir =
t
;;
let concrete_dependencies_of_local_package_without_test t local_package_name =
let local_package = Package_name.Map.find_exn t.local_packages local_package_name in
Local_package.(for_solver local_package |> For_solver.opam_filtered_dependency_formula)
|> Resolve_opam_formula.filtered_formula_to_package_names
~with_test:false
(Solver_env.to_env t.solver_env)
t.version_by_package_name
|> function
| Ok x -> x
| Error (`Formula_could_not_be_satisfied hints) ->
User_error.raise
(Pp.textf
"Unable to find dependencies of package %S in lockdir when the solver variable \
'with_test' is set to 'false':"
(Package_name.to_string local_package.name)
:: List.map hints ~f:Resolve_opam_formula.Unsatisfied_formula_hint.pp)
;;
let local_transitive_dependency_closure_without_test =
let module Top_closure = Top_closure.Make (Package_name.Set) (Monad.Id) in
fun t start ->
match
Top_closure.top_closure
~deps:(fun a ->
concrete_dependencies_of_local_package_without_test t a
concrete_dependencies_of_local_package t a ~with_test:false
|> User_error.ok_exn
|> List.filter ~f:(Package_name.Map.mem t.local_packages))
~key:Fun.id
start
Expand All @@ -251,7 +239,8 @@ let transitive_dependency_closure_without_test t start =
|> Package_name.Set.to_list
|> Package_name.Set.union_map ~f:(fun name ->
let all_deps =
concrete_dependencies_of_local_package_without_test t name
concrete_dependencies_of_local_package t name ~with_test:false
|> User_error.ok_exn
|> Package_name.Set.of_list
in
Package_name.Set.diff all_deps local_package_names)
Expand Down Expand Up @@ -295,8 +284,8 @@ let check_contains_package t package_name =
let all_dependencies t package ~traverse =
check_contains_package t package;
let immediate_deps =
match concrete_dependencies_of_local_package_with_test t package with
| Ok x -> x
match concrete_dependencies_of_local_package t package ~with_test:true with
| Ok x -> Package_name.Set.of_list x
| Error e ->
Code_error.raise
"Invalid package universe which should have already been validated"
Expand All @@ -313,7 +302,8 @@ let non_test_dependencies t package ~traverse =
check_contains_package t package;
match traverse with
| `Immediate ->
concrete_dependencies_of_local_package_without_test t package
concrete_dependencies_of_local_package t package ~with_test:false
|> User_error.ok_exn
|> Package_name.Set.of_list
| `Transitive ->
let closure =
Expand Down

0 comments on commit 2c004f3

Please sign in to comment.