Skip to content

Commit

Permalink
Merge pull request #5471 from rjbou/pin-depends-test
Browse files Browse the repository at this point in the history
lock: fix pin-depends with `with-` variables
  • Loading branch information
rjbou authored Feb 21, 2025
2 parents 4cde2e8 + c6afba3 commit 380cbb3
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ users)
* Check that the repositories given to `opam repository remove` actually exist [#5014 @kit-ty-kate - fixes #5012]

## Lock
* [BUG] Fix `pin-depends` for `with-*` dependencies [#5471 @rjbou - fix #5428]

## Clean

Expand Down
16 changes: 14 additions & 2 deletions src/client/opamLockCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,20 @@ let lock_opam ?(only_direct=false) st opam =
(OpamPackage.Name.Set.elements uninstalled_depopts))
in
let pin_depends =
let pin_depends =
let is_pin nv = OpamSwitchState.is_pinned st nv.name in
let pins map set =
OpamPackage.Map.fold (fun nv _ set ->
if is_pin nv then OpamPackage.Set.add nv set else set)
map set
in
OpamPackage.Set.filter is_pin all_depends
|> pins dev_depends_map
|> pins test_depends_map
|> pins doc_depends_map
|> pins dev_setup_depends_map
in
OpamPackage.Set.fold (fun nv acc ->
if not (OpamSwitchState.is_pinned st nv.name) then acc else
match OpamSwitchState.primary_url st nv with
| None -> acc
| Some u ->
Expand All @@ -296,7 +308,7 @@ let lock_opam ?(only_direct=false) st opam =
| None -> local_warn ())
| _ -> local_warn ())
| None -> (nv, u) :: acc)
all_depends []
pin_depends []
|> List.rev
in
opam
Expand Down
83 changes: 83 additions & 0 deletions tests/reftests/lock.test
Original file line number Diff line number Diff line change
Expand Up @@ -1235,3 +1235,86 @@ available: opam-version >= "2.1"
url {
}
x-locked: "locked"
### : Pin depends :
### rm -r tolock
### opam switch create pin-depends --empty
### <pin:tolock/tolock.opam>
opam-version: "2.0"
depends: [
"foo"
"a-simple-dep"
"a-test-dep" {with-test}
"a-doc-dep" {with-doc}
]
build: [ "test" "-f" "content" ]
pin-depends: [
[ "a-simple-dep.dev" "git+https://github.com/dbuenzli/cmdliner#f239981642a" ]
[ "a-test-dep.dev" "git+https://github.com/dbuenzli/cmdliner#1de361182ab" ]
[ "a-doc-dep.dev" "git+https://github.com/dbuenzli/cmdliner#e8f8890fe48" ]
]
### <tolock/content>
it's here
### <pin:opam-file>
opam-version: "2.0"
version: "dev"
### OPAMEDITOR="cp -f ${BASEDIR}/opam-file"
### opam install ./tolock --with-test --with-doc
[NOTE] Package tolock does not exist in opam repositories registered in the current switch.
The following additional pinnings are required by tolock.dev:
- a-simple-dep.dev at git+https://github.com/dbuenzli/cmdliner#f239981642a
- a-test-dep.dev at git+https://github.com/dbuenzli/cmdliner#1de361182ab
- a-doc-dep.dev at git+https://github.com/dbuenzli/cmdliner#e8f8890fe48
Pin and install them? [Y/n] y
[NOTE] Package a-simple-dep does not exist in opam repositories registered in the current switch.
[a-simple-dep.dev] synchronised (no changes)
[NOTE] No package definition found for a-simple-dep.dev: please complete the template
You can edit this file again with "opam pin edit a-simple-dep", export it with "opam show a-simple-dep --raw"
a-simple-dep is now pinned to git+https://github.com/dbuenzli/cmdliner#f239981642a (version dev)
[NOTE] Package a-test-dep does not exist in opam repositories registered in the current switch.
[a-test-dep.dev] synchronised (no changes)
[NOTE] No package definition found for a-test-dep.dev: please complete the template
You can edit this file again with "opam pin edit a-test-dep", export it with "opam show a-test-dep --raw"
a-test-dep is now pinned to git+https://github.com/dbuenzli/cmdliner#1de361182ab (version dev)
[NOTE] Package a-doc-dep does not exist in opam repositories registered in the current switch.
[a-doc-dep.dev] synchronised (no changes)
[NOTE] No package definition found for a-doc-dep.dev: please complete the template
You can edit this file again with "opam pin edit a-doc-dep", export it with "opam show a-doc-dep --raw"
a-doc-dep is now pinned to git+https://github.com/dbuenzli/cmdliner#e8f8890fe48 (version dev)
tolock is now pinned to file://${BASEDIR}/tolock (version dev)
The following actions will be performed:
=== install 5 packages
- install a-doc-dep dev (pinned) [required by tolock]
- install a-simple-dep dev (pinned) [required by tolock]
- install a-test-dep dev (pinned) [required by tolock]
- install foo 2 [required by tolock]
- install tolock dev (pinned)

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> retrieved a-doc-dep.dev (no changes)
-> installed a-doc-dep.dev
-> retrieved a-simple-dep.dev (no changes)
-> installed a-simple-dep.dev
-> retrieved a-test-dep.dev (no changes)
-> installed a-test-dep.dev
-> installed foo.2
-> retrieved tolock.dev (file://${BASEDIR}/tolock)
-> installed tolock.dev
Done.
### opam lock tolock
Generated lock files for:
- tolock.dev: ${BASEDIR}/tolock.opam.locked
### opam-cat tolock.opam.locked
authors: "the testing team"
bug-reports: "https://nobug"
build: ["test" "-f" "content"]
depends: ["a-doc-dep" {= "dev" & with-doc} "a-simple-dep" {= "dev"} "a-test-dep" {= "dev" & with-test} "foo" {= "2"}]
description: "Two words."
dev-repo: "hg+https://[email protected]"
homepage: "egapemoh"
license: "MIT"
maintainer: "[email protected]"
name: "tolock"
opam-version: "2.0"
pin-depends: [["a-doc-dep.dev" "git+https://github.com/dbuenzli/cmdliner#e8f8890fe48"] ["a-simple-dep.dev" "git+https://github.com/dbuenzli/cmdliner#f239981642a"] ["a-test-dep.dev" "git+https://github.com/dbuenzli/cmdliner#1de361182ab"]]
synopsis: "A word"
version: "dev"

0 comments on commit 380cbb3

Please sign in to comment.