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 *)
35 let blocked pkg = List.mem pkg blocked
37 (* These packages are treated as if they have been rebuilt. *)
39 "ocaml-srpm-macros"; (* don't need to build this *)
40 "ocaml"; (* rebuilt by hand *)
42 let ignored pkg = List.mem pkg ignored
44 (* List of OCaml-related source package names. *)
49 [ -f \"$f/master/$f.spec\" ] && echo \"$f\"
52 dirs @ [ "alt-ergo"; "apron"; "brltty"; "coccinelle"; "coq";
53 "cduce"; "frama-c"; "gappalib-coq"; "graphviz"; "hevea"; "hivex";
54 "opam"; "plplot"; "virt-top"; "why3"; "z3";
55 "flocq" (* no OCaml code, but needs to be rebuilt after Coq *);
56 "guestfs-browser"; "libguestfs" ]
58 (* Dependencies of each package. (pkg, [deps ...]) *)
59 let pkg_deps = dependencies branch source_packages
61 (* Remove blocked packages and packages which have a blocked package
62 * as a dependency (recursively).
65 let rec is_blocked pkg =
66 if blocked pkg then true
68 let deps = List.assoc pkg pkg_deps in
69 List.exists is_blocked deps
72 List.filter (fun pkg -> not (is_blocked pkg)) source_packages
74 (* Short the dependencies lists so that the build order is stable
78 List.map (fun (pkg, deps) -> pkg, List.sort compare deps) pkg_deps
80 (* Sort the source packages so that the packages with the largest
81 * number of reverse dependencies [other packages that depend on it]
82 * appear earlier in the list, on the basis that building these
83 * packages first has the greatest advantage.
88 fun (rdep, deps) -> if List.mem pkg deps then Some rdep else None
92 let r1 = rdeps p1 and r2 = rdeps p2 in
93 let n1 = List.length r1 and n2 = List.length r2 in
94 if n1 <> n2 then compare n2 n1 else compare p1 p2
96 List.sort cmp source_packages
99 printf "final list of source packages = %s\n%!"
100 (String.concat " " source_packages)
103 (* We could make this a goal, but it's cheap enough to run it unconditionally. *)
104 let install_build_dependencies pkg =
105 sh "sudo yum clean all --disablerepo=\\* --enablerepo=%s"
107 sh "sudo yum-builddep -y --disablerepo=\\* --enablerepo=%s %s"
108 (quote yum_repo) (fedora_specfile pkg branch)
111 (* Unset MAKEFLAGS so it doesn't affect local builds. *)
112 let () = Unix.putenv "MAKEFLAGS" ""
114 (* Goal: rebuild all packages. *)
115 let rec goal all () =
116 let n = List.length source_packages in
119 require (rebuild_started pkg);
120 printf "*** *** rebuilt %d/%d packages *** ***\n%!" (i+1) n
123 (* Goal: That 'package' has been rebuilt and exists in Koji. *)
125 let specfile = fedora_specfile pkg branch in
127 (* Note: verrel may change as we go along, so don't assign it to
131 (* Note the target must be both of these because the old verrel
132 * could exist as a koji build without it having been part of the
135 target (ignored pkg ||
136 (file_contains_string specfile rebuild_name &&
137 koji_build_state (fedora_verrel pkg branch) == `Complete));
139 (* Ignored packages are treated as if they have been rebuilt. *)
140 if not (ignored pkg) then (
142 (* Start the rebuild. *)
143 require (rebuild_started pkg);
145 (* Wait for the build state to reach a conclusion. *)
147 match koji_build_state (fedora_verrel pkg branch) with
149 failwith (sprintf "rebuild of package %s: no build found" pkg)
156 failwith (sprintf "rebuild of package %s: deleted" pkg)
158 failwith (sprintf "rebuild of package %s: failed" pkg)
160 failwith (sprintf "rebuild of package %s: canceled" pkg)
164 (* Wait for the build to appear in Koji repo. *)
165 koji_wait_repo koji_target (fedora_verrel pkg branch)
168 (* Goal: The rebuild of the package has started, but we haven't waited
171 and rebuild_started pkg =
172 let deps = List.assoc pkg pkg_deps in
173 let specfile = fedora_specfile pkg branch in
175 (* Note the target must be both of these because the old verrel
176 * could exist as a koji build without it having been part of the
179 target (ignored pkg ||
180 (file_contains_string specfile rebuild_name &&
181 (match koji_build_state (fedora_verrel pkg branch) with
182 | `Building | `Complete -> true
183 | `Deleted | `Failed | `Canceled | `No_such_build -> false)));
185 (* All dependent packages must have been fully rebuilt and in the
188 List.iter (fun dep -> require (rebuilt dep)) deps;
190 (* Ignored packages are treated as if they have been rebuilt. *)
191 if not (ignored pkg) then (
193 (* A local test build must succeed. *)
194 require (local_build_succeeded pkg);
196 (* local_build_succeeded normally does this ... *)
197 require (specfile_updated pkg);
199 (* Rebuild the package in Koji. Don't wait ... *)
200 koji_build ~wait:false ?side_tag pkg branch;
202 (* ... but the build doesn't appear in Koji (eg. in 'koji
203 * buildinfo') until the SRPM has been built. This can take quite
204 * some time. Loop here until the build appears.
207 match koji_build_state (fedora_verrel pkg branch) with
211 | `Building | `Complete ->
214 failwith (sprintf "rebuild of package %s: deleted" pkg)
216 failwith (sprintf "rebuild of package %s: failed" pkg)
218 failwith (sprintf "rebuild of package %s: canceled" pkg)
224 and local_build_succeeded pkg =
225 (* The specfile must have been updated. *)
226 require (specfile_updated pkg);
229 sprintf "fedora_ocaml_local_build_%s_%s" pkg (fedora_verrel pkg branch) in
231 target (memory_exists key);
233 install_build_dependencies pkg;
235 (* Do a local test build to ensure the Koji build will work. *)
239 " (fedora_repo pkg branch);
244 and specfile_updated pkg =
245 let repodir = fedora_repo pkg branch in
246 let specfile = fedora_specfile pkg branch in
250 rm -rf x86_64 noarch *.src.rpm .build* clog
254 if not (git_has_local_changes repodir) then
260 (* - XXX why did we do this here?
261 install_build_dependencies pkg;
264 (* For rationale behind always bumping the spec file, see comment
268 if not (file_contains_string specfile rebuild_name) then
269 rebuild_name ^ " rebuild."
271 "Bump release and rebuild." in
272 sh "rpmdev-bumpspec -c %s %s" (quote title) specfile;
274 (* XXX Automate common specfile fixes. *)