Skip to content

Commit

Permalink
fix(pkg): more filter partial evaluation (#9393)
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg authored Dec 7, 2023
1 parent 90d7bad commit 0aa3ec3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
22 changes: 13 additions & 9 deletions src/dune_pkg/opam_solver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -384,23 +384,27 @@ let simplify_filter solver_env =
| _ -> None)
;;

let filter_needed = function
| None -> true
| Some f -> OpamFilter.eval_to_bool ~default:true (Fun.const None) f
let partial_eval_filter = function
| None -> `Filter None
| Some f ->
let env = Fun.const None in
(match OpamFilter.eval_to_bool env f with
| exception Failure _ -> `Filter (Some f)
| b -> if b then `Filter None else `Skip)
;;

let opam_commands_to_actions solver_env loc package (commands : OpamTypes.command list) =
List.filter_map commands ~f:(fun (args, filter) ->
let filter = Option.map filter ~f:(simplify_filter solver_env) in
match filter_needed filter with
| false -> None
| true ->
match partial_eval_filter filter with
| `Skip -> None
| `Filter filter ->
let terms =
List.filter_map args ~f:(fun (simple_arg, filter) ->
let filter = Option.map filter ~f:(simplify_filter solver_env) in
match filter_needed filter with
| false -> None
| true ->
match partial_eval_filter filter with
| `Skip -> None
| `Filter filter ->
let slang =
let slang =
match simple_arg with
Expand Down
8 changes: 2 additions & 6 deletions test/blackbox-tests/test-cases/pkg/convert-opam-commands.t
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,8 @@ Package which has boolean where string was expected. This should be caught while
(when
(< %{pkg-self:version} 1.0)
(run echo g))
(when
true
(run echo i))
(when
true
(run echo j))
(run echo i)
(run echo j)
(when
%{pkg:foo:installed}
(run echo k))
Expand Down

0 comments on commit 0aa3ec3

Please sign in to comment.