Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix opam switch list-available pkg.version patttern #6186

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -35,6 +35,7 @@ users)
* [BUG] Ensure the output of opam commands using a column style UI stay consistent accross environment by setting the number of columns to 80 if stdout is not a tty and if the `COLUMNS` env variable is not set [#6244 @kit-ty-kate]

## Switch
* [BUG] Correctly handle `pkg.version` pattern in `opam switch list-available` [#6186 @arozovyk - fix #6152]

## Config

Expand Down Expand Up @@ -138,6 +139,7 @@ users)
# API updates
## opam-client
* `OpamArg.InvalidCLI`: export exception [#6150 @rjbou]
* `OpamListCommand.pattern_selector`: add `?concat` argument to be able to specify if the selector is an AND list or OR list, OR list being the default [#6186 @rjbou]

## opam-repository

Expand Down
10 changes: 2 additions & 8 deletions src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2894,16 +2894,10 @@ let switch cli =
(OpamStd.List.concat_map ", " OpamRepositoryName.to_string
(OpamStd.Option.default (OpamGlobalState.repos_list gt) repos));
let filters =
List.map (fun patt ->
OpamListCommand.Pattern
({ OpamListCommand.default_pattern_selector with
OpamListCommand.fields = ["name"; "version"] },
patt))
pattlist
OpamListCommand.pattern_selector ~concat:OpamFormula.ands pattlist
in
let all_compilers =
OpamListCommand.filter ~base:compilers st
(OpamFormula.ands (List.map (fun f -> OpamFormula.Atom f) filters))
OpamListCommand.filter ~base:compilers st filters
in
let compilers =
if all then
Expand Down
4 changes: 2 additions & 2 deletions src/client/opamListCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ let rec value_strings value =
List.fold_left (fun acc v -> SS.union acc (value_strings v.pelem))
(value_strings v.pelem) vl.pelem

let pattern_selector patterns =
let pattern_selector ?(concat=OpamFormula.ors) patterns =
let name_patt =
{ default_pattern_selector with exact = true; fields = ["name"] }
in
let version_patt =
{ default_pattern_selector with exact = true; fields = ["version"] }
in
OpamFormula.ors
concat
(List.map (fun patt ->
match OpamStd.String.cut_at patt '.' with
| None ->
Expand Down
9 changes: 7 additions & 2 deletions src/client/opamListCommand.mli
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ val filter:
base:package_set -> 'a switch_state ->
selector OpamFormula.formula -> package_set

(** Or-filter on package patterns (NAME or NAME.VERSION) *)
val pattern_selector: string list -> selector OpamFormula.formula
(** filter on package patterns (NAME or NAME.VERSION).
By default, it concatenate the given pattern list with ORs unless another
concatenation function is given with [concat]) *)
val pattern_selector:
?concat:(selector OpamFormula.formula list -> selector OpamFormula.formula)
-> string list
-> selector OpamFormula.formula

(** Get the aggregated active external dependencies of the given packages *)
val get_depexts: 'a switch_state -> package_set -> OpamSysPkg.Set.t
Expand Down
10 changes: 7 additions & 3 deletions tests/reftests/switch-list-available.test
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,20 @@ comp-b 3
comp-b 4
### opam switch list-available comp-b.1
# Listing available compilers from repositories: default
# No matches found
# Name # Version # Synopsis
comp-b 1
### opam switch list-available comp-b.1 --all
# Listing available compilers from repositories: default
# No matches found
# Name # Version # Synopsis
comp-b 1
### opam switch list-available comp-b.2
# Listing available compilers from repositories: default
# No matches found
[NOTE] Some compilers have been hidden (e.g. pre-releases). If you want to display them, run: 'opam switch list-available --all'
### opam switch list-available comp-b.2 --all
# Listing available compilers from repositories: default
# No matches found
# Name # Version # Synopsis
comp-b 2
### <pkg:comp_c.1>
opam-version: "2.0"
flags: compiler
Expand Down
Loading