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 *)
27 "ocaml-camlimages"; (* build failure, conflicting C types in header files *)
29 let blocked pkg = List.mem pkg blocked
31 (* These packages are treated as if they have been rebuilt. *)
33 "ocaml-srpm-macros"; (* don't need to build this *)
34 "ocaml"; (* rebuilt by hand *)
35 "whenjobs"; (* obsolete *)
37 let ignored pkg = List.mem pkg ignored
39 (* List of OCaml-related source package names. *)
41 let dirs = shlines "cd %s && ls -1d ocaml*" fedora_dir in
42 dirs @ [ "alt-ergo"; "apron"; "brltty"; "coccinelle"; "coq";
43 "cduce"; "frama-c"; "gappalib-coq"; "graphviz"; "hevea"; "hivex";
44 "js-of-ocaml"; "llvm"; "plplot"; "virt-top"; "why3"; "xen";
45 "flocq" (* no OCaml code, but needs to be rebuilt after Coq *);
49 (* Dependencies of each package. (pkg, [deps ...]) *)
50 let pkg_deps = dependencies branch source_packages
52 (* Remove blocked packages and packages which have a blocked package
53 * as a dependency (recursively).
56 let rec is_blocked pkg =
57 if blocked pkg then true
59 let deps = List.assoc pkg pkg_deps in
60 List.exists is_blocked deps
63 List.filter (fun pkg -> not (is_blocked pkg)) source_packages
65 (* Short the dependencies lists so that the build order is stable
69 List.map (fun (pkg, deps) -> pkg, List.sort compare deps) pkg_deps
71 (* Sort the source packages so that the packages with the largest
72 * number of reverse dependencies [other packages that depend on it]
73 * appear earlier in the list, on the basis that building these
74 * packages first has the greatest advantage.
79 fun (rdep, deps) -> if List.mem pkg deps then Some rdep else None
83 let r1 = rdeps p1 and r2 = rdeps p2 in
84 let n1 = List.length r1 and n2 = List.length r2 in
85 if n1 <> n2 then compare n2 n1 else compare p1 p2
87 List.sort cmp source_packages
90 printf "final list of source packages = %s\n%!"
91 (String.concat " " source_packages)
93 (* We could make this a goal, but it's cheap enough to run it unconditionally. *)
94 let install_build_dependencies pkg =
95 sh "sudo yum clean all --disablerepo=\\* --enablerepo=%s"
97 sh "sudo yum-builddep -y --disablerepo=\\* --enablerepo=%s %s"
98 (quote yum_repo) (fedora_specfile pkg branch)
100 (* Unset MAKEFLAGS so it doesn't affect local builds. *)
101 let () = Unix.putenv "MAKEFLAGS" ""
103 (* Goal: rebuild all packages. *)
104 let rec goal all () =
105 let n = List.length source_packages in
108 require (rebuild_started pkg);
109 printf "*** *** rebuilt %d/%d packages *** ***\n%!" (i+1) n
112 (* Goal: That 'package' has been rebuilt and exists in Koji. *)
114 let specfile = fedora_specfile pkg branch in
116 (* Note: verrel may change as we go along, so don't assign it to
120 (* Note the target must be both of these because the old verrel
121 * could exist as a koji build without it having been part of the
124 target (ignored pkg ||
125 (file_contains_string specfile rebuild_name &&
126 koji_build_state (fedora_verrel pkg branch) == `Complete));
128 (* Ignored packages are treated as if they have been rebuilt. *)
129 if not (ignored pkg) then (
131 (* Start the rebuild. *)
132 require (rebuild_started pkg);
134 (* Wait for the build state to reach a conclusion. *)
136 match koji_build_state (fedora_verrel pkg branch) with
138 failwith (sprintf "rebuild of package %s: no build found" pkg)
145 failwith (sprintf "rebuild of package %s: deleted" pkg)
147 failwith (sprintf "rebuild of package %s: failed" pkg)
149 failwith (sprintf "rebuild of package %s: canceled" pkg)
153 (* Wait for the build to appear in Koji repo. *)
154 koji_wait_repo koji_target (fedora_verrel pkg branch)
157 (* Goal: The rebuild of the package has started, but we haven't waited
160 and rebuild_started pkg =
161 let deps = List.assoc pkg pkg_deps in
162 let specfile = fedora_specfile pkg branch in
164 (* Note the target must be both of these because the old verrel
165 * could exist as a koji build without it having been part of the
168 target (ignored pkg ||
169 (file_contains_string specfile rebuild_name &&
170 (match koji_build_state (fedora_verrel pkg branch) with
171 | `Building | `Complete -> true
172 | `Deleted | `Failed | `Canceled | `No_such_build -> false)));
174 (* All dependent packages must have been fully rebuilt and in the
177 List.iter (fun dep -> require (rebuilt dep)) deps;
179 (* Ignored packages are treated as if they have been rebuilt. *)
180 if not (ignored pkg) then (
182 (* A local test build must succeed. *)
183 require (local_build_succeeded pkg);
185 (* local_build_succeeded normally does this ... *)
186 require (specfile_updated pkg);
188 (* Rebuild the package in Koji. Don't wait ... *)
189 koji_build ~wait:false pkg branch;
191 (* ... but the build doesn't appear in Koji (eg. in 'koji
192 * buildinfo') until the SRPM has been built. This can take quite
193 * some time. Loop here until the build appears.
196 match koji_build_state (fedora_verrel pkg branch) with
200 | `Building | `Complete ->
203 failwith (sprintf "rebuild of package %s: deleted" pkg)
205 failwith (sprintf "rebuild of package %s: failed" pkg)
207 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);
233 and specfile_updated pkg =
234 let repodir = fedora_repo pkg branch in
235 let specfile = fedora_specfile pkg branch in
239 rm -rf x86_64 noarch *.src.rpm .build* clog
243 if not (git_has_local_changes repodir) then
249 (* - XXX why did we do this here?
250 install_build_dependencies pkg;
253 (* For rationale behind always bumping the spec file, see comment
257 if not (file_contains_string specfile rebuild_name) then
258 rebuild_name ^ " rebuild."
260 "Bump release and rebuild." in
261 sh "rpmdev-bumpspec -c %s %s" (quote title) specfile;
263 (* XXX Automate common specfile fixes. *)