1 (* Perform a complete Fedora OCaml rebuild, in build order. *)
12 (*let side_tag = Some "f31-ocaml"*)
20 (* The name of the rebuild, and also the magic substring that must
21 * appear in the %changelog when the package has been rebuilt.
23 let rebuild_name = "OCaml 4.08.1 (rc2)"
25 (* Local repository that contains build dependencies. *)
26 let yum_repo = "koji-rawhide"
28 (* Packages that have problems. These block the packages and all
32 "ocaml-camlp4"; (* deprecated + all dependent packages *)
33 "ocaml-yojson"; (* jjames is looking at this *)
34 "ocaml-dose3"; (* requires ocaml-seq, see 1735476 & 1735629 *)
35 "coq"; (* RHBZ#1735619 *)
37 let blocked pkg = List.mem pkg blocked
39 (* These packages are treated as if they have been rebuilt. *)
41 "ocaml-srpm-macros"; (* don't need to build this *)
42 "ocaml"; (* rebuilt by hand *)
44 let ignored pkg = List.mem pkg ignored
46 (* List of OCaml-related source package names. *)
51 [ -f \"$f/master/$f.spec\" ] && echo \"$f\"
54 dirs @ [ "alt-ergo"; "apron"; "brltty"; "coccinelle"; "coq";
55 "cduce"; "freetennis";
56 "frama-c"; "gappalib-coq"; "graphviz"; "hevea"; "hivex";
57 "opam"; "plplot"; "virt-top"; "why3"; "z3";
58 "flocq" (* no OCaml code, but needs to be rebuilt after Coq *);
59 "guestfs-browser"; "libguestfs" ]
61 (* Dependencies of each package. (pkg, [deps ...]) *)
62 let pkg_deps = dependencies branch source_packages
64 (* Remove blocked packages and packages which have a blocked package
65 * as a dependency (recursively).
68 let rec is_blocked pkg =
69 if blocked pkg then true
71 let deps = List.assoc pkg pkg_deps in
72 List.exists is_blocked deps
75 List.filter (fun pkg -> not (is_blocked pkg)) source_packages
77 (* Short the dependencies lists so that the build order is stable
81 List.map (fun (pkg, deps) -> pkg, List.sort compare deps) pkg_deps
83 (* Sort the source packages so that the packages with the largest
84 * number of reverse dependencies [other packages that depend on it]
85 * appear earlier in the list, on the basis that building these
86 * packages first has the greatest advantage.
91 fun (rdep, deps) -> if List.mem pkg deps then Some rdep else None
95 let r1 = rdeps p1 and r2 = rdeps p2 in
96 let n1 = List.length r1 and n2 = List.length r2 in
97 if n1 <> n2 then compare n2 n1 else compare p1 p2
99 List.sort cmp source_packages
102 printf "final list of source packages = %s\n%!"
103 (String.concat " " source_packages)
106 (* We could make this a goal, but it's cheap enough to run it unconditionally. *)
107 let install_build_dependencies pkg =
108 sh "sudo yum clean all --disablerepo=\\* --enablerepo=%s"
110 sh "sudo yum-builddep -y --disablerepo=\\* --enablerepo=%s %s"
111 (quote yum_repo) (fedora_specfile pkg branch)
114 (* Unset MAKEFLAGS so it doesn't affect local builds. *)
115 let () = Unix.putenv "MAKEFLAGS" ""
117 (* Goal: rebuild all packages. *)
118 let rec goal all () =
119 let n = List.length source_packages in
122 require (rebuild_started pkg);
123 printf "*** *** rebuilt %d/%d packages *** ***\n%!" (i+1) n
126 (* Goal: That 'package' has been rebuilt and exists in Koji. *)
128 let specfile = fedora_specfile pkg branch in
130 (* Note: verrel may change as we go along, so don't assign it to
134 (* Note the target must be both of these because the old verrel
135 * could exist as a koji build without it having been part of the
138 target (ignored pkg ||
139 (file_contains_string specfile rebuild_name &&
140 koji_build_state (fedora_verrel pkg branch) == `Complete));
142 (* Ignored packages are treated as if they have been rebuilt. *)
143 if not (ignored pkg) then (
145 (* Start the rebuild. *)
146 require (rebuild_started pkg);
148 (* Wait for the build state to reach a conclusion. *)
150 match koji_build_state (fedora_verrel pkg branch) with
152 failwith (sprintf "rebuild of package %s: no build found" pkg)
159 failwith (sprintf "rebuild of package %s: deleted" pkg)
161 failwith (sprintf "rebuild of package %s: failed" pkg)
163 failwith (sprintf "rebuild of package %s: canceled" pkg)
167 (* Wait for the build to appear in Koji repo. *)
168 koji_wait_repo koji_target (fedora_verrel pkg branch)
171 (* Goal: The rebuild of the package has started, but we haven't waited
174 and rebuild_started pkg =
175 let deps = List.assoc pkg pkg_deps in
176 let specfile = fedora_specfile pkg branch in
178 (* Note the target must be both of these because the old verrel
179 * could exist as a koji build without it having been part of the
182 target (ignored pkg ||
183 (file_contains_string specfile rebuild_name &&
184 (match koji_build_state (fedora_verrel pkg branch) with
185 | `Building | `Complete -> true
186 | `Deleted | `Failed | `Canceled | `No_such_build -> false)));
188 (* All dependent packages must have been fully rebuilt and in the
191 List.iter (fun dep -> require (rebuilt dep)) deps;
193 (* Ignored packages are treated as if they have been rebuilt. *)
194 if not (ignored pkg) then (
196 (* A local test build must succeed. *)
197 require (local_build_succeeded pkg);
199 (* local_build_succeeded normally does this ... *)
200 require (specfile_updated pkg);
202 (* Rebuild the package in Koji. Don't wait ... *)
203 koji_build ~wait:false ?side_tag pkg branch;
205 (* ... but the build doesn't appear in Koji (eg. in 'koji
206 * buildinfo') until the SRPM has been built. This can take quite
207 * some time. Loop here until the build appears.
210 match koji_build_state (fedora_verrel pkg branch) with
214 | `Building | `Complete ->
217 failwith (sprintf "rebuild of package %s: deleted" pkg)
219 failwith (sprintf "rebuild of package %s: failed" pkg)
221 failwith (sprintf "rebuild of package %s: canceled" pkg)
227 and local_build_succeeded pkg =
228 (* The specfile must have been updated. *)
229 require (specfile_updated pkg);
232 sprintf "fedora_ocaml_local_build_%s_%s" pkg (fedora_verrel pkg branch) in
234 target (memory_exists key);
236 install_build_dependencies pkg;
238 (* Do a local test build to ensure the Koji build will work. *)
242 " (fedora_repo pkg branch);
247 and specfile_updated pkg =
248 let repodir = fedora_repo pkg branch in
249 let specfile = fedora_specfile pkg branch in
253 rm -rf x86_64 noarch *.src.rpm .build* clog
257 if not (git_has_local_changes repodir) then
263 (* - XXX why did we do this here?
264 install_build_dependencies pkg;
267 (* For rationale behind always bumping the spec file, see comment
271 if not (file_contains_string specfile rebuild_name) then
272 rebuild_name ^ " rebuild."
274 "Bump release and rebuild." in
275 sh "rpmdev-bumpspec -c %s %s" (quote title) specfile;
277 (* XXX Automate common specfile fixes. *)