New libguestfs 1.26 branch.
[goaljobs-goals.git] / fedora_ocaml_rebuild.ml
index 2eccde1..9dc151d 100644 (file)
@@ -5,6 +5,7 @@ open Printf
 
 open Goaljobs
 open Config
+open Git
 open Fedora
 
 let branch = "master"
@@ -19,6 +20,7 @@ let rebuild_name = "OCaml 4.01.0"
 let blocked = [
   "ocaml-libvirt"; (* RHBZ#1009701 *)
   "ocaml-lwt"; "ocaml-react"; (* loganjerry is handling *)
+  "ocaml-xmlrpc-light"; (* temporary, can remove after 2013-09-19 *)
 ]
 
 (* List of OCaml-related source package names. *)
@@ -59,8 +61,10 @@ and rebuilt pkg =
   (* Wait for the build state to reach a conclusion. *)
   let rec loop () =
     match koji_build_state (fedora_verrel pkg branch) with
+    | `No_such_build ->
+      failwith (sprintf "rebuild of package %s: no build found" pkg)
     | `Building ->
-      sleep 30;
+      sleep 60;
       loop ()
     | `Complete ->
       ()
@@ -90,7 +94,7 @@ and rebuild_started pkg =
   target (file_contains_string specfile rebuild_name &&
             (match koji_build_state (fedora_verrel pkg branch) with
             | `Building | `Complete -> true
-            | `Deleted | `Failed | `Canceled -> false));
+            | `Deleted | `Failed | `Canceled | `No_such_build -> false));
 
   (* All dependent packages must have been fully rebuilt and in the
    * repo first.
@@ -100,8 +104,28 @@ and rebuild_started pkg =
   (* A local test build must succeed. *)
   require (local_build_succeeded pkg);
 
-  (* Rebuild the package in Koji, but don't wait. *)
-  koji_build ~wait:false pkg branch
+  (* Rebuild the package in Koji.  Don't wait ... *)
+  koji_build ~wait:false pkg branch;
+
+  (* ... but the build doesn't appear in Koji (eg. in 'koji
+   * buildinfo') until the SRPM has been built.  This can take quite
+   * some time.  Loop here until the build appears.
+   *)
+  let rec loop () =
+    match koji_build_state (fedora_verrel pkg branch) with
+    | `No_such_build ->
+      sleep 60;
+      loop ();
+    | `Building | `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 ()
 
 and local_build_succeeded pkg =
   (* The specfile must have been updated. *)
@@ -115,7 +139,7 @@ and local_build_succeeded pkg =
   (* Do a local test build to ensure the Koji build will work. *)
   sh "
     cd %s
-    sudo yum-builddep %s
+    sudo yum-builddep -y %s
     fedpkg local
   " (fedora_repo pkg branch)
     (fedora_specfile pkg branch);
@@ -126,13 +150,34 @@ and specfile_updated pkg =
   let repodir = fedora_repo pkg branch in
   let specfile = fedora_specfile pkg branch in
 
-  (* XXX Automate common changes. *)
-  let title = rebuild_name ^ " rebuild." in
   sh "
     cd %s
-    git pull --rebase
-    rm -rf x86_64 noarch *.src.rpm
-    rpmdev-bumpspec -c %s %s
+    rm -rf x86_64 noarch *.src.rpm .build* clog
+    git fetch
+  " repodir;
+
+  if not (git_has_local_changes repodir) then
+    sh "
+      cd %s
+      git pull --rebase
+    " repodir;
+
+  sh "sudo yum-builddep -y %s" specfile;
+
+  (* For rationale behind always bumping the spec file, see comment
+   * in 'fedora.ml'.
+   *)
+  let title =
+    if not (file_contains_string specfile rebuild_name) then
+      rebuild_name ^ " rebuild."
+    else
+      "Bump release and rebuild." in
+  sh "rpmdev-bumpspec -c %s %s" (quote title) specfile;
+
+  (* XXX Automate common specfile fixes. *)
+
+  sh "
+    cd %s
     echo 'Please make further changes as required to the spec file %s.spec'
     echo '(Press return key)'
     read
@@ -144,6 +189,5 @@ and specfile_updated pkg =
     read
     fedpkg push
   " repodir
-    (quote title) specfile
     pkg
     specfile