1 (* Perform a complete Fedora OCaml rebuild, in build order. *)
12 let koji_target = "rawhide"
14 (* The name of the rebuild, and also the magic substring that must
15 * appear in the %changelog when the package has been rebuilt.
17 let rebuild_name = "ocaml-4.02.1"
19 (* Local repository that contains build dependencies. *)
20 let yum_repo = "koji-rawhide"
22 (* Packages that have problems. These block the packages and all
26 "ocaml-pa-do"; (* orphaned *)
27 "llvm"; (* FTBFS, unrelated to OCaml *)
28 "plplot"; (* FTBFS, unrelated to OCaml *)
30 let blocked pkg = List.mem pkg blocked
32 (* These packages are treated as if they have been rebuilt. *)
34 "ocaml-srpm-macros"; (* don't need to build this *)
35 "ocaml"; (* rebuilt by hand *)
36 "whenjobs"; (* obsolete *)
38 let ignored pkg = List.mem pkg ignored
40 (* List of OCaml-related source package names. *)
42 let dirs = shlines "cd %s && ls -1d ocaml*" fedora_dir in
43 dirs @ [ "alt-ergo"; "apron"; "brltty"; "coccinelle"; "coq";
44 "cduce"; "frama-c"; "gappalib-coq"; "graphviz"; "hevea"; "hivex";
45 "js-of-ocaml"; "llvm"; "plplot"; "virt-top"; "why3";
46 "flocq" (* no OCaml code, but needs to be rebuilt after Coq *);
47 "guestfs-browser"; "libguestfs";
50 (* Dependencies of each package. (pkg, [deps ...]) *)
51 let pkg_deps = dependencies branch source_packages
53 (* Remove blocked packages and packages which have a blocked package
54 * as a dependency (recursively).
57 let rec is_blocked pkg =
58 if blocked pkg then true
60 let deps = List.assoc pkg pkg_deps in
61 List.exists is_blocked deps
64 List.filter (fun pkg -> not (is_blocked pkg)) source_packages
66 (* Short the dependencies lists so that the build order is stable
70 List.map (fun (pkg, deps) -> pkg, List.sort compare deps) pkg_deps
72 (* Sort the source packages so that the packages with the largest
73 * number of reverse dependencies [other packages that depend on it]
74 * appear earlier in the list, on the basis that building these
75 * packages first has the greatest advantage.
80 fun (rdep, deps) -> if List.mem pkg deps then Some rdep else None
84 let r1 = rdeps p1 and r2 = rdeps p2 in
85 let n1 = List.length r1 and n2 = List.length r2 in
86 if n1 <> n2 then compare n2 n1 else compare p1 p2
88 List.sort cmp source_packages
91 printf "final list of source packages = %s\n%!"
92 (String.concat " " source_packages)
94 (* We could make this a goal, but it's cheap enough to run it unconditionally. *)
95 let install_build_dependencies pkg =
96 sh "sudo yum clean all --disablerepo=\\* --enablerepo=%s"
98 sh "sudo yum-builddep -y --disablerepo=\\* --enablerepo=%s %s"
99 (quote yum_repo) (fedora_specfile pkg branch)
101 (* Unset MAKEFLAGS so it doesn't affect local builds. *)
102 let () = Unix.putenv "MAKEFLAGS" ""
104 (* Goal: rebuild all packages. *)
105 let rec goal all () =
106 let n = List.length source_packages in
109 require (rebuild_started pkg);
110 printf "*** *** rebuilt %d/%d packages *** ***\n%!" (i+1) n
113 (* Goal: That 'package' has been rebuilt and exists in Koji. *)
115 let specfile = fedora_specfile pkg branch in
117 (* Note: verrel may change as we go along, so don't assign it to
121 (* Note the target must be both of these because the old verrel
122 * could exist as a koji build without it having been part of the
125 target (ignored pkg ||
126 (file_contains_string specfile rebuild_name &&
127 koji_build_state (fedora_verrel pkg branch) == `Complete));
129 (* Ignored packages are treated as if they have been rebuilt. *)
130 if not (ignored pkg) then (
132 (* Start the rebuild. *)
133 require (rebuild_started pkg);
135 (* Wait for the build state to reach a conclusion. *)
137 match koji_build_state (fedora_verrel pkg branch) with
139 failwith (sprintf "rebuild of package %s: no build found" pkg)
146 failwith (sprintf "rebuild of package %s: deleted" pkg)
148 failwith (sprintf "rebuild of package %s: failed" pkg)
150 failwith (sprintf "rebuild of package %s: canceled" pkg)
154 (* Wait for the build to appear in Koji repo. *)
155 koji_wait_repo koji_target (fedora_verrel pkg branch)
158 (* Goal: The rebuild of the package has started, but we haven't waited
161 and rebuild_started pkg =
162 let deps = List.assoc pkg pkg_deps in
163 let specfile = fedora_specfile pkg branch in
165 (* Note the target must be both of these because the old verrel
166 * could exist as a koji build without it having been part of the
169 target (ignored pkg ||
170 (file_contains_string specfile rebuild_name &&
171 (match koji_build_state (fedora_verrel pkg branch) with
172 | `Building | `Complete -> true
173 | `Deleted | `Failed | `Canceled | `No_such_build -> false)));
175 (* All dependent packages must have been fully rebuilt and in the
178 List.iter (fun dep -> require (rebuilt dep)) deps;
180 (* Ignored packages are treated as if they have been rebuilt. *)
181 if not (ignored pkg) then (
183 (* A local test build must succeed. *)
184 require (local_build_succeeded pkg);
186 (* local_build_succeeded normally does this ... *)
187 require (specfile_updated pkg);
189 (* Rebuild the package in Koji. Don't wait ... *)
190 koji_build ~wait:false pkg branch;
192 (* ... but the build doesn't appear in Koji (eg. in 'koji
193 * buildinfo') until the SRPM has been built. This can take quite
194 * some time. Loop here until the build appears.
197 match koji_build_state (fedora_verrel pkg branch) with
201 | `Building | `Complete ->
204 failwith (sprintf "rebuild of package %s: deleted" pkg)
206 failwith (sprintf "rebuild of package %s: failed" pkg)
208 failwith (sprintf "rebuild of package %s: canceled" pkg)
214 and local_build_succeeded pkg =
215 (* The specfile must have been updated. *)
216 require (specfile_updated pkg);
219 sprintf "fedora_ocaml_local_build_%s_%s" pkg (fedora_verrel pkg branch) in
221 target (memory_exists key);
223 install_build_dependencies pkg;
225 (* Do a local test build to ensure the Koji build will work. *)
229 " (fedora_repo pkg branch);
234 and specfile_updated pkg =
235 let repodir = fedora_repo pkg branch in
236 let specfile = fedora_specfile pkg branch in
240 rm -rf x86_64 noarch *.src.rpm .build* clog
244 if not (git_has_local_changes repodir) then
250 (* - XXX why did we do this here?
251 install_build_dependencies pkg;
254 (* For rationale behind always bumping the spec file, see comment
258 if not (file_contains_string specfile rebuild_name) then
259 rebuild_name ^ " rebuild."
261 "Bump release and rebuild." in
262 sh "rpmdev-bumpspec -c %s %s" (quote title) specfile;
264 (* XXX Automate common specfile fixes. *)