Skip to content

Commit 48a157e

Browse files
authored
Filter root packages by available condition (#72)
This is useful if some packages in a repository only work on certain platforms. For example, eio_linux should only be tested on Linux, but some other packages should still be tested on e.g. macos.
1 parent 6e935f5 commit 48a157e

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

service/domain_worker.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ type reply = ((OpamPackage.t list, string) result * float, [`Msg of string]) res
2020
[Ok (Error msg)] if there is no solution.
2121
[Error msg] if the request was invalid. *)
2222

23+
val env : Solver_service_api.Worker.Vars.t -> string -> OpamVariable.variable_contents option
24+
(** [env vars name] is the value of [name] in [vars]. *)
25+
2326
val solve : request -> reply

service/solver.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,19 @@ let compatible_with ~ocaml_version (dep_name, filter) =
2626
OpamFormula.eval check_ocaml filter
2727
else true
2828

29+
let env vars v =
30+
if List.mem v OpamPackageVar.predefined_depends_variables then None
31+
else Domain_worker.env vars (OpamVariable.Full.to_string v)
32+
2933
let solve_for_platform ?cancelled t ~log ~opam_repository_commits ~packages ~root_pkgs ~pinned_pkgs ~pins ~vars id =
3034
let ocaml_version = OpamPackage.Version.of_string vars.Worker.Vars.ocaml_version in
3135
let root_pkgs =
3236
root_pkgs
3337
|> List.filter (fun (_name, (_version, opam)) ->
38+
let avail = OpamFile.OPAM.available opam in
3439
let deps = OpamFile.OPAM.depends opam in
40+
let env = env vars in
41+
OpamFilter.eval_to_bool ~default:true env avail &&
3542
OpamFormula.eval (compatible_with ~ocaml_version) deps)
3643
in
3744
if root_pkgs = [] then (

test/test.expected

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,22 @@ platforms: [debian-12-ocaml-5]
227227
Need to update opam-repo.git to get new commit 1bc28b8e8d98db6e524822c6f28bddebbc3504a3
228228
results:
229229
Cancelled
230+
231+
# Available
232+
233+
## foo-linux is only selected on Linux platform, but foo is selected for both ##
234+
235+
commits: [(opam-repo.git, [ocaml-base-compiler.5.0])]
236+
root_pkgs: [foo.dev; foo-linux.dev]
237+
platforms: [linux; mac]
238+
results:
239+
[linux:
240+
compat_pkgs: [foo.dev; foo-linux.dev]
241+
packages: [foo.dev; foo-linux.dev; ocaml-base-compiler.5.0]
242+
commits: [(opam-repo.git, 1bc28b8e8d98db6e524822c6f28bddebbc3504a3)]
243+
lower_bound: false;
244+
mac:
245+
compat_pkgs: [foo.dev]
246+
packages: [foo.dev; ocaml-base-compiler.5.0]
247+
commits: [(opam-repo.git, 1bc28b8e8d98db6e524822c6f28bddebbc3504a3)]
248+
lower_bound: false]

test/test.ml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,23 @@ let test_cancel t =
214214
~commits:[opam_repo, opam_packages]
215215
~platforms
216216

217+
let test_available t =
218+
let opam_repo = Opam_repo.create "opam-repo.git" in
219+
let opam_packages = [
220+
"ocaml-base-compiler.5.0", "";
221+
] in
222+
let root_pkgs = [
223+
"foo.dev", "";
224+
"foo-linux.dev", {| available: os = "linux" |};
225+
] in
226+
solve t "foo-linux is only selected on Linux platform, but foo is selected for both"
227+
~root_pkgs
228+
~commits:[opam_repo, opam_packages]
229+
~platforms:[
230+
"linux", debian_12_ocaml_5;
231+
"mac", { debian_12_ocaml_5 with os = "macos" };
232+
]
233+
217234
let () =
218235
Eio_main.run @@ fun env ->
219236
let domain_mgr = env#domain_mgr in
@@ -232,6 +249,7 @@ let () =
232249
"Multiple roots", test_multiple_roots;
233250
"Pinned", test_pinned;
234251
"Cancel", test_cancel;
252+
"Available", test_available;
235253
]
236254
|> List.iter (fun (name, fn) ->
237255
Fmt.pr "@.# %s@." name;

0 commit comments

Comments
 (0)