Skip to content

Commit 767d608

Browse files
authored
fix(pkg): command filter may not be a boolean (#16313)
I was testing the `opam_solver` on random packages from the opam repo and stumbled upon this crash (because of [ocamlsdl.0.9.1](https://github.com/ocaml/opam-repository/blob/1e79ccac739fdf75f5425eef07fb8a5482f48528/packages/ocamlsdl/ocamlsdl.0.9.1/opam#L7))
2 parents 0230737 + e26e7d1 commit 767d608

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

doc/changes/fixed/16313.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix a crash when an opam filter is not a boolean (#16313, @art-w)

src/dune_pkg/lock_pkg.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let partial_eval_filter = function
5656
| Some f ->
5757
let env = Fun.const None in
5858
(match OpamFilter.eval_to_bool env f with
59-
| exception Failure _ -> `Filter (Some f)
59+
| exception (Failure _ | Invalid_argument _) -> `Filter (Some f)
6060
| b -> if b then `Filter None else `Skip)
6161
;;
6262

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
A command argument can carry a boolean filter. Some packages write that
2+
filter as an interpolated string rather than as a boolean: (as seen in
3+
`ocamlsdl.0.9.1`)
4+
5+
$ mkrepo
6+
$ mkpkg string-filter <<'EOF'
7+
> build: [
8+
> ["echo" "always"]
9+
> ["configure" "--with-other=%{lib}%/other" {"%{other:installed}%"}]
10+
> ]
11+
> EOF
12+
13+
As the package `other` is not part of the solution, the interpolation expands
14+
to the empty string, which is not a boolean. Opam removes these arguments when
15+
their filter does not evaluate to true. Dune does the same:
16+
17+
$ solve_project <<EOF
18+
> (lang dune 3.11)
19+
> (package
20+
> (name x)
21+
> (allow_empty)
22+
> (depends string-filter))
23+
> EOF
24+
Solution for dune.lock:
25+
- string-filter.0.0.1
26+
27+
$ cat ${default_lock_dir}/string-filter.0.0.1.pkg
28+
(version 0.0.1)
29+
30+
(build
31+
(all_platforms ((action (progn (run echo always) (run configure))))))

0 commit comments

Comments
 (0)