diff --git a/lib/analyse.ml b/lib/analyse.ml index 43361c3..36e5cf3 100644 --- a/lib/analyse.ml +++ b/lib/analyse.ml @@ -53,6 +53,7 @@ let make_placeholder_selections ~platforms ~opam_repository_commits = { Selection.variant = fst platform; packages = []; + only_packages = []; commits = List.map (fun y -> @@ -196,12 +197,11 @@ module Analysis = struct None (** If the opam file for the given root_pkgs includes a build command, use - that instead of the default (dune build @install @runtests). This is - put into Selection.command to be picked up by the build phase. + that instead of the default (dune build \@install \@runtests). This is put + into Selection.command to be picked up by the build phase. - This is only implemented if root_pkgs is a singleton, otherwise we - fall back to the default build command. - *) + This is only implemented if root_pkgs is a singleton, otherwise we fall + back to the default build command. *) let maybe_add_build_command ~root_pkgs selection = match root_pkgs with | [ (pkg_name, opam_str) ] -> @@ -211,6 +211,7 @@ module Analysis = struct { Selection.variant = selection.Selection.variant; packages = selection.packages; + only_packages = selection.only_packages; commits = selection.commits; command; } @@ -283,7 +284,9 @@ module Analysis = struct Capnp_rpc_lwt.Capability.with_ref (job_log job) @@ fun log -> Backend_solver.solve solver job request ~log >|= function | Ok [] -> Fmt.error_msg "No solution found for any supported platform" - | Ok x -> Ok (List.map Selection.of_worker x) + | Ok x -> + let root_pkgs = List.map fst root_pkgs in + Ok (List.map (Selection.of_worker ~root_pkgs) x) | Error (`Msg msg) -> Fmt.error_msg "Error from solver: %s" msg let find_opam_files ~job ~dir = diff --git a/lib/opam_build.ml b/lib/opam_build.ml index f916c12..387b05a 100644 --- a/lib/opam_build.ml +++ b/lib/opam_build.ml @@ -218,10 +218,16 @@ let spec_script ~repo ~base ~opam_files ~compiler_commit ~selection ~cmds = ~cmds:(run_all_opam_exec cmds) let spec_dune ~repo ~base ~opam_files ~compiler_commit ~selection = + let only_packages = + let to_name x = OpamPackage.of_string x |> OpamPackage.name_to_string in + match selection.Selection.only_packages with + | [] -> "" + | pkgs -> " --only-packages=" ^ String.concat "," (List.map to_name pkgs) + in let cmd = match selection.Selection.command with | Some c -> c - | None -> "dune build @install @runtest" + | None -> Printf.sprintf "dune build%s @install @runtest" only_packages in let cmds = [ "opam install dune"; cmd ^ " && rm -rf _build" ] in spec_script ~repo ~base ~opam_files ~compiler_commit ~selection ~cmds diff --git a/lib/selection.ml b/lib/selection.ml index c7781bb..be7c0d9 100644 --- a/lib/selection.ml +++ b/lib/selection.ml @@ -1,21 +1,25 @@ type t = { variant : Variant.t; (** The variant image to build on. *) packages : string list; (** The selected packages ("name.version"). *) + only_packages : string list; [@default []] + (** Local root packages to include (empty to include all). *) commits : (string * string) list; (** The list of (repo_url,commit) opam-repositories from the analysis, and they're all usefull during the build.*) command : string option; - (** The build command to use (will default to dune build @install @runtest if not specified) *) + (** The build command to use (will default to dune build \@install + \@runtest if not specified) *) } [@@deriving yojson, ord] (** A set of packages for a single build. *) -let of_worker w = +let of_worker ~root_pkgs w = let module W = Ocaml_multicore_ci_api.Worker.Selection in - let { W.id; packages; commits; _ } = w in + let { W.id; packages; commits; compat_pkgs } = w in let variant = Variant.of_string id in + let only_packages = if root_pkgs = compat_pkgs then [] else compat_pkgs in let commits = commits in - { variant; packages; commits; command = None } + { variant; packages; only_packages; commits; command = None } let remove_package t ~package = { diff --git a/lib/selection.mli b/lib/selection.mli index df1baa3..3ad031f 100644 --- a/lib/selection.mli +++ b/lib/selection.mli @@ -1,14 +1,19 @@ type t = { variant : Variant.t; (** The variant image to build on. *) packages : string list; (** The selected packages ("name.version"). *) + only_packages : string list; [@default []] + (** Local root packages to include (empty to include all). *) commits : (string * string) list; (** The list of (repo_url,commit) opam-repositories from the analysis, and they're all usefull during the build.*) command : string option; - (** The build command to use (will default to dune build @install @runtest if not specified) *) + (** The build command to use (will default to dune build \@install + \@runtest if not specified) *) } [@@deriving yojson, ord] (** A set of packages for a single build. *) -val of_worker : Ocaml_multicore_ci_api.Worker.Selection.t -> t +val of_worker : + root_pkgs:string list -> Ocaml_multicore_ci_api.Worker.Selection.t -> t + val remove_package : t -> package:string -> t