1 (* Perform a complete Fedora OCaml rebuild, in build order. *)
12 let side_tag = Some "f29-ocaml"
13 (*let side_tag = None*)
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.07.0 (final)"
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 (* File "compiler internals", line 1:
33 Error: Unbound module Stdlib *)
36 (* https://bugzilla.redhat.com/show_bug.cgi?id=1593408 *)
37 "ocamlify"; "ocaml-oasis";
39 let blocked pkg = List.mem pkg blocked
41 (* These packages are treated as if they have been rebuilt. *)
43 "ocaml-srpm-macros"; (* don't need to build this *)
44 "ocaml"; (* rebuilt by hand *)
46 let ignored pkg = List.mem pkg ignored
48 (* List of OCaml-related source package names. *)
53 [ -f \"$f/master/$f.spec\" ] && echo \"$f\"
56 dirs @ [ "alt-ergo"; "apron"; "brltty"; "coccinelle"; "coq";
57 "cduce"; "frama-c"; "gappalib-coq"; "graphviz"; "hevea"; "hivex";
58 "plplot"; "virt-top"; "why3"; "z3";
59 "flocq" (* no OCaml code, but needs to be rebuilt after Coq *);
60 "guestfs-browser"; "libguestfs" ]
62 (* Dependencies of each package. (pkg, [deps ...]) *)
63 let pkg_deps = dependencies branch source_packages
65 (* Remove blocked packages and packages which have a blocked package
66 * as a dependency (recursively).
69 let rec is_blocked pkg =
70 if blocked pkg then true
72 let deps = List.assoc pkg pkg_deps in
73 List.exists is_blocked deps
76 List.filter (fun pkg -> not (is_blocked pkg)) source_packages
78 (* Short the dependencies lists so that the build order is stable
82 List.map (fun (pkg, deps) -> pkg, List.sort compare deps) pkg_deps
84 (* Sort the source packages so that the packages with the largest
85 * number of reverse dependencies [other packages that depend on it]
86 * appear earlier in the list, on the basis that building these
87 * packages first has the greatest advantage.
92 fun (rdep, deps) -> if List.mem pkg deps then Some rdep else None
96 let r1 = rdeps p1 and r2 = rdeps p2 in
97 let n1 = List.length r1 and n2 = List.length r2 in
98 if n1 <> n2 then compare n2 n1 else compare p1 p2
100 List.sort cmp source_packages
103 printf "final list of source packages = %s\n%!"
104 (String.concat " " source_packages)
107 (* We could make this a goal, but it's cheap enough to run it unconditionally. *)
108 let install_build_dependencies pkg =
109 sh "sudo yum clean all --disablerepo=\\* --enablerepo=%s"
111 sh "sudo yum-builddep -y --disablerepo=\\* --enablerepo=%s %s"
112 (quote yum_repo) (fedora_specfile pkg branch)
115 (* Unset MAKEFLAGS so it doesn't affect local builds. *)
116 let () = Unix.putenv "MAKEFLAGS" ""
118 (* Goal: rebuild all packages. *)
119 let rec goal all () =
120 let n = List.length source_packages in
123 require (rebuild_started pkg);
124 printf "*** *** rebuilt %d/%d packages *** ***\n%!" (i+1) n
127 (* Goal: That 'package' has been rebuilt and exists in Koji. *)
129 let specfile = fedora_specfile pkg branch in
131 (* Note: verrel may change as we go along, so don't assign it to
135 (* Note the target must be both of these because the old verrel
136 * could exist as a koji build without it having been part of the
139 target (ignored pkg ||
140 (file_contains_string specfile rebuild_name &&
141 koji_build_state (fedora_verrel pkg branch) == `Complete));
143 (* Ignored packages are treated as if they have been rebuilt. *)
144 if not (ignored pkg) then (
146 (* Start the rebuild. *)
147 require (rebuild_started pkg);
149 (* Wait for the build state to reach a conclusion. *)
151 match koji_build_state (fedora_verrel pkg branch) with
153 failwith (sprintf "rebuild of package %s: no build found" pkg)
160 failwith (sprintf "rebuild of package %s: deleted" pkg)
162 failwith (sprintf "rebuild of package %s: failed" pkg)
164 failwith (sprintf "rebuild of package %s: canceled" pkg)
168 (* Wait for the build to appear in Koji repo. *)
169 koji_wait_repo koji_target (fedora_verrel pkg branch)
172 (* Goal: The rebuild of the package has started, but we haven't waited
175 and rebuild_started pkg =
176 let deps = List.assoc pkg pkg_deps in
177 let specfile = fedora_specfile pkg branch in
179 (* Note the target must be both of these because the old verrel
180 * could exist as a koji build without it having been part of the
183 target (ignored pkg ||
184 (file_contains_string specfile rebuild_name &&
185 (match koji_build_state (fedora_verrel pkg branch) with
186 | `Building | `Complete -> true
187 | `Deleted | `Failed | `Canceled | `No_such_build -> false)));
189 (* All dependent packages must have been fully rebuilt and in the
192 List.iter (fun dep -> require (rebuilt dep)) deps;
194 (* Ignored packages are treated as if they have been rebuilt. *)
195 if not (ignored pkg) then (
197 (* A local test build must succeed. *)
198 require (local_build_succeeded pkg);
200 (* local_build_succeeded normally does this ... *)
201 require (specfile_updated pkg);
203 (* Rebuild the package in Koji. Don't wait ... *)
204 koji_build ~wait:false ?side_tag pkg branch;
206 (* ... but the build doesn't appear in Koji (eg. in 'koji
207 * buildinfo') until the SRPM has been built. This can take quite
208 * some time. Loop here until the build appears.
211 match koji_build_state (fedora_verrel pkg branch) with
215 | `Building | `Complete ->
218 failwith (sprintf "rebuild of package %s: deleted" pkg)
220 failwith (sprintf "rebuild of package %s: failed" pkg)
222 failwith (sprintf "rebuild of package %s: canceled" pkg)
228 and local_build_succeeded pkg =
229 (* The specfile must have been updated. *)
230 require (specfile_updated pkg);
233 sprintf "fedora_ocaml_local_build_%s_%s" pkg (fedora_verrel pkg branch) in
235 target (memory_exists key);
237 install_build_dependencies pkg;
239 (* Do a local test build to ensure the Koji build will work. *)
243 " (fedora_repo pkg branch);
248 and specfile_updated pkg =
249 let repodir = fedora_repo pkg branch in
250 let specfile = fedora_specfile pkg branch in
254 rm -rf x86_64 noarch *.src.rpm .build* clog
258 if not (git_has_local_changes repodir) then
264 (* - XXX why did we do this here?
265 install_build_dependencies pkg;
268 (* For rationale behind always bumping the spec file, see comment
272 if not (file_contains_string specfile rebuild_name) then
273 rebuild_name ^ " rebuild."
275 "Bump release and rebuild." in
276 sh "rpmdev-bumpspec -c %s %s" (quote title) specfile;
278 (* XXX Automate common specfile fixes. *)