1 (* Perform a complete Fedora OCaml rebuild, in build order. *)
12 (*let side_tag = Some "f32-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 (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
33 let blocked pkg = List.mem pkg blocked
35 (* These packages are treated as if they have been rebuilt. *)
37 "ocaml-srpm-macros"; (* don't need to build this *)
38 "ocaml"; (* rebuilt by hand *)
40 let ignored pkg = List.mem pkg ignored
42 (* List of OCaml-related source package names. *)
47 [ -f \"$f/master/$f.spec\" ] && echo \"$f\"
50 dirs @ [ "alt-ergo"; "apron"; "brltty"; "coccinelle"; "coq";
51 "frama-c"; "gappalib-coq"; "graphviz"; "hevea"; "hivex";
52 "opam"; "plplot"; "virt-top"; "why3"; "z3";
53 "flocq" (* no OCaml code, but needs to be rebuilt after Coq *);
56 (* Dependencies of each package. (pkg, [deps ...]) *)
57 let pkg_deps = dependencies branch source_packages
59 (* Remove blocked packages and packages which have a blocked package
60 * as a dependency (recursively).
63 let rec is_blocked pkg =
64 if blocked pkg then true
66 let deps = List.assoc pkg pkg_deps in
67 List.exists is_blocked deps
70 List.filter (fun pkg -> not (is_blocked pkg)) source_packages
72 (* Short the dependencies lists so that the build order is stable
76 List.map (fun (pkg, deps) -> pkg, List.sort compare deps) pkg_deps
78 (* Sort the source packages so that the packages with the largest
79 * number of reverse dependencies [other packages that depend on it]
80 * appear earlier in the list, on the basis that building these
81 * packages first has the greatest advantage.
86 fun (rdep, deps) -> if List.mem pkg deps then Some rdep else None
90 let r1 = rdeps p1 and r2 = rdeps p2 in
91 let n1 = List.length r1 and n2 = List.length r2 in
92 if n1 <> n2 then compare n2 n1 else compare p1 p2
94 List.sort cmp source_packages
97 printf "final list of source packages = %s\n%!"
98 (String.concat " " source_packages)
101 (* We could make this a goal, but it's cheap enough to run it unconditionally. *)
102 let install_build_dependencies pkg =
103 sh "sudo yum clean all --disablerepo=\\* --enablerepo=%s"
105 sh "sudo yum-builddep -y --disablerepo=\\* --enablerepo=%s %s"
106 (quote yum_repo) (fedora_specfile pkg branch)
109 (* Unset MAKEFLAGS so it doesn't affect local builds. *)
110 let () = Unix.putenv "MAKEFLAGS" ""
112 (* Goal: rebuild all packages. *)
113 let rec goal all () =
114 let n = List.length source_packages in
117 require (rebuild_started pkg);
118 printf "*** *** rebuilt %d/%d packages *** ***\n%!" (i+1) n
121 (* Goal: That 'package' has been rebuilt and exists in Koji. *)
123 let specfile = fedora_specfile pkg branch in
125 (* Note: verrel may change as we go along, so don't assign it to
129 (* Note the target must be both of these because the old verrel
130 * could exist as a koji build without it having been part of the
133 target (ignored pkg ||
134 (file_contains_string specfile rebuild_name &&
135 koji_build_state (fedora_verrel pkg branch) == `Complete));
137 (* Ignored packages are treated as if they have been rebuilt. *)
138 if not (ignored pkg) then (
140 (* Start the rebuild. *)
141 require (rebuild_started pkg);
143 (* Wait for the build state to reach a conclusion. *)
145 match koji_build_state (fedora_verrel pkg branch) with
147 failwith (sprintf "rebuild of package %s: no build found" pkg)
154 failwith (sprintf "rebuild of package %s: deleted" pkg)
156 failwith (sprintf "rebuild of package %s: failed" pkg)
158 failwith (sprintf "rebuild of package %s: canceled" pkg)
162 (* Wait for the build to appear in Koji repo. *)
163 koji_wait_repo koji_target (fedora_verrel pkg branch)
166 (* Goal: The rebuild of the package has started, but we haven't waited
169 and rebuild_started pkg =
170 let deps = List.assoc pkg pkg_deps in
171 let specfile = fedora_specfile pkg branch in
173 (* Note the target must be both of these because the old verrel
174 * could exist as a koji build without it having been part of the
177 target (ignored pkg ||
178 (file_contains_string specfile rebuild_name &&
179 (match koji_build_state (fedora_verrel pkg branch) with
180 | `Building | `Complete -> true
181 | `Deleted | `Failed | `Canceled | `No_such_build -> false)));
183 (* All dependent packages must have been fully rebuilt and in the
186 List.iter (fun dep -> require (rebuilt dep)) deps;
188 (* Ignored packages are treated as if they have been rebuilt. *)
189 if not (ignored pkg) then (
191 (* A local test build must succeed. *)
192 require (local_build_succeeded pkg);
194 (* local_build_succeeded normally does this ... *)
195 require (specfile_updated pkg);
197 (* Rebuild the package in Koji. Don't wait ... *)
198 koji_build ~wait:false ?side_tag pkg branch;
200 (* ... but the build doesn't appear in Koji (eg. in 'koji
201 * buildinfo') until the SRPM has been built. This can take quite
202 * some time. Loop here until the build appears.
205 match koji_build_state (fedora_verrel pkg branch) with
209 | `Building | `Complete ->
212 failwith (sprintf "rebuild of package %s: deleted" pkg)
214 failwith (sprintf "rebuild of package %s: failed" pkg)
216 failwith (sprintf "rebuild of package %s: canceled" pkg)
222 and local_build_succeeded pkg =
223 (* The specfile must have been updated. *)
224 require (specfile_updated pkg);
227 sprintf "fedora_ocaml_local_build_%s_%s" pkg (fedora_verrel pkg branch) in
229 target (memory_exists key);
231 install_build_dependencies pkg;
233 (* Do a local test build to ensure the Koji build will work. *)
237 " (fedora_repo pkg branch);
242 and specfile_updated pkg =
243 let repodir = fedora_repo pkg branch in
244 let specfile = fedora_specfile pkg branch in
248 rm -rf x86_64 noarch *.src.rpm .build* clog
252 if not (git_has_local_changes repodir) then
258 (* - XXX why did we do this here?
259 install_build_dependencies pkg;
262 (* For rationale behind always bumping the spec file, see comment
266 if not (file_contains_string specfile rebuild_name) then
267 rebuild_name ^ " rebuild."
269 "Bump release and rebuild." in
270 sh "rpmdev-bumpspec -c %s %s" (quote title) specfile;
272 (* XXX Automate common specfile fixes. *)