diff --git a/lib/build.ml b/lib/build.ml index 67bc12ef..7778ceb3 100644 --- a/lib/build.ml +++ b/lib/build.ml @@ -15,6 +15,7 @@ module Spec = struct type opam_build = { revdep : package option; with_tests : bool; + lower_bounds : bool; upgrade_opam : bool [@default false]; } [@@deriving to_yojson] @@ -27,8 +28,8 @@ module Spec = struct ty : ty; } - let opam ?revdep ~platform ~with_tests ~upgrade_opam pkg = - let ty = `Opam (`Build { revdep; with_tests; upgrade_opam }, pkg) in + let opam ?revdep ~platform ~lower_bounds ~with_tests ~upgrade_opam pkg = + let ty = `Opam (`Build { revdep; lower_bounds; with_tests; upgrade_opam }, pkg) in { platform; ty } let pp_pkg ?revdep f pkg = @@ -39,9 +40,10 @@ module Spec = struct let pp_ty f = function | `Opam (`List_revdeps, pkg) -> Fmt.pf f "list revdeps of %s" (OpamPackage.to_string pkg) - | `Opam (`Build { revdep; with_tests; upgrade_opam }, pkg) -> + | `Opam (`Build { revdep; lower_bounds; with_tests; upgrade_opam }, pkg) -> let action = if with_tests then "test" else "build" in - Fmt.pf f "%s %a%s" action (pp_pkg ?revdep) pkg + Fmt.pf f "%s %a%s%s" action (pp_pkg ?revdep) pkg + (if lower_bounds then ", lower-bounds" else "") (if upgrade_opam then ", using opam 2.1" else "") end @@ -122,7 +124,7 @@ module Op = struct let base = Image.hash base in match ty with | `Opam (`List_revdeps, pkg) -> Opam_build.revdeps ~for_docker ~base ~variant ~pkg - | `Opam (`Build { revdep; with_tests; upgrade_opam }, pkg) -> Opam_build.spec ~for_docker ~upgrade_opam ~base ~variant ~revdep ~with_tests ~pkg + | `Opam (`Build { revdep; lower_bounds; with_tests; upgrade_opam }, pkg) -> Opam_build.spec ~for_docker ~upgrade_opam ~base ~variant ~revdep ~lower_bounds ~with_tests ~pkg in Current.Job.write job (Fmt.strf "@.\ diff --git a/lib/build.mli b/lib/build.mli index 78f704d3..8b8c868e 100644 --- a/lib/build.mli +++ b/lib/build.mli @@ -4,6 +4,7 @@ module Spec : sig val opam : ?revdep:OpamPackage.t -> platform:Platform.t -> + lower_bounds:bool -> with_tests:bool -> upgrade_opam:bool -> OpamPackage.t -> diff --git a/lib/opam_build.ml b/lib/opam_build.ml index ff833e91..6f54b2cd 100644 --- a/lib/opam_build.ml +++ b/lib/opam_build.ml @@ -2,32 +2,36 @@ let download_cache = "opam-archives" let cache = [ Obuilder_spec.Cache.v download_cache ~target:"/home/opam/.opam/download-cache" ] let network = ["host"] -let opam_install ~variant ~upgrade_opam ~pin ~with_tests ~pkg = +let opam_upgrade_cmd = "sudo ln -f /usr/bin/opam-2.1 /usr/bin/opam && opam init --reinit -ni" + +let opam_install ~variant ~is_opam_2_1 ~pin ~lower_bounds ~with_tests ~pkg = let pkg = OpamPackage.to_string pkg in + let upgrade_opam = lower_bounds || is_opam_2_1 in let open Obuilder_spec in - let pin = - if pin then - let version = - let idx = String.index pkg '.' + 1 in - String.sub pkg idx (String.length pkg - idx) - in - [ run "opam pin add -k version -yn %s %s" pkg version ] - else - [] - in - pin @ [ + (if lower_bounds then + (if not is_opam_2_1 then [run "%s" opam_upgrade_cmd] else []) @ + [ + env "OPAMCRITERIA" "+removed,+count[version-lag,solution]"; + env "OPAMEXTERNALSOLVER" "builtin-0install"; + ] + else + [] + ) @ + (if pin then + let version = + let idx = String.index pkg '.' + 1 in + String.sub pkg idx (String.length pkg - idx) + in + [ run "opam pin add -k version -yn %s %s" pkg version ] + else + [] + ) @ [ run ~network "opam %s" (if upgrade_opam then "update --depexts" else "depext -yu"); (* TODO: Replace by two calls to opam install + opam install -t using the OPAMDROPINSTALLEDPACKAGES feature *) - run ~cache ~network {| - opam remove -y %s && opam %s%s %s; + run ~cache ~network + {|opam remove -y %s && opam %s%s %s; res=$?; - test "$res" = 0 && exit 0; - if test "$res" = 60 && diff -q /usr/bin/opam /usr/bin/opam-2.0; then - sudo ln -f /usr/bin/opam-2.1 /usr/bin/opam && opam init --reinit -ni; - opam remove -y %s && opam install -vy%s %s%s; - exit 1; - fi; - test "$res" != 31 && exit 1; + test "$res" != 31 && exit "$res"; export OPAMCLI=2.0; build_dir=$(opam var prefix)/.opam-switch/build; failed=$(ls "$build_dir"); @@ -38,7 +42,6 @@ let opam_install ~variant ~upgrade_opam ~pin ~with_tests ~pkg = done; exit 1|} pkg (if upgrade_opam then "install -vy" else "depext -ivy") (if with_tests then "t" else "") pkg - pkg (if with_tests then "t" else "") pkg (if with_tests then "" else " && opam reinstall -vyt "^pkg) (Variant.distribution variant) ] @@ -73,19 +76,24 @@ let set_personality ~variant = else [] -let spec ~for_docker ~upgrade_opam ~base ~variant ~revdep ~with_tests ~pkg = +let spec ~for_docker ~upgrade_opam ~base ~variant ~revdep ~lower_bounds ~with_tests ~pkg = + let opam_install = opam_install ~variant ~is_opam_2_1:upgrade_opam in let revdep = match revdep with | None -> [] - | Some revdep -> opam_install ~variant ~upgrade_opam ~pin:false ~with_tests:false ~pkg:revdep + | Some revdep -> opam_install ~pin:false ~lower_bounds:false ~with_tests:false ~pkg:revdep and tests = match with_tests, revdep with - | true, None -> opam_install ~variant ~upgrade_opam ~pin:false ~with_tests:true ~pkg - | true, Some revdep -> opam_install ~variant ~upgrade_opam ~pin:false ~with_tests:true ~pkg:revdep + | true, None -> opam_install ~pin:false ~lower_bounds:false ~with_tests:true ~pkg + | true, Some revdep -> opam_install ~pin:false ~lower_bounds:false ~with_tests:true ~pkg:revdep | false, _ -> [] + and lower_bounds = match lower_bounds with + | true -> opam_install ~pin:false ~lower_bounds:true ~with_tests:false ~pkg + | false -> [] in Obuilder_spec.stage ~from:base ( set_personality ~variant @ setup_repository ~variant ~for_docker ~upgrade_opam - @ opam_install ~variant ~upgrade_opam ~pin:true ~with_tests:false ~pkg + @ opam_install ~pin:true ~lower_bounds:false ~with_tests:false ~pkg + @ lower_bounds @ revdep @ tests ) diff --git a/lib/opam_build.mli b/lib/opam_build.mli index 1527b37a..35586bb2 100644 --- a/lib/opam_build.mli +++ b/lib/opam_build.mli @@ -4,6 +4,7 @@ val spec : base:string -> variant:Variant.t -> revdep:OpamPackage.t option -> + lower_bounds:bool -> with_tests:bool -> pkg:OpamPackage.t -> Obuilder_spec.t diff --git a/service/pipeline.ml b/service/pipeline.ml index 3764a91c..2aa906e7 100644 --- a/service/pipeline.ml +++ b/service/pipeline.ml @@ -73,19 +73,25 @@ let dep_list_map (type a) (module M : Current_term.S.ORDERED with type t = a) ?c let build_spec ~platform ~upgrade_opam pkg = let+ pkg = pkg in - Build.Spec.opam ~platform ~with_tests:false ~upgrade_opam pkg + Build.Spec.opam ~platform ~lower_bounds:false ~with_tests:false ~upgrade_opam pkg let test_spec ~platform ~upgrade_opam ~after pkg = let+ _ = after and+ pkg = pkg in - Build.Spec.opam ~platform ~with_tests:true ~upgrade_opam pkg + Build.Spec.opam ~platform ~lower_bounds:false ~with_tests:true ~upgrade_opam pkg + +let lower_bounds_spec ~platform ~upgrade_opam ~after pkg = + let+ _ = after + and+ pkg = pkg + in + Build.Spec.opam ~platform ~lower_bounds:true ~with_tests:false ~upgrade_opam pkg let revdep_spec ~platform ~upgrade_opam ~revdep pkg = let+ revdep = revdep and+ pkg = pkg in - Build.Spec.opam ~platform ~with_tests:true ~revdep ~upgrade_opam pkg + Build.Spec.opam ~platform ~lower_bounds:false ~with_tests:true ~revdep ~upgrade_opam pkg let combine_revdeps revdeps = let map = @@ -150,15 +156,24 @@ let build_with_cluster ~ocluster ~analysis ~lint ~master source = let spec = test_spec ~platform ~upgrade_opam pkg ~after:image in Build.v ocluster ~label:"test" ~base ~spec ~master source in + let lower_bounds_check = + let spec = lower_bounds_spec ~platform ~upgrade_opam pkg ~after:image in + Build.v ocluster ~label:"lower-bounds" ~base ~spec ~master source + in let+ pkg = pkg and+ build = Node.action `Built image and+ tests = Node.action `Built tests + and+ lower_bounds_check = Node.action `Built lower_bounds_check and+ revdeps = if revdeps then test_revdeps ~ocluster ~master ~base ~platform ~pkg source ~after:image else Current.return [] in let label = OpamPackage.to_string pkg in - Node.actioned_branch ~label build (Node.leaf ~label:"tests" tests :: revdeps) + Node.actioned_branch ~label build ( + Node.leaf ~label:"tests" tests :: + Node.leaf ~label:"lower-bounds" lower_bounds_check :: + revdeps + ) ) |> Current.map (Node.branch ~label) |> Current.collapse ~key:"platform" ~value:label ~input:analysis