1 (* Perform a complete Fedora OCaml rebuild, in build order. *)
12 let koji_target = "rawhide"
14 (* The name of the rebuild, and also the magic substring that must
15 * appear in the %changelog when the package has been rebuilt.
17 let rebuild_name = "ocaml-4.02.0-0.8.git10e45753.fc22"
19 (* Local repository that contains build dependencies. *)
20 let yum_repo = "koji-rawhide"
22 (* Packages that have problems. These block the packages and all
26 "ocaml-omake"; (* build failure (warnings) *)
27 "ocaml-pa-do"; (* build failure, complex *)
28 "ocaml-preludeml"; (* build failure *)
29 "frama-c"; (* build failure *)
30 "gappalib-coq"; (* build failure in configure script *)
32 let blocked pkg = List.mem pkg blocked
34 (* These packages are treated as if they have been rebuilt. *)
36 "ocaml-srpm-macros"; (* don't need to build this *)
37 "ocaml"; (* rebuilt by hand *)
38 "whenjobs"; (* obsolete *)
39 "libguestfs"; (* rebuilt by hand *)
40 "graphviz"; (* rebuilt by hand *)
41 "plplot"; (* already done *)
43 let ignored pkg = List.mem pkg ignored
45 (* List of OCaml-related source package names. *)
47 let dirs = shlines "cd %s && ls -1d ocaml*" fedora_dir in
48 dirs @ [ "alt-ergo"; "apron"; "brltty"; "coccinelle"; "coq";
49 "cduce"; "frama-c"; "gappalib-coq"; "graphviz"; "hevea"; "hivex";
50 "js-of-ocaml"; "llvm"; "plplot"; "virt-top"; "why3"; "xen";
51 "flocq" (* no OCaml code, but needs to be rebuilt after Coq *);
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)
98 (* We could make this a goal, but it's cheap enough to run it unconditionally. *)
99 let install_build_dependencies pkg =
100 sh "sudo yum clean all --disablerepo=\\* --enablerepo=%s"
102 sh "sudo yum-builddep -y --disablerepo=\\* --enablerepo=%s %s"
103 (quote yum_repo) (fedora_specfile pkg branch)
105 (* Unset MAKEFLAGS so it doesn't affect local builds. *)
106 let () = Unix.putenv "MAKEFLAGS" ""
108 (* Goal: rebuild all packages. *)
109 let rec goal all () =
110 let n = List.length source_packages in
113 require (rebuild_started pkg);
114 printf "*** *** rebuilt %d/%d packages *** ***\n%!" (i+1) n
117 (* Goal: That 'package' has been rebuilt and exists in Koji. *)
119 let specfile = fedora_specfile pkg branch in
121 (* Note: verrel may change as we go along, so don't assign it to
125 (* Note the target must be both of these because the old verrel
126 * could exist as a koji build without it having been part of the
129 target (ignored pkg ||
130 (file_contains_string specfile rebuild_name &&
131 koji_build_state (fedora_verrel pkg branch) == `Complete));
133 (* Ignored packages are treated as if they have been rebuilt. *)
134 if not (ignored pkg) then (
136 (* Start the rebuild. *)
137 require (rebuild_started pkg);
139 (* Wait for the build state to reach a conclusion. *)
141 match koji_build_state (fedora_verrel pkg branch) with
143 failwith (sprintf "rebuild of package %s: no build found" pkg)
150 failwith (sprintf "rebuild of package %s: deleted" pkg)
152 failwith (sprintf "rebuild of package %s: failed" pkg)
154 failwith (sprintf "rebuild of package %s: canceled" pkg)
158 (* Wait for the build to appear in Koji repo. *)
159 koji_wait_repo koji_target (fedora_verrel pkg branch)
162 (* Goal: The rebuild of the package has started, but we haven't waited
165 and rebuild_started pkg =
166 let deps = List.assoc pkg pkg_deps in
167 let specfile = fedora_specfile pkg branch in
169 (* Note the target must be both of these because the old verrel
170 * could exist as a koji build without it having been part of the
173 target (ignored pkg ||
174 (file_contains_string specfile rebuild_name &&
175 (match koji_build_state (fedora_verrel pkg branch) with
176 | `Building | `Complete -> true
177 | `Deleted | `Failed | `Canceled | `No_such_build -> false)));
179 (* All dependent packages must have been fully rebuilt and in the
182 List.iter (fun dep -> require (rebuilt dep)) deps;
184 (* Ignored packages are treated as if they have been rebuilt. *)
185 if not (ignored pkg) then (
186 (* A local test build must succeed. *)
187 require (local_build_succeeded pkg);
189 (* Rebuild the package in Koji. Don't wait ... *)
190 koji_build ~wait:false pkg branch;
192 (* ... but the build doesn't appear in Koji (eg. in 'koji
193 * buildinfo') until the SRPM has been built. This can take quite
194 * some time. Loop here until the build appears.
197 match koji_build_state (fedora_verrel pkg branch) with
201 | `Building | `Complete ->
204 failwith (sprintf "rebuild of package %s: deleted" pkg)
206 failwith (sprintf "rebuild of package %s: failed" pkg)
208 failwith (sprintf "rebuild of package %s: canceled" pkg)
213 and local_build_succeeded pkg =
214 (* The specfile must have been updated. *)
215 require (specfile_updated pkg);
218 sprintf "fedora_ocaml_local_build_%s_%s" pkg (fedora_verrel pkg branch) in
220 target (memory_exists key);
222 install_build_dependencies pkg;
224 (* Do a local test build to ensure the Koji build will work. *)
228 " (fedora_repo pkg branch);
232 and specfile_updated pkg =
233 let repodir = fedora_repo pkg branch in
234 let specfile = fedora_specfile pkg branch in
238 rm -rf x86_64 noarch *.src.rpm .build* clog
242 if not (git_has_local_changes repodir) then
248 install_build_dependencies pkg;
250 (* For rationale behind always bumping the spec file, see comment
254 if not (file_contains_string specfile rebuild_name) then
255 rebuild_name ^ " rebuild."
257 "Bump release and rebuild." in
258 sh "rpmdev-bumpspec -c %s %s" (quote title) specfile;
260 (* XXX Automate common specfile fixes. *)
264 echo 'Please make further changes as required to the spec file %s.spec'
265 echo '(Press return key)'
268 echo 'OK to commit this change? (press ^C if not)'
271 echo 'OK to push this change? (press ^C if not)'