From 897fddc9620a9adeac11a96e0ceb39d4c166d63e Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Tue, 12 Mar 2024 12:35:01 +0000 Subject: [PATCH] Feed it --- src/solver/opamCudf.ml | 1 + src/solver/opamCudf.mli | 3 +++ src/solver/opamSolver.ml | 22 ++++++++++++++-------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/solver/opamCudf.ml b/src/solver/opamCudf.ml index 9318ab39152..3e57a4b24e5 100644 --- a/src/solver/opamCudf.ml +++ b/src/solver/opamCudf.ml @@ -22,6 +22,7 @@ let s_reinstall = "reinstall" let s_installed_root = "installed-root" let s_pinned = "pinned" let s_version_lag = "version-lag" +let s_avoid_version = "avoid-version" let opam_invariant_package_name = Dose_common.CudfAdd.encode "=opam-invariant" diff --git a/src/solver/opamCudf.mli b/src/solver/opamCudf.mli index 278be48c1c3..25fa2c8ed0a 100644 --- a/src/solver/opamCudf.mli +++ b/src/solver/opamCudf.mli @@ -186,6 +186,9 @@ val s_pinned: string (** the number of versions of the package since this one, cubed *) val s_version_lag: string +(** the avoid-version flag *) +val s_avoid_version: string + (** valid cudf name for the dummy package used for enforcing opam's switch invariants *) val opam_invariant_package_name: string diff --git a/src/solver/opamSolver.ml b/src/solver/opamSolver.ml index bd68b18327f..0a501d02dd0 100644 --- a/src/solver/opamSolver.ml +++ b/src/solver/opamSolver.ml @@ -167,15 +167,25 @@ let opam2cudf_map universe version_map packages = OpamPackage.Set.fold (fun nv -> OpamPackage.Map.add nv true) (packages %% set) OpamPackage.Map.empty in + let avoid_versions = + OpamStd.Option.default OpamPackage.Set.empty @@ + OpamStd.List.assoc_opt String.equal "avoid-version" universe.u_attrs + in let base_map = OpamPackage.Set.fold (fun nv -> + let pkg_extra = [ + OpamCudf.s_source, `String(OpamPackage.name_to_string nv); + OpamCudf.s_source_number, `String(OpamPackage.version_to_string nv); + ] in + let pkg_extra = + if OpamPackage.Set.mem nv avoid_versions then + (OpamCudf.s_avoid_version, `Bool true)::pkg_extra + else + pkg_extra in OpamPackage.Map.add nv { Cudf.default_package with Cudf.package = name_to_cudf nv.name; - pkg_extra = [ - OpamCudf.s_source, `String(OpamPackage.name_to_string nv); - OpamCudf.s_source_number, `String(OpamPackage.version_to_string nv); - ]; + pkg_extra; }) packages OpamPackage.Map.empty in @@ -188,10 +198,6 @@ let opam2cudf_map universe version_map packages = let reinstall_map = set_to_bool_map universe.u_reinstall in let installed_root_map = set_to_bool_map universe.u_installed_roots in let pinned_to_current_version_map = set_to_bool_map universe.u_pinned in - let avoid_versions = - OpamStd.Option.default OpamPackage.Set.empty @@ - OpamStd.List.assoc_opt String.equal "avoid-version" universe.u_attrs - in let version_lag_map = OpamPackage.Name.Map.fold (fun name version_set acc -> let nvers, vs =