1 (* Perform a complete Fedora OCaml rebuild, in build order. *)
12 let side_tag = Some "f27-ocaml"
19 (* The name of the rebuild, and also the magic substring that must
20 * appear in the %changelog when the package has been rebuilt.
22 let rebuild_name = "OCaml 4.04.1"
24 (* Local repository that contains build dependencies. *)
25 let yum_repo = "koji-rawhide"
27 (* Packages that have problems. These block the packages and all
31 "brltty"; (* broken for non-OCaml reasons *)
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. *)
44 let dirs = shlines "cd %s && ls -1d ocaml*" fedora_dir in
45 dirs @ [ "alt-ergo"; "apron"; "brltty"; "coccinelle"; "coq";
46 "cduce"; "frama-c"; "gappalib-coq"; "graphviz"; "hevea"; "hivex";
47 "plplot"; "virt-top"; "why3"; "z3";
48 "flocq" (* no OCaml code, but needs to be rebuilt after Coq *);
49 "guestfs-browser"; "libguestfs" ]
51 (* Dependencies of each package. (pkg, [deps ...]) *)
52 let pkg_deps = dependencies branch source_packages
54 (* Remove blocked packages and packages which have a blocked package
55 * as a dependency (recursively).
58 let rec is_blocked pkg =
59 if blocked pkg then true
61 let deps = List.assoc pkg pkg_deps in
62 List.exists is_blocked deps
65 List.filter (fun pkg -> not (is_blocked pkg)) source_packages
67 (* Short the dependencies lists so that the build order is stable
71 List.map (fun (pkg, deps) -> pkg, List.sort compare deps) pkg_deps
73 (* Sort the source packages so that the packages with the largest
74 * number of reverse dependencies [other packages that depend on it]
75 * appear earlier in the list, on the basis that building these
76 * packages first has the greatest advantage.
81 fun (rdep, deps) -> if List.mem pkg deps then Some rdep else None
85 let r1 = rdeps p1 and r2 = rdeps p2 in
86 let n1 = List.length r1 and n2 = List.length r2 in
87 if n1 <> n2 then compare n2 n1 else compare p1 p2
89 List.sort cmp source_packages
92 printf "final list of source packages = %s\n%!"
93 (String.concat " " source_packages)
96 (* We could make this a goal, but it's cheap enough to run it unconditionally. *)
97 let install_build_dependencies pkg =
98 sh "sudo yum clean all --disablerepo=\\* --enablerepo=%s"
100 sh "sudo yum-builddep -y --disablerepo=\\* --enablerepo=%s %s"
101 (quote yum_repo) (fedora_specfile pkg branch)
104 (* Unset MAKEFLAGS so it doesn't affect local builds. *)
105 let () = Unix.putenv "MAKEFLAGS" ""
107 (* Goal: rebuild all packages. *)
108 let rec goal all () =
109 let n = List.length source_packages in
112 require (rebuild_started pkg);
113 printf "*** *** rebuilt %d/%d packages *** ***\n%!" (i+1) n
116 (* Goal: That 'package' has been rebuilt and exists in Koji. *)
118 let specfile = fedora_specfile pkg branch in
120 (* Note: verrel may change as we go along, so don't assign it to
124 (* Note the target must be both of these because the old verrel
125 * could exist as a koji build without it having been part of the
128 target (ignored pkg ||
129 (file_contains_string specfile rebuild_name &&
130 koji_build_state (fedora_verrel pkg branch) == `Complete));
132 (* Ignored packages are treated as if they have been rebuilt. *)
133 if not (ignored pkg) then (
135 (* Start the rebuild. *)
136 require (rebuild_started pkg);
138 (* Wait for the build state to reach a conclusion. *)
140 match koji_build_state (fedora_verrel pkg branch) with
142 failwith (sprintf "rebuild of package %s: no build found" pkg)
149 failwith (sprintf "rebuild of package %s: deleted" pkg)
151 failwith (sprintf "rebuild of package %s: failed" pkg)
153 failwith (sprintf "rebuild of package %s: canceled" pkg)
157 (* Wait for the build to appear in Koji repo. *)
158 koji_wait_repo koji_target (fedora_verrel pkg branch)
161 (* Goal: The rebuild of the package has started, but we haven't waited
164 and rebuild_started pkg =
165 let deps = List.assoc pkg pkg_deps in
166 let specfile = fedora_specfile pkg branch in
168 (* Note the target must be both of these because the old verrel
169 * could exist as a koji build without it having been part of the
172 target (ignored pkg ||
173 (file_contains_string specfile rebuild_name &&
174 (match koji_build_state (fedora_verrel pkg branch) with
175 | `Building | `Complete -> true
176 | `Deleted | `Failed | `Canceled | `No_such_build -> false)));
178 (* All dependent packages must have been fully rebuilt and in the
181 List.iter (fun dep -> require (rebuilt dep)) deps;
183 (* Ignored packages are treated as if they have been rebuilt. *)
184 if not (ignored pkg) then (
186 (* A local test build must succeed. *)
187 require (local_build_succeeded pkg);
189 (* local_build_succeeded normally does this ... *)
190 require (specfile_updated pkg);
192 (* Rebuild the package in Koji. Don't wait ... *)
193 koji_build ~wait:false ?side_tag pkg branch;
195 (* ... but the build doesn't appear in Koji (eg. in 'koji
196 * buildinfo') until the SRPM has been built. This can take quite
197 * some time. Loop here until the build appears.
200 match koji_build_state (fedora_verrel pkg branch) with
204 | `Building | `Complete ->
207 failwith (sprintf "rebuild of package %s: deleted" pkg)
209 failwith (sprintf "rebuild of package %s: failed" pkg)
211 failwith (sprintf "rebuild of package %s: canceled" pkg)
217 and local_build_succeeded pkg =
218 (* The specfile must have been updated. *)
219 require (specfile_updated pkg);
222 sprintf "fedora_ocaml_local_build_%s_%s" pkg (fedora_verrel pkg branch) in
224 target (memory_exists key);
226 install_build_dependencies pkg;
228 (* Do a local test build to ensure the Koji build will work. *)
232 " (fedora_repo pkg branch);
237 and specfile_updated pkg =
238 let repodir = fedora_repo pkg branch in
239 let specfile = fedora_specfile pkg branch in
243 rm -rf x86_64 noarch *.src.rpm .build* clog
247 if not (git_has_local_changes repodir) then
253 (* - XXX why did we do this here?
254 install_build_dependencies pkg;
257 (* For rationale behind always bumping the spec file, see comment
261 if not (file_contains_string specfile rebuild_name) then
262 rebuild_name ^ " rebuild."
264 "Bump release and rebuild." in
265 sh "rpmdev-bumpspec -c %s %s" (quote title) specfile;
267 (* XXX Automate common specfile fixes. *)