Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a lower-bound checker #102

Merged
merged 2 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/build.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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 =
Expand All @@ -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

Expand Down Expand Up @@ -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 "@.\
Expand Down
1 change: 1 addition & 0 deletions lib/build.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
62 changes: 35 additions & 27 deletions lib/opam_build.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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)
]

Expand Down Expand Up @@ -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
)
Expand Down
1 change: 1 addition & 0 deletions lib/opam_build.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 19 additions & 4 deletions service/pipeline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand Down