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(pkg): more filter partial evaluation #9393

Merged
merged 1 commit into from
Dec 7, 2023
Merged
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
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