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 let blocked pkg = List.mem pkg blocked
38 (* These packages are treated as if they have been rebuilt. *)
40 "ocaml-srpm-macros"; (* don't need to build this *)
41 "ocaml"; (* rebuilt by hand *)
43 let ignored pkg = List.mem pkg ignored
45 (* List of OCaml-related source package names. *)
50 [ -f \"$f/master/$f.spec\" ] && echo \"$f\"
53 dirs @ [ "alt-ergo"; "apron"; "brltty"; "coccinelle"; "coq";
54 "cduce"; "frama-c"; "gappalib-coq"; "graphviz"; "hevea"; "hivex";
55 "plplot"; "virt-top"; "why3"; "z3";
56 "flocq" (* no OCaml code, but needs to be rebuilt after Coq *);
57 "guestfs-browser"; "libguestfs" ]
59 (* Dependencies of each package. (pkg, [deps ...]) *)
60 let pkg_deps = dependencies branch source_packages
62 (* Remove blocked packages and packages which have a blocked package
63 * as a dependency (recursively).
66 let rec is_blocked pkg =
67 if blocked pkg then true
69 let deps = List.assoc pkg pkg_deps in
70 List.exists is_blocked deps
73 List.filter (fun pkg -> not (is_blocked pkg)) source_packages
75 (* Short the dependencies lists so that the build order is stable
79 List.map (fun (pkg, deps) -> pkg, List.sort compare deps) pkg_deps
81 (* Sort the source packages so that the packages with the largest
82 * number of reverse dependencies [other packages that depend on it]
83 * appear earlier in the list, on the basis that building these
84 * packages first has the greatest advantage.
89 fun (rdep, deps) -> if List.mem pkg deps then Some rdep else None
93 let r1 = rdeps p1 and r2 = rdeps p2 in
94 let n1 = List.length r1 and n2 = List.length r2 in
95 if n1 <> n2 then compare n2 n1 else compare p1 p2
97 List.sort cmp source_packages
100 printf "final list of source packages = %s\n%!"
101 (String.concat " " source_packages)
104 (* We could make this a goal, but it's cheap enough to run it unconditionally. *)
105 let install_build_dependencies pkg =
106 sh "sudo yum clean all --disablerepo=\\* --enablerepo=%s"
108 sh "sudo yum-builddep -y --disablerepo=\\* --enablerepo=%s %s"
109 (quote yum_repo) (fedora_specfile pkg branch)
112 (* Unset MAKEFLAGS so it doesn't affect local builds. *)
113 let () = Unix.putenv "MAKEFLAGS" ""
115 (* Goal: rebuild all packages. *)
116 let rec goal all () =
117 let n = List.length source_packages in
120 require (rebuild_started pkg);
121 printf "*** *** rebuilt %d/%d packages *** ***\n%!" (i+1) n
124 (* Goal: That 'package' has been rebuilt and exists in Koji. *)
126 let specfile = fedora_specfile pkg branch in
128 (* Note: verrel may change as we go along, so don't assign it to
132 (* Note the target must be both of these because the old verrel
133 * could exist as a koji build without it having been part of the
136 target (ignored pkg ||
137 (file_contains_string specfile rebuild_name &&
138 koji_build_state (fedora_verrel pkg branch) == `Complete));
140 (* Ignored packages are treated as if they have been rebuilt. *)
141 if not (ignored pkg) then (
143 (* Start the rebuild. *)
144 require (rebuild_started pkg);
146 (* Wait for the build state to reach a conclusion. *)
148 match koji_build_state (fedora_verrel pkg branch) with
150 failwith (sprintf "rebuild of package %s: no build found" pkg)
157 failwith (sprintf "rebuild of package %s: deleted" pkg)
159 failwith (sprintf "rebuild of package %s: failed" pkg)
161 failwith (sprintf "rebuild of package %s: canceled" pkg)
165 (* Wait for the build to appear in Koji repo. *)
166 koji_wait_repo koji_target (fedora_verrel pkg branch)
169 (* Goal: The rebuild of the package has started, but we haven't waited
172 and rebuild_started pkg =
173 let deps = List.assoc pkg pkg_deps in
174 let specfile = fedora_specfile pkg branch in
176 (* Note the target must be both of these because the old verrel
177 * could exist as a koji build without it having been part of the
180 target (ignored pkg ||
181 (file_contains_string specfile rebuild_name &&
182 (match koji_build_state (fedora_verrel pkg branch) with
183 | `Building | `Complete -> true
184 | `Deleted | `Failed | `Canceled | `No_such_build -> false)));
186 (* All dependent packages must have been fully rebuilt and in the
189 List.iter (fun dep -> require (rebuilt dep)) deps;
191 (* Ignored packages are treated as if they have been rebuilt. *)
192 if not (ignored pkg) then (
194 (* A local test build must succeed. *)
195 require (local_build_succeeded pkg);
197 (* local_build_succeeded normally does this ... *)
198 require (specfile_updated pkg);
200 (* Rebuild the package in Koji. Don't wait ... *)
201 koji_build ~wait:false ?side_tag pkg branch;
203 (* ... but the build doesn't appear in Koji (eg. in 'koji
204 * buildinfo') until the SRPM has been built. This can take quite
205 * some time. Loop here until the build appears.
208 match koji_build_state (fedora_verrel pkg branch) with
212 | `Building | `Complete ->
215 failwith (sprintf "rebuild of package %s: deleted" pkg)
217 failwith (sprintf "rebuild of package %s: failed" pkg)
219 failwith (sprintf "rebuild of package %s: canceled" pkg)
225 and local_build_succeeded pkg =
226 (* The specfile must have been updated. *)
227 require (specfile_updated pkg);
230 sprintf "fedora_ocaml_local_build_%s_%s" pkg (fedora_verrel pkg branch) in
232 target (memory_exists key);
234 install_build_dependencies pkg;
236 (* Do a local test build to ensure the Koji build will work. *)
240 " (fedora_repo pkg branch);
245 and specfile_updated pkg =
246 let repodir = fedora_repo pkg branch in
247 let specfile = fedora_specfile pkg branch in
251 rm -rf x86_64 noarch *.src.rpm .build* clog
255 if not (git_has_local_changes repodir) then
261 (* - XXX why did we do this here?
262 install_build_dependencies pkg;
265 (* For rationale behind always bumping the spec file, see comment
269 if not (file_contains_string specfile rebuild_name) then
270 rebuild_name ^ " rebuild."
272 "Bump release and rebuild." in
273 sh "rpmdev-bumpspec -c %s %s" (quote title) specfile;
275 (* XXX Automate common specfile fixes. *)