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 final"
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-pa-do"; (* orphaned *)
28 let blocked pkg = List.mem pkg blocked
30 (* These packages are treated as if they have been rebuilt. *)
32 "ocaml-srpm-macros"; (* don't need to build this *)
33 "ocaml"; (* rebuilt by hand *)
34 "whenjobs"; (* obsolete *)
36 let ignored pkg = List.mem pkg ignored
38 (* List of OCaml-related source package names. *)
40 let dirs = shlines "cd %s && ls -1d ocaml*" fedora_dir in
41 dirs @ [ "alt-ergo"; "apron"; "brltty"; "coccinelle"; "coq";
42 "cduce"; "frama-c"; "gappalib-coq"; "graphviz"; "hevea"; "hivex";
43 "js-of-ocaml"; "llvm"; "plplot"; "virt-top"; "why3"; "xen";
44 "flocq" (* no OCaml code, but needs to be rebuilt after Coq *);
48 (* Dependencies of each package. (pkg, [deps ...]) *)
49 let pkg_deps = dependencies branch source_packages
51 (* Remove blocked packages and packages which have a blocked package
52 * as a dependency (recursively).
55 let rec is_blocked pkg =
56 if blocked pkg then true
58 let deps = List.assoc pkg pkg_deps in
59 List.exists is_blocked deps
62 List.filter (fun pkg -> not (is_blocked pkg)) source_packages
64 (* Short the dependencies lists so that the build order is stable
68 List.map (fun (pkg, deps) -> pkg, List.sort compare deps) pkg_deps
70 (* Sort the source packages so that the packages with the largest
71 * number of reverse dependencies [other packages that depend on it]
72 * appear earlier in the list, on the basis that building these
73 * packages first has the greatest advantage.
78 fun (rdep, deps) -> if List.mem pkg deps then Some rdep else None
82 let r1 = rdeps p1 and r2 = rdeps p2 in
83 let n1 = List.length r1 and n2 = List.length r2 in
84 if n1 <> n2 then compare n2 n1 else compare p1 p2
86 List.sort cmp source_packages
89 printf "final list of source packages = %s\n%!"
90 (String.concat " " source_packages)
92 (* We could make this a goal, but it's cheap enough to run it unconditionally. *)
93 let install_build_dependencies pkg =
94 sh "sudo yum clean all --disablerepo=\\* --enablerepo=%s"
96 sh "sudo yum-builddep -y --disablerepo=\\* --enablerepo=%s %s"
97 (quote yum_repo) (fedora_specfile pkg branch)
99 (* Unset MAKEFLAGS so it doesn't affect local builds. *)
100 let () = Unix.putenv "MAKEFLAGS" ""
102 (* Goal: rebuild all packages. *)
103 let rec goal all () =
104 let n = List.length source_packages in
107 require (rebuild_started pkg);
108 printf "*** *** rebuilt %d/%d packages *** ***\n%!" (i+1) n
111 (* Goal: That 'package' has been rebuilt and exists in Koji. *)
113 let specfile = fedora_specfile pkg branch in
115 (* Note: verrel may change as we go along, so don't assign it to
119 (* Note the target must be both of these because the old verrel
120 * could exist as a koji build without it having been part of the
123 target (ignored pkg ||
124 (file_contains_string specfile rebuild_name &&
125 koji_build_state (fedora_verrel pkg branch) == `Complete));
127 (* Ignored packages are treated as if they have been rebuilt. *)
128 if not (ignored pkg) then (
130 (* Start the rebuild. *)
131 require (rebuild_started pkg);
133 (* Wait for the build state to reach a conclusion. *)
135 match koji_build_state (fedora_verrel pkg branch) with
137 failwith (sprintf "rebuild of package %s: no build found" pkg)
144 failwith (sprintf "rebuild of package %s: deleted" pkg)
146 failwith (sprintf "rebuild of package %s: failed" pkg)
148 failwith (sprintf "rebuild of package %s: canceled" pkg)
152 (* Wait for the build to appear in Koji repo. *)
153 koji_wait_repo koji_target (fedora_verrel pkg branch)
156 (* Goal: The rebuild of the package has started, but we haven't waited
159 and rebuild_started pkg =
160 let deps = List.assoc pkg pkg_deps in
161 let specfile = fedora_specfile pkg branch in
163 (* Note the target must be both of these because the old verrel
164 * could exist as a koji build without it having been part of the
167 target (ignored pkg ||
168 (file_contains_string specfile rebuild_name &&
169 (match koji_build_state (fedora_verrel pkg branch) with
170 | `Building | `Complete -> true
171 | `Deleted | `Failed | `Canceled | `No_such_build -> false)));
173 (* All dependent packages must have been fully rebuilt and in the
176 List.iter (fun dep -> require (rebuilt dep)) deps;
178 (* Ignored packages are treated as if they have been rebuilt. *)
179 if not (ignored pkg) then (
181 (* A local test build must succeed. *)
182 require (local_build_succeeded pkg);
184 (* local_build_succeeded normally does this ... *)
185 require (specfile_updated pkg);
187 (* Rebuild the package in Koji. Don't wait ... *)
188 koji_build ~wait:false pkg branch;
190 (* ... but the build doesn't appear in Koji (eg. in 'koji
191 * buildinfo') until the SRPM has been built. This can take quite
192 * some time. Loop here until the build appears.
195 match koji_build_state (fedora_verrel pkg branch) with
199 | `Building | `Complete ->
202 failwith (sprintf "rebuild of package %s: deleted" pkg)
204 failwith (sprintf "rebuild of package %s: failed" pkg)
206 failwith (sprintf "rebuild of package %s: canceled" pkg)
212 and local_build_succeeded pkg =
213 (* The specfile must have been updated. *)
214 require (specfile_updated pkg);
217 sprintf "fedora_ocaml_local_build_%s_%s" pkg (fedora_verrel pkg branch) in
219 target (memory_exists key);
221 install_build_dependencies pkg;
223 (* Do a local test build to ensure the Koji build will work. *)
227 " (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 (* - XXX why did we do this here?
249 install_build_dependencies pkg;
252 (* For rationale behind always bumping the spec file, see comment
256 if not (file_contains_string specfile rebuild_name) then
257 rebuild_name ^ " rebuild."
259 "Bump release and rebuild." in
260 sh "rpmdev-bumpspec -c %s %s" (quote title) specfile;
262 (* XXX Automate common specfile fixes. *)