1 (* Perform a complete Fedora OCaml rebuild, in build order. *)
12 (*let side_tag = Some "f27-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.04.2"
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 "brltty"; (* broken for non-OCaml reasons *)
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 *)
41 let ignored pkg = List.mem pkg ignored
43 (* List of OCaml-related source package names. *)
48 [ -f \"$f/master/$f.spec\" ] && echo \"$f\"
51 dirs @ [ "alt-ergo"; "apron"; "brltty"; "coccinelle"; "coq";
52 "cduce"; "frama-c"; "gappalib-coq"; "graphviz"; "hevea"; "hivex";
53 "plplot"; "virt-top"; "why3"; "z3";
54 "flocq" (* no OCaml code, but needs to be rebuilt after Coq *);
55 "guestfs-browser"; "libguestfs" ]
57 (* Dependencies of each package. (pkg, [deps ...]) *)
58 let pkg_deps = dependencies branch source_packages
60 (* Remove blocked packages and packages which have a blocked package
61 * as a dependency (recursively).
64 let rec is_blocked pkg =
65 if blocked pkg then true
67 let deps = List.assoc pkg pkg_deps in
68 List.exists is_blocked deps
71 List.filter (fun pkg -> not (is_blocked pkg)) source_packages
73 (* Short the dependencies lists so that the build order is stable
77 List.map (fun (pkg, deps) -> pkg, List.sort compare deps) pkg_deps
79 (* Sort the source packages so that the packages with the largest
80 * number of reverse dependencies [other packages that depend on it]
81 * appear earlier in the list, on the basis that building these
82 * packages first has the greatest advantage.
87 fun (rdep, deps) -> if List.mem pkg deps then Some rdep else None
91 let r1 = rdeps p1 and r2 = rdeps p2 in
92 let n1 = List.length r1 and n2 = List.length r2 in
93 if n1 <> n2 then compare n2 n1 else compare p1 p2
95 List.sort cmp source_packages
98 printf "final list of source packages = %s\n%!"
99 (String.concat " " source_packages)
102 (* We could make this a goal, but it's cheap enough to run it unconditionally. *)
103 let install_build_dependencies pkg =
104 sh "sudo yum clean all --disablerepo=\\* --enablerepo=%s"
106 sh "sudo yum-builddep -y --disablerepo=\\* --enablerepo=%s %s"
107 (quote yum_repo) (fedora_specfile pkg branch)
110 (* Unset MAKEFLAGS so it doesn't affect local builds. *)
111 let () = Unix.putenv "MAKEFLAGS" ""
113 (* Goal: rebuild all packages. *)
114 let rec goal all () =
115 let n = List.length source_packages in
118 require (rebuild_started pkg);
119 printf "*** *** rebuilt %d/%d packages *** ***\n%!" (i+1) n
122 (* Goal: That 'package' has been rebuilt and exists in Koji. *)
124 let specfile = fedora_specfile pkg branch in
126 (* Note: verrel may change as we go along, so don't assign it to
130 (* Note the target must be both of these because the old verrel
131 * could exist as a koji build without it having been part of the
134 target (ignored pkg ||
135 (file_contains_string specfile rebuild_name &&
136 koji_build_state (fedora_verrel pkg branch) == `Complete));
138 (* Ignored packages are treated as if they have been rebuilt. *)
139 if not (ignored pkg) then (
141 (* Start the rebuild. *)
142 require (rebuild_started pkg);
144 (* Wait for the build state to reach a conclusion. *)
146 match koji_build_state (fedora_verrel pkg branch) with
148 failwith (sprintf "rebuild of package %s: no build found" pkg)
155 failwith (sprintf "rebuild of package %s: deleted" pkg)
157 failwith (sprintf "rebuild of package %s: failed" pkg)
159 failwith (sprintf "rebuild of package %s: canceled" pkg)
163 (* Wait for the build to appear in Koji repo. *)
164 koji_wait_repo koji_target (fedora_verrel pkg branch)
167 (* Goal: The rebuild of the package has started, but we haven't waited
170 and rebuild_started pkg =
171 let deps = List.assoc pkg pkg_deps in
172 let specfile = fedora_specfile pkg branch in
174 (* Note the target must be both of these because the old verrel
175 * could exist as a koji build without it having been part of the
178 target (ignored pkg ||
179 (file_contains_string specfile rebuild_name &&
180 (match koji_build_state (fedora_verrel pkg branch) with
181 | `Building | `Complete -> true
182 | `Deleted | `Failed | `Canceled | `No_such_build -> false)));
184 (* All dependent packages must have been fully rebuilt and in the
187 List.iter (fun dep -> require (rebuilt dep)) deps;
189 (* Ignored packages are treated as if they have been rebuilt. *)
190 if not (ignored pkg) then (
192 (* A local test build must succeed. *)
193 require (local_build_succeeded pkg);
195 (* local_build_succeeded normally does this ... *)
196 require (specfile_updated pkg);
198 (* Rebuild the package in Koji. Don't wait ... *)
199 koji_build ~wait:false ?side_tag pkg branch;
201 (* ... but the build doesn't appear in Koji (eg. in 'koji
202 * buildinfo') until the SRPM has been built. This can take quite
203 * some time. Loop here until the build appears.
206 match koji_build_state (fedora_verrel pkg branch) with
210 | `Building | `Complete ->
213 failwith (sprintf "rebuild of package %s: deleted" pkg)
215 failwith (sprintf "rebuild of package %s: failed" pkg)
217 failwith (sprintf "rebuild of package %s: canceled" pkg)
223 and local_build_succeeded pkg =
224 (* The specfile must have been updated. *)
225 require (specfile_updated pkg);
228 sprintf "fedora_ocaml_local_build_%s_%s" pkg (fedora_verrel pkg branch) in
230 target (memory_exists key);
232 install_build_dependencies pkg;
234 (* Do a local test build to ensure the Koji build will work. *)
238 " (fedora_repo pkg branch);
243 and specfile_updated pkg =
244 let repodir = fedora_repo pkg branch in
245 let specfile = fedora_specfile pkg branch in
249 rm -rf x86_64 noarch *.src.rpm .build* clog
253 if not (git_has_local_changes repodir) then
259 (* - XXX why did we do this here?
260 install_build_dependencies pkg;
263 (* For rationale behind always bumping the spec file, see comment
267 if not (file_contains_string specfile rebuild_name) then
268 rebuild_name ^ " rebuild."
270 "Bump release and rebuild." in
271 sh "rpmdev-bumpspec -c %s %s" (quote title) specfile;
273 (* XXX Automate common specfile fixes. *)