Skip to content

Commit

Permalink
switch: allow local compiler switch creation (ocaml#3720)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbou committed Mar 27, 2019
1 parent 7e8008a commit b7381d5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/client/opamAuxCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,13 @@ let get_compatible_compiler ?repos rt dir =
(OpamStd.Format.itemize OpamPackage.to_string
(OpamPackage.Set.elements local_packages));
if OpamConsole.confirm "Do you want to create an empty switch regardless?"
then []
then [], false
else OpamStd.Sys.exit_because `Aborted)
else
let compilers = OpamPackage.Set.inter compilers installable in
try
[OpamSolution.eq_atom_of_package
(OpamPackage.Set.choose_one compilers)]
(OpamPackage.Set.choose_one compilers)], true
with
| Not_found when not (OpamPackage.Set.is_empty local_packages) ->
OpamConsole.warning
Expand All @@ -507,15 +507,15 @@ let get_compatible_compiler ?repos rt dir =
OpamConsole.confirm
"Create the switch with no specific compiler selected, and attempt to \
continue?"
then []
then [], false
else OpamStd.Sys.exit_because `Aborted
| Failure _ | Not_found ->
(* Find a matching compiler from the default selection *)
let default_compiler =
OpamFile.Config.default_compiler gt.config
in
if default_compiler = Empty then
(OpamConsole.warning "No compiler selected"; [])
(OpamConsole.warning "No compiler selected"; [], false)
else
let candidates = OpamFormula.to_dnf default_compiler in
try
Expand Down Expand Up @@ -545,7 +545,7 @@ let get_compatible_compiler ?repos rt dir =
Some (OpamSolution.eq_atoms_of_packages compiler)
else None
)
candidates
candidates, false
with Not_found ->
OpamConsole.warning
"The default compiler selection: %s\n\
Expand All @@ -557,5 +557,5 @@ let get_compatible_compiler ?repos rt dir =
if OpamConsole.confirm
"You may also proceed, with no specific compiler selected. \
Do you want to?"
then []
then [], false
else OpamStd.Sys.exit_because `Aborted
2 changes: 1 addition & 1 deletion src/client/opamAuxCommands.mli
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ val simulate_autopin:
warning, and returns the empty list after user confirmation. *)
val get_compatible_compiler:
?repos:repository_name list ->
'a repos_state -> dirname -> atom list
'a repos_state -> dirname -> atom list * bool
10 changes: 6 additions & 4 deletions src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2040,7 +2040,7 @@ let switch =
match packages, compiler_opt, OpamSwitch.is_external switch with
| None, None, false ->
OpamSwitchCommand.guess_compiler_package ?repos rt
(OpamSwitch.to_string switch)
(OpamSwitch.to_string switch), false
| None, None, true ->
OpamAuxCommands.get_compatible_compiler ?repos rt
(OpamFilename.dirname_dir
Expand All @@ -2049,7 +2049,7 @@ let switch =
OpamStd.Option.Op.(
((compiler_opt >>|
OpamSwitchCommand.guess_compiler_package ?repos rt) +! []) @
packages +! [])
packages +! []), false
in
let param_compiler = function
| [] -> None
Expand Down Expand Up @@ -2109,18 +2109,20 @@ let switch =
OpamGlobalState.with_ `Lock_write @@ fun gt ->
let repos, rt = get_repos_rt gt repos in
let switch = OpamSwitch.of_string switch_arg in
let packages =
let packages, local_compiler =
compiler_packages rt ?repos switch (param_compiler params)
in
let _gt, st =
OpamSwitchCommand.install gt ~rt
?synopsis:descr ?repos
~update_config:(not no_switch)
~packages
~local_compiler
switch
in
let st =
if not no_install && not empty && OpamSwitch.is_external switch then
if not no_install && not empty &&
OpamSwitch.is_external switch && not local_compiler then
let st, atoms =
OpamAuxCommands.autopin st ~simulate:deps_only ~quiet:true
[`Dirname (OpamFilename.Dir.of_string switch_arg)]
Expand Down
9 changes: 8 additions & 1 deletion src/client/opamSwitchCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ let install_compiler_packages t atoms =
OpamSolution.check_solution ~quiet:OpamClientConfig.(not !r.show) t result;
t

let install gt ?rt ?synopsis ?repos ~update_config ~packages switch =
let install gt ?rt ?synopsis ?repos ~update_config ~packages ?(local_compiler=false) switch =
let update_config = update_config && not (OpamSwitch.is_external switch) in
let old_switch_opt = OpamFile.Config.switch gt.config in
let comp_dir = OpamPath.Switch.root gt.root switch in
Expand Down Expand Up @@ -311,6 +311,13 @@ let install gt ?rt ?synopsis ?repos ~update_config ~packages switch =
in
{ st with switch; available_packages }
in
let st =
if OpamSwitch.is_external switch && local_compiler then
OpamAuxCommands.autopin st ~quiet:true
[`Dirname (OpamFilename.Dir.of_string (OpamSwitch.to_string switch))]
|> fst
else st
in
let packages =
try OpamSolution.sanitize_atom_list st packages
with e ->
Expand Down
4 changes: 3 additions & 1 deletion src/client/opamSwitchCommand.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ val install:
?synopsis:string ->
?repos:repository_name list ->
update_config:bool ->
packages:atom conjunction -> switch ->
packages:atom conjunction ->
?local_compiler:bool ->
switch ->
unlocked global_state * rw switch_state

(** Install a compiler's base packages *)
Expand Down

0 comments on commit b7381d5

Please sign in to comment.