1 (* Perform a complete Fedora OCaml rebuild, in build order. *)
12 let side_tag = Some "f24-ocaml"
19 (* The name of the rebuild, and also the magic substring that must
20 * appear in the %changelog when the package has been rebuilt.
22 let rebuild_name = "OCaml 4.02.3"
24 (* Local repository that contains build dependencies. *)
25 let yum_repo = "koji-rawhide"
27 (* Packages that have problems. These block the packages and all
31 "ocaml-pa-do"; (* orphaned *)
32 "ocaml-camlp5"; (* not updated to 4.02.3 yet *)
34 let blocked pkg = List.mem pkg blocked
36 (* These packages are treated as if they have been rebuilt. *)
38 "ocaml-srpm-macros"; (* don't need to build this *)
39 "ocaml"; (* rebuilt by hand *)
40 "whenjobs"; (* obsolete *)
42 let ignored pkg = List.mem pkg ignored
44 (* List of OCaml-related source package names. *)
46 let dirs = shlines "cd %s && ls -1d ocaml*" fedora_dir in
47 dirs @ [ "alt-ergo"; "apron"; "brltty"; "coccinelle"; "coq";
48 "cduce"; "frama-c"; "gappalib-coq"; "graphviz"; "hevea"; "hivex";
49 "js-of-ocaml"; "plplot"; "virt-top"; "why3"; "z3";
50 "flocq" (* no OCaml code, but needs to be rebuilt after Coq *);
51 "guestfs-browser"; "libguestfs";
54 (* Dependencies of each package. (pkg, [deps ...]) *)
55 let pkg_deps = dependencies branch source_packages
57 (* Remove blocked packages and packages which have a blocked package
58 * as a dependency (recursively).
61 let rec is_blocked pkg =
62 if blocked pkg then true
64 let deps = List.assoc pkg pkg_deps in
65 List.exists is_blocked deps
68 List.filter (fun pkg -> not (is_blocked pkg)) source_packages
70 (* Short the dependencies lists so that the build order is stable
74 List.map (fun (pkg, deps) -> pkg, List.sort compare deps) pkg_deps
76 (* Sort the source packages so that the packages with the largest
77 * number of reverse dependencies [other packages that depend on it]
78 * appear earlier in the list, on the basis that building these
79 * packages first has the greatest advantage.
84 fun (rdep, deps) -> if List.mem pkg deps then Some rdep else None
88 let r1 = rdeps p1 and r2 = rdeps p2 in
89 let n1 = List.length r1 and n2 = List.length r2 in
90 if n1 <> n2 then compare n2 n1 else compare p1 p2
92 List.sort cmp source_packages
95 printf "final list of source packages = %s\n%!"
96 (String.concat " " source_packages)
99 (* We could make this a goal, but it's cheap enough to run it unconditionally. *)
100 let install_build_dependencies pkg =
101 sh "sudo yum clean all --disablerepo=\\* --enablerepo=%s"
103 sh "sudo yum-builddep -y --disablerepo=\\* --enablerepo=%s %s"
104 (quote yum_repo) (fedora_specfile pkg branch)
107 (* Unset MAKEFLAGS so it doesn't affect local builds. *)
108 let () = Unix.putenv "MAKEFLAGS" ""
110 (* Goal: rebuild all packages. *)
111 let rec goal all () =
112 let n = List.length source_packages in
115 require (rebuild_started pkg);
116 printf "*** *** rebuilt %d/%d packages *** ***\n%!" (i+1) n
119 (* Goal: That 'package' has been rebuilt and exists in Koji. *)
121 let specfile = fedora_specfile pkg branch in
123 (* Note: verrel may change as we go along, so don't assign it to
127 (* Note the target must be both of these because the old verrel
128 * could exist as a koji build without it having been part of the
131 target (ignored pkg ||
132 (file_contains_string specfile rebuild_name &&
133 koji_build_state (fedora_verrel pkg branch) == `Complete));
135 (* Ignored packages are treated as if they have been rebuilt. *)
136 if not (ignored pkg) then (
138 (* Start the rebuild. *)
139 require (rebuild_started pkg);
141 (* Wait for the build state to reach a conclusion. *)
143 match koji_build_state (fedora_verrel pkg branch) with
145 failwith (sprintf "rebuild of package %s: no build found" pkg)
152 failwith (sprintf "rebuild of package %s: deleted" pkg)
154 failwith (sprintf "rebuild of package %s: failed" pkg)
156 failwith (sprintf "rebuild of package %s: canceled" pkg)
160 (* Wait for the build to appear in Koji repo. *)
161 koji_wait_repo koji_target (fedora_verrel pkg branch)
164 (* Goal: The rebuild of the package has started, but we haven't waited
167 and rebuild_started pkg =
168 let deps = List.assoc pkg pkg_deps in
169 let specfile = fedora_specfile pkg branch in
171 (* Note the target must be both of these because the old verrel
172 * could exist as a koji build without it having been part of the
175 target (ignored pkg ||
176 (file_contains_string specfile rebuild_name &&
177 (match koji_build_state (fedora_verrel pkg branch) with
178 | `Building | `Complete -> true
179 | `Deleted | `Failed | `Canceled | `No_such_build -> false)));
181 (* All dependent packages must have been fully rebuilt and in the
184 List.iter (fun dep -> require (rebuilt dep)) deps;
186 (* Ignored packages are treated as if they have been rebuilt. *)
187 if not (ignored pkg) then (
189 (* A local test build must succeed. *)
190 require (local_build_succeeded pkg);
192 (* local_build_succeeded normally does this ... *)
193 require (specfile_updated pkg);
195 (* Rebuild the package in Koji. Don't wait ... *)
196 koji_build ~wait:false ?side_tag pkg branch;
198 (* ... but the build doesn't appear in Koji (eg. in 'koji
199 * buildinfo') until the SRPM has been built. This can take quite
200 * some time. Loop here until the build appears.
203 match koji_build_state (fedora_verrel pkg branch) with
207 | `Building | `Complete ->
210 failwith (sprintf "rebuild of package %s: deleted" pkg)
212 failwith (sprintf "rebuild of package %s: failed" pkg)
214 failwith (sprintf "rebuild of package %s: canceled" pkg)
220 and local_build_succeeded pkg =
221 (* The specfile must have been updated. *)
222 require (specfile_updated pkg);
225 sprintf "fedora_ocaml_local_build_%s_%s" pkg (fedora_verrel pkg branch) in
227 target (memory_exists key);
229 install_build_dependencies pkg;
231 (* Do a local test build to ensure the Koji build will work. *)
235 " (fedora_repo pkg branch);
240 and specfile_updated pkg =
241 let repodir = fedora_repo pkg branch in
242 let specfile = fedora_specfile pkg branch in
246 rm -rf x86_64 noarch *.src.rpm .build* clog
250 if not (git_has_local_changes repodir) then
256 (* - XXX why did we do this here?
257 install_build_dependencies pkg;
260 (* For rationale behind always bumping the spec file, see comment
264 if not (file_contains_string specfile rebuild_name) then
265 rebuild_name ^ " rebuild."
267 "Bump release and rebuild." in
268 sh "rpmdev-bumpspec -c %s %s" (quote title) specfile;
270 (* XXX Automate common specfile fixes. *)