Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add dependencies only switch import #5388

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ users)
## Remove

## Switch
* ◈ Add `opam switch import --deps-only` option to install only dependencies of root package at import [#5388 @rjbou - fix #5200]

## Config

Expand Down Expand Up @@ -151,6 +152,7 @@ users)

# API updates
## opam-client
* `OpamSwitchCommand.import`: add optional `?deps_only` argument to install only dependencies of root packages [#5388 @rjbou]

## opam-repository
* `OpamRepository.fetch_from_cache`: when an archive is found, add a symlink (or copy) for the ones found in opam file but not in cache [#6068 @kit-ty-kate]
Expand Down
8 changes: 5 additions & 3 deletions src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2779,7 +2779,8 @@ let switch cli =
mk_flag ~cli cli_original ["deps-only"]
"When creating a local switch in a project directory (i.e. a directory \
containing opam package definitions), install the dependencies of the \
project but not the project itself."
project but not the project itself. When importing a switch, do not \
install root packages."
in
let force =
mk_flag ~cli (cli_from cli2_1) ["force"]
Expand Down Expand Up @@ -2997,7 +2998,7 @@ let switch cli =
~update_config:(not no_switch)
switch
@@ fun st ->
let st = OpamSwitchCommand.import st import_source in
let st = OpamSwitchCommand.import st ~deps_only import_source in
let invariant = OpamSwitchState.infer_switch_invariant st in
let st = OpamSwitchCommand.set_invariant_raw st invariant in
st.switch_global, st
Expand All @@ -3011,7 +3012,8 @@ let switch cli =
OpamConsole.warning
"Switch exists, '--repositories' argument ignored";
OpamSwitchState.with_ `Lock_write gt ~switch @@ fun st ->
OpamSwitchState.drop @@ OpamSwitchCommand.import st import_source
OpamSwitchState.drop
@@ OpamSwitchCommand.import st ~deps_only import_source
end;
`Ok ()
| Some `remove, switches ->
Expand Down
11 changes: 8 additions & 3 deletions src/client/opamSwitchCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ let switch_previous lock gt =
OpamConsole.error_and_exit `Not_found
"No previously used switch could be found"

let import_t ?ask importfile t =
let import_t ?ask ?(deps_only=false) importfile t =
log "import switch";

let extra_files = importfile.OpamFile.SwitchExport.extra_files in
Expand Down Expand Up @@ -462,6 +462,11 @@ let import_t ?ask importfile t =
t.compiler_packages,
import_sel.sel_installed -- import_sel.sel_compiler
in
let to_install =
if deps_only then
to_install -- (import_sel.sel_roots -- import_sel.sel_compiler)
else to_install
in

let t =
{ t with
Expand Down Expand Up @@ -679,7 +684,7 @@ let reinstall init_st =
overlays = OpamPackage.Name.Map.empty; }
st

let import st filename =
let import st ?deps_only filename =
let import_str = match filename with
| None -> OpamSystem.string_of_channel stdin
| Some f -> OpamFilename.read (OpamFile.filename f)
Expand All @@ -695,7 +700,7 @@ let import st filename =
overlays = OpamPackage.Name.Map.empty }
with e1 -> OpamStd.Exn.fatal e1; raise e
in
import_t importfile st
import_t ?deps_only importfile st

let set_invariant ?(force=false) st invariant =
let satisfied = OpamFormula.satisfies_depends st.installed invariant in
Expand Down
4 changes: 3 additions & 1 deletion src/client/opamSwitchCommand.mli
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ val install_compiler:
?additional_installs:atom list -> ?deps_only:bool -> ?ask:bool ->
rw switch_state -> rw switch_state

(** Import a file which contains the packages to install. *)
(** Import a file which contains the packages to install.
If [deps_only] is true do not install root packages. *)
val import:
rw switch_state ->
?deps_only:bool ->
OpamFile.SwitchExport.t OpamFile.t option ->
rw switch_state

Expand Down
46 changes: 46 additions & 0 deletions tests/reftests/switch-import.test
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,49 @@ url {
src: "file://${BASEDIR}/export-extra-files"
}
}
### : import with deps-only :
### <pkg:foo.1>
opam-version: "2.0"
flags: compiler
### <pkg:foo.2>
opam-version: "2.0"
flags: compiler
### <pkg:bar.1>
opam-version: "2.0"
depends: "baz"
### <pkg:baz.1>
opam-version: "2.0"
### opam switch create for-deps foo.1

<><> Installing new switch packages <><><><><><><><><><><><><><><><><><><><><><>
Switch invariant: ["foo" {= "1"}]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed foo.1
Done.
### opam install bar
The following actions will be performed:
=== install 2 packages
- install bar 1
- install baz 1 [required by bar]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed baz.1
-> installed bar.1
Done.
### opam switch export deps.xp
### opam-cat deps.xp
compiler: ["foo.1"]
installed: ["bar.1" "baz.1" "foo.1"]
opam-version: "2.0"
roots: ["bar.1" "foo.1"]
### opam switch import deps.xp --switch deps --deps-only
The following actions will be performed:
=== install 2 packages
- install baz 1
- install foo 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed baz.1
-> installed foo.1
Done.
Loading