Skip to content

Commit 22d73a1

Browse files
committed
lock: add '--keep-local' argument to add local pins (unresolved ones) to 'pin-depends:' field
1 parent 4bd1a89 commit 22d73a1

File tree

5 files changed

+68
-8
lines changed

5 files changed

+68
-8
lines changed

master_changes.md

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ users)
8585

8686
## Lock
8787
* [BUG] Fix `pin-depends` for `with-*` dependencies [#5471 @rjbou - fix #5428]
88+
* [NEW] Add `--keep-local` to keep local pins url in `pin-depends` field [#6411 @rjbou - fix #4897]
8889

8990
## Clean
9091

@@ -225,6 +226,7 @@ users)
225226
* `OpamArg`: export `require_checksums` and `no_checksums`, that are shared with `build_options` [#5563 @rjbou]
226227
* `OpamArg.hash_kinds`: was added [#5960 @kit-ty-kate]
227228
* `OpamRepositoryCommand.switch_repos`: expose the function [#5014 @kit-ty-kate]
229+
* `OpamLockCommand.lock_opam`: add `~keep_local` argument to add local pins to pin-depends (and not resolve them) [#6411 @rjbou]
228230

229231
## opam-repository
230232
* `OpamDownload.get_output`: fix `wget` option for `POST` requests [#6036 @rjbou]

src/client/opamCommands.ml

+12-5
Original file line numberDiff line numberDiff line change
@@ -4392,9 +4392,10 @@ let lock cli =
43924392
fixed and the same filter is on all dependencies that are added from \
43934393
them";
43944394
`P "- $(i,pin-depends) are kept and new ones are added if in the \
4395-
dependencies some packages are pinned ";
4395+
dependencies some packages are pinned";
43964396
`P "- pins are resolved: if a package is locally pinned, opam tries to get \
4397-
its remote url and branch, and sets this as the target URL";
4397+
its remote url and branch, and sets this as the target URL; otherwise \
4398+
it ignore them. You can use $(i,--keep-local) to keep the local url.";
43984399
`S Manpage.s_arguments;
43994400
`S Manpage.s_options;
44004401
]
@@ -4404,7 +4405,11 @@ let lock cli =
44044405
"Only lock direct dependencies, rather than the whole dependency tree."
44054406
in
44064407
let lock_suffix = OpamArg.lock_suffix cli in
4407-
let lock global_options only_direct lock_suffix atom_locs () =
4408+
let keep_local_flag =
4409+
mk_flag ~cli (cli_from cli2_4) ["keep-local"]
4410+
"Do not discard local pins from pin-depends."
4411+
in
4412+
let lock global_options only_direct lock_suffix keep_local atom_locs () =
44084413
apply_global_options cli global_options;
44094414
OpamGlobalState.with_ `Lock_none @@ fun gt ->
44104415
OpamSwitchState.with_ `Lock_none gt @@ fun st ->
@@ -4420,7 +4425,9 @@ let lock cli =
44204425
let pkg_done =
44214426
OpamPackage.Set.fold (fun nv msgs ->
44224427
let opam = OpamSwitchState.opam st nv in
4423-
let locked = OpamLockCommand.lock_opam ~only_direct st opam in
4428+
let locked =
4429+
OpamLockCommand.lock_opam ~only_direct ~keep_local st opam
4430+
in
44244431
let locked_fname =
44254432
OpamFilename.add_extension
44264433
(OpamFilename.of_string (OpamPackage.name_to_string nv))
@@ -4443,7 +4450,7 @@ let lock cli =
44434450
in
44444451
mk_command ~cli (cli_from cli2_1) "lock" ~doc ~man
44454452
Term.(const lock $global_options cli $only_direct_flag $lock_suffix
4446-
$atom_or_local_list)
4453+
$keep_local_flag $atom_or_local_list)
44474454

44484455
(* HELP *)
44494456
let help =

src/client/opamLockCommand.ml

+6-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ let get_git_url url nv dir =
128128
(OpamPackage.to_string nv);
129129
None)
130130

131-
let lock_opam ?(only_direct=false) st opam =
131+
let lock_opam ?(only_direct=false) ~keep_local st opam =
132132
let nv = OpamFile.OPAM.package opam in
133133
(* Depends *)
134134
let all_depends =
@@ -292,6 +292,11 @@ let lock_opam ?(only_direct=false) st opam =
292292
| None -> acc
293293
| Some u ->
294294
match OpamUrl.local_dir u with
295+
| Some _ when keep_local ->
296+
OpamConsole.note
297+
"Dependency %s is pinned to local target %s, keeping it."
298+
(OpamPackage.to_string nv) (OpamUrl.to_string u);
299+
(nv, u) :: acc
295300
| Some d ->
296301
let local_warn () =
297302
OpamConsole.warning "Dependency %s is pinned to local target %s"

src/client/opamLockCommand.mli

+8-2
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,11 @@ val select_packages:
2121
[ `Atom of atom | `Filename of filename | `Dirname of dirname ] list ->
2222
'a switch_state -> 'a switch_state * package_set
2323

24-
(** Returns the locked opam file, according its depends, depopts, and pins. *)
25-
val lock_opam: ?only_direct:bool -> 'a switch_state -> OpamFile.OPAM.t -> OpamFile.OPAM.t
24+
(** Returns the locked opam file, according its depends, depopts, and pins.
25+
If [only_direct] is set to true, it only adds direct dependencies specified
26+
in the opam file. If [keep_local] is set to true, local pins that can not
27+
be resolved to a distant url are added with their local path in
28+
'pin_depends:' field. *)
29+
val lock_opam:
30+
?only_direct:bool -> keep_local:bool ->
31+
'a switch_state -> OpamFile.OPAM.t -> OpamFile.OPAM.t

tests/reftests/lock.test

+40
Original file line numberDiff line numberDiff line change
@@ -1318,3 +1318,43 @@ opam-version: "2.0"
13181318
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"]]
13191319
synopsis: "A word"
13201320
version: "dev"
1321+
### : Keep local pins as pin-depends
1322+
### <pin:local-one/local-one.opam>
1323+
opam-version: "2.0"
1324+
### <pin:local-two/local-two.opam>
1325+
opam-version: "2.0"
1326+
### <pkg:distant-x.1>
1327+
opam-version: "2.0"
1328+
depends: [ "local-one" "local-two" ]
1329+
### opam switch create locality --empty
1330+
### opam pin ./local-one -n
1331+
[NOTE] Package local-one does not exist in opam repositories registered in the current switch.
1332+
local-one is now pinned to file://${BASEDIR}/local-one (version dev)
1333+
### opam pin ./local-two -n
1334+
[NOTE] Package local-two does not exist in opam repositories registered in the current switch.
1335+
local-two is now pinned to file://${BASEDIR}/local-two (version dev)
1336+
### opam install distant-x
1337+
The following actions will be performed:
1338+
=== install 3 packages
1339+
- install distant-x 1
1340+
- install local-one dev (pinned) [required by distant-x]
1341+
- install local-two dev (pinned) [required by distant-x]
1342+
1343+
<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
1344+
-> retrieved local-one.dev (file://${BASEDIR}/local-one)
1345+
-> installed local-one.dev
1346+
-> retrieved local-two.dev (file://${BASEDIR}/local-two)
1347+
-> installed local-two.dev
1348+
-> installed distant-x.1
1349+
Done.
1350+
### opam lock distant-x --keep-local
1351+
[NOTE] Dependency local-one.dev is pinned to local target file://${BASEDIR}/local-one, keeping it.
1352+
[NOTE] Dependency local-two.dev is pinned to local target file://${BASEDIR}/local-two, keeping it.
1353+
Generated lock files for:
1354+
- distant-x.1: ${BASEDIR}/distant-x.opam.locked
1355+
### opam-cat distant-x.opam.locked
1356+
depends: ["local-one" {= "dev"} "local-two" {= "dev"}]
1357+
name: "distant-x"
1358+
opam-version: "2.0"
1359+
pin-depends: [["local-one.dev" "file://${BASEDIR}/local-one"] ["local-two.dev" "file://${BASEDIR}/local-two"]]
1360+
version: "1"

0 commit comments

Comments
 (0)