diff --git a/src/client/opamAuxCommands.ml b/src/client/opamAuxCommands.ml index 39c98e29685..81e2909cbed 100644 --- a/src/client/opamAuxCommands.ml +++ b/src/client/opamAuxCommands.ml @@ -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 @@ -507,7 +507,7 @@ 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 *) @@ -515,7 +515,7 @@ let get_compatible_compiler ?repos rt dir = 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 @@ -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\ @@ -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 diff --git a/src/client/opamAuxCommands.mli b/src/client/opamAuxCommands.mli index cb3efccbc97..d2be444353e 100644 --- a/src/client/opamAuxCommands.mli +++ b/src/client/opamAuxCommands.mli @@ -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 diff --git a/src/client/opamCommands.ml b/src/client/opamCommands.ml index 1500a4ba5a9..d6065c8c9ba 100644 --- a/src/client/opamCommands.ml +++ b/src/client/opamCommands.ml @@ -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 @@ -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 @@ -2109,7 +2109,7 @@ 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 = @@ -2117,10 +2117,12 @@ let switch = ?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)] diff --git a/src/client/opamSwitchCommand.ml b/src/client/opamSwitchCommand.ml index 8b5bdc8dbc0..8b1a37fe8a4 100644 --- a/src/client/opamSwitchCommand.ml +++ b/src/client/opamSwitchCommand.ml @@ -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 @@ -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 -> diff --git a/src/client/opamSwitchCommand.mli b/src/client/opamSwitchCommand.mli index c7804e97f1a..0b25b142571 100644 --- a/src/client/opamSwitchCommand.mli +++ b/src/client/opamSwitchCommand.mli @@ -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 *)