Skip to content

Commit

Permalink
Merge pull request #3358 from OCamlPro/better-compil-select
Browse files Browse the repository at this point in the history
Better automatic compiler selection for local switches
  • Loading branch information
AltGr authored May 17, 2018
2 parents 9df37ac + be1303f commit 228437c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
13 changes: 13 additions & 0 deletions doc/pages/Tricks.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,16 @@ to rename `foo` to `bar`:

This ensures at the same time that users upgrading will get the new package
`bar`, and that the package can't be installed twice under the two names.


---

#### Display the current "opam switch" in the prompt ?

This can get quite handy if you have many switches you use in parallel.
You can use e.g. the command `opam switch show --safe 2>/dev/null | sed
's|.*/|*|'` to return a (shortened) switch name.

For `bash`, just include `$(COMMAND)` in your definition of `PS1` (making sure the `$` is escaped).

For `zsh`, use `setopt prompt_subst`, and include `$(COMMAND)` in the definition of `prompt`.
28 changes: 22 additions & 6 deletions src/client/opamAuxCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,6 @@ let get_compatible_compiler ?repos ?locked rt dir =
acc (OpamFile.OPAM.pin_depends opam))
local_opams OpamPackage.Set.empty
in
let local_atoms =
OpamSolution.eq_atoms_of_packages local_packages
in
let virt_st =
let opams =
OpamPackage.Map.union (fun _ x -> x) virt_st.opams local_opams
Expand Down Expand Up @@ -512,10 +509,29 @@ let get_compatible_compiler ?repos ?locked rt dir =
else
let candidates = OpamFormula.to_dnf default_compiler in
try
List.find
OpamStd.List.find_map
(fun atoms ->
OpamSolver.atom_coinstallability_check univ
(local_atoms @ atoms))
let has_all compiler_packages =
List.for_all (fun at ->
OpamPackage.Set.exists (OpamFormula.check at) compiler_packages)
atoms
in
let compiler =
OpamFormula.packages_of_atoms
(Lazy.force virt_st.available_packages)
atoms
in
if not (has_all compiler) then None else
(* fake universe with `local_packages` as base, just to check
coinstallability *)
let univ =
{ univ with u_base = local_packages; u_installed = local_packages }
in
let compiler = OpamSolver.installable_subset univ compiler in
if has_all compiler then
Some (OpamSolution.eq_atoms_of_packages compiler)
else None
)
candidates
with Not_found ->
OpamConsole.warning
Expand Down

0 comments on commit 228437c

Please sign in to comment.