+ let specfile = fedora_specfile pkg branch in
+
+ (* Note: verrel may change as we go along, so don't assign it to
+ * variable.
+ *)
+
+ (* Note the target must be both of these because the old verrel
+ * could exist as a koji build without it having been part of the
+ * rebuild.
+ *)
+ target (file_contains_string specfile rebuild_name &&
+ koji_build_state (fedora_verrel pkg branch) == `Complete);
+
+ (* Start the rebuild. *)
+ require (rebuild_started pkg);
+
+ (* Wait for the build state to reach a conclusion. *)
+ let rec loop () =
+ match koji_build_state (fedora_verrel pkg branch) with
+ | `Building ->
+ sleep 30;
+ loop ()
+ | `Complete ->
+ ()
+ | `Deleted ->
+ failwith (sprintf "rebuild of package %s: deleted" pkg)
+ | `Failed ->
+ failwith (sprintf "rebuild of package %s: failed" pkg)
+ | `Canceled ->
+ failwith (sprintf "rebuild of package %s: canceled" pkg)
+ in
+ loop ();
+
+ (* Wait for the build to appear in Koji repo. *)
+ koji_wait_repo koji_target (fedora_verrel pkg branch)
+
+(* Goal: The rebuild of the package has started, but we haven't waited
+ * for it to finish.
+ *)
+and rebuild_started pkg =