Skip to content

Commit

Permalink
Merge pull request #6125 from rjbou/fix-depsonly-root
Browse files Browse the repository at this point in the history
Fix regression: deps-only setting direct dependencies as root packages by default
  • Loading branch information
kit-ty-kate authored Jul 30, 2024
2 parents 590b7e7 + 5a324c1 commit 0ea9e2d
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 15 deletions.
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ users)
## Install
* Fix package name display for no agreement conflicts [#6055 @rjbou - fix #6030]
* Make fetching an archive from cache add missing symlinks [#6068 @kit-ty-kate - fix #6064]
* [BUG] Fix `opam install --deps-only` set direct dependencies as root packages [#6125 @rjbou]

## Build (package)
* ◈ Add `--verbose-on` option to enable verbose mode on specified package names [#5682 @desumn @rjbou]
Expand Down Expand Up @@ -141,6 +142,7 @@ users)
* env: Add a test for `build-env` overwrites build env opam environment variables [#5377 @rjbou]
* clean: Add to check cleaning of sources directories [#5474 @rjbou]
* Add reftest for `--verbose-on` option [#5682 @rjbou]
* Add a test for --deps-only setting direct dependencies as root packages [#6125 @rjbou]

### Engine

Expand Down
43 changes: 28 additions & 15 deletions src/client/opamClient.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2301,21 +2301,34 @@ let install_t t ?ask ?(ignore_conflicts=false) ?(depext_only=false)
(OpamSolution.install_depexts ~force_depext:true ~confirm:false t
(OpamSolver.all_packages solution)), None
else
let add_roots =
OpamStd.Option.map (function
| true ->
OpamPackage.Name.Set.union requested @@
OpamPackage.Name.Set.of_list (List.rev_map fst deps_atoms)
| false -> OpamPackage.Name.Set.empty)
add_to_roots
in
let t, res =
OpamSolution.apply ?ask t
~requested:packages
~print_requested:(print_requested requested formula)
?add_roots ~skip
~download_only ~assume_built solution in
t, Some (Success res)
let add_roots =
match add_to_roots, deps_only with
| (Some true | None), true ->
let pkgs_solution = OpamSolver.all_packages solution in
let requested_deps =
OpamPackage.Set.fold (fun nv acc ->
OpamFormula.Or
(OpamPackageVar.all_depends t (OpamSwitchState.opam t nv)
~depopts:false ~build:true ~post:false,
acc))
(OpamPackage.packages_of_names pkgs_solution requested)
(* solution contains 'deps-to-xxx' virtual packages
and requested is deps-to-xxx packages *)
OpamFormula.Empty
in
Some (OpamPackage.names_of_packages
(OpamFormula.packages pkgs_solution requested_deps))
| Some true, false -> Some requested
| Some false, _ -> Some OpamPackage.Name.Set.empty
| None, false -> None
in
let t, res =
OpamSolution.apply ?ask t
~requested:packages
~print_requested:(print_requested requested formula)
?add_roots ~skip
~download_only ~assume_built solution in
t, Some (Success res)
in
OpamStd.Option.iter (OpamSolution.check_solution t) solution;
t
Expand Down
120 changes: 120 additions & 0 deletions tests/reftests/deps-only.test
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,123 @@ depends: "foo"
conflicts: "bar"
### opam install d --deps-only
Nothing to do.
### :::: check if deps-only installed packages are set root ::::
### <pkg:roots1.1>
opam-version: "2.0"
### <pkg:roots2.1>
opam-version: "2.0"
depends: "roots1"
### <pkg:roots3.1>
opam-version: "2.0"
depends: "roots2"
### <pkg:stoor1.1>
opam-version: "2.0"
### <pkg:stoor2.1>
opam-version: "2.0"
depends: "stoor1"
### opam switch create roots --empty
### : deps of a package
### opam install roots3 --deps-only
The following actions will be performed:
=== install 2 packages
- install roots1 1 [required by roots2]
- install roots2 1 [required by roots3]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed roots1.1
-> installed roots2.1
Done.
### opam list --roots -s
roots2
### opam remove roots1
The following actions will be performed:
=== remove 2 packages
- remove roots1 1
- remove roots2 1 [uses roots1]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> removed roots2.1
-> removed roots1.1
Done.
### : deps for 2 package that depend on each other
### opam install roots3 roots2 --deps-only
The following actions will be performed:
=== install 1 package
- install roots1 1 [required by roots2]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed roots1.1
Done.
### opam list --roots -s
roots1
### opam remove roots1
The following actions will be performed:
=== remove 1 package
- remove roots1 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> removed roots1.1
Done.
### : deps for 2 package that depend on each other
### opam install roots3 stoor2 --deps-only | unordered
The following actions will be performed:
=== install 3 packages
- install roots1 1 [required by roots2]
- install roots2 1 [required by roots3]
- install stoor1 1 [required by stoor2]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed roots1.1
-> installed roots2.1
-> installed stoor1.1
Done.
### opam list --roots -s
roots2
stoor1
### opam remove roots1 stoor1 | unordered
The following actions will be performed:
=== remove 3 packages
- remove roots1 1
- remove roots2 1 [uses roots1]
- remove stoor1 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> removed roots2.1
-> removed roots1.1
-> removed stoor1.1
Done.
### : deps with explicite set-root
### opam install roots3 --deps-only --set-root
The following actions will be performed:
=== install 2 packages
- install roots1 1 [required by roots2]
- install roots2 1 [required by roots3]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed roots1.1
-> installed roots2.1
Done.
### opam list --roots -s
roots2
### opam remove roots1
The following actions will be performed:
=== remove 2 packages
- remove roots1 1
- remove roots2 1 [uses roots1]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> removed roots2.1
-> removed roots1.1
Done.
### : deps with explicit unset-root
### opam install roots3 --deps-only --unset-root
The following actions will be performed:
=== install 2 packages
- install roots1 1 [required by roots2]
- install roots2 1 [required by roots3]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed roots1.1
-> installed roots2.1
Done.
### opam list --roots -s

0 comments on commit 0ea9e2d

Please sign in to comment.