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-mikmatch"; (* build failure on 4.02.0 *)
27 "ocaml-omake"; (* build failure on 4.02.0 with hevea *)
28 "ocaml-p3l"; (* build failure on 4.02.0 -warn-error A *)
29 "ocaml-pa-do"; (* build failure, complex *)
30 "ocaml-lwt"; (* build failure on 4.02.0 *)
31 "ocaml-preludeml"; (* build failure *)
32 "cduce"; (* broken again with latest 4.02 *)
33 "frama-c"; (* build failure *)
34 "gappalib-coq"; (* build failure in configure script *)
36 let blocked pkg = List.mem pkg blocked
38 (* These packages are treated as if they have been rebuilt. *)
40 "ocaml-srpm-macros"; (* don't need to build this *)
41 "ocaml"; (* rebuilt by hand *)
42 "whenjobs"; (* obsolete *)
43 "libguestfs"; (* rebuilt by hand *)
44 "graphviz"; (* rebuilt by hand *)
45 "xen"; (* already done *)
46 "plplot"; (* already done *)
48 let ignored pkg = List.mem pkg ignored
50 (* List of OCaml-related source package names. *)
52 let dirs = shlines "cd %s && ls -1d ocaml*" fedora_dir in
53 dirs @ [ "alt-ergo"; "apron"; "brltty"; "coccinelle"; "coq";
54 "cduce"; "frama-c"; "gappalib-coq"; "graphviz"; "hivex";
55 "js-of-ocaml"; "llvm"; "plplot"; "why3"; "xen" ]
57 (* Dependencies of each package. (pkg, [deps ...]) *)
58 let pkg_deps = dependencies branch source_packages
60 (* Remove blocked packages and packages which have a blocked package
61 * as a dependency (recursively).
64 let rec is_blocked pkg =
65 if blocked pkg then true
67 let deps = List.assoc pkg pkg_deps in
68 List.exists is_blocked deps
71 List.filter (fun pkg -> not (is_blocked pkg)) source_packages
73 (* Short the dependencies lists so that the build order is stable
77 List.map (fun (pkg, deps) -> pkg, List.sort compare deps) pkg_deps
79 (* Sort the source packages so that the packages with the largest
80 * number of reverse dependencies [other packages that depend on it]
81 * appear earlier in the list, on the basis that building these
82 * packages first has the greatest advantage.
87 fun (rdep, deps) -> if List.mem pkg deps then Some rdep else None
91 let r1 = rdeps p1 and r2 = rdeps p2 in
92 let n1 = List.length r1 and n2 = List.length r2 in
93 if n1 <> n2 then compare n2 n1 else compare p1 p2
95 List.sort cmp source_packages
98 printf "final list of source packages = %s\n%!"
99 (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)
108 (* Unset MAKEFLAGS so it doesn't affect local builds. *)
109 let () = Unix.putenv "MAKEFLAGS" ""
111 (* Goal: rebuild all packages. *)
112 let rec goal all () =
113 List.iter (fun pkg -> require (rebuild_started pkg)) source_packages
115 (* Goal: That 'package' has been rebuilt and exists in Koji. *)
117 let specfile = fedora_specfile pkg branch in
119 (* Note: verrel may change as we go along, so don't assign it to
123 (* Note the target must be both of these because the old verrel
124 * could exist as a koji build without it having been part of the
127 target (ignored pkg ||
128 (file_contains_string specfile rebuild_name &&
129 koji_build_state (fedora_verrel pkg branch) == `Complete));
131 (* Ignored packages are treated as if they have been rebuilt. *)
132 if not (ignored pkg) then (
134 (* Start the rebuild. *)
135 require (rebuild_started pkg);
137 (* Wait for the build state to reach a conclusion. *)
139 match koji_build_state (fedora_verrel pkg branch) with
141 failwith (sprintf "rebuild of package %s: no build found" pkg)
148 failwith (sprintf "rebuild of package %s: deleted" pkg)
150 failwith (sprintf "rebuild of package %s: failed" pkg)
152 failwith (sprintf "rebuild of package %s: canceled" pkg)
156 (* Wait for the build to appear in Koji repo. *)
157 koji_wait_repo koji_target (fedora_verrel pkg branch)
160 (* Goal: The rebuild of the package has started, but we haven't waited
163 and rebuild_started pkg =
164 let deps = List.assoc pkg pkg_deps in
165 let specfile = fedora_specfile pkg branch in
167 (* Note the target must be both of these because the old verrel
168 * could exist as a koji build without it having been part of the
171 target (ignored pkg ||
172 (file_contains_string specfile rebuild_name &&
173 (match koji_build_state (fedora_verrel pkg branch) with
174 | `Building | `Complete -> true
175 | `Deleted | `Failed | `Canceled | `No_such_build -> false)));
177 (* All dependent packages must have been fully rebuilt and in the
180 List.iter (fun dep -> require (rebuilt dep)) deps;
182 (* Ignored packages are treated as if they have been rebuilt. *)
183 if not (ignored pkg) then (
184 (* A local test build must succeed. *)
185 require (local_build_succeeded 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)
211 and local_build_succeeded pkg =
212 (* The specfile must have been updated. *)
213 require (specfile_updated pkg);
216 sprintf "fedora_ocaml_local_build_%s_%s" pkg (fedora_verrel pkg branch) in
218 target (memory_exists key);
220 install_build_dependencies pkg;
222 (* Do a local test build to ensure the Koji build will work. *)
226 " (fedora_repo pkg branch);
230 and specfile_updated pkg =
231 let repodir = fedora_repo pkg branch in
232 let specfile = fedora_specfile pkg branch in
236 rm -rf x86_64 noarch *.src.rpm .build* clog
240 if not (git_has_local_changes repodir) then
246 install_build_dependencies pkg;
248 (* For rationale behind always bumping the spec file, see comment
252 if not (file_contains_string specfile rebuild_name) then
253 rebuild_name ^ " rebuild."
255 "Bump release and rebuild." in
256 sh "rpmdev-bumpspec -c %s %s" (quote title) specfile;
258 (* XXX Automate common specfile fixes. *)
262 echo 'Please make further changes as required to the spec file %s.spec'
263 echo '(Press return key)'
266 echo 'OK to commit this change? (press ^C if not)'
269 echo 'OK to push this change? (press ^C if not)'