1 (* Perform a complete Fedora OCaml rebuild, in build order. *)
12 let side_tag = Some "f27-ocaml2"
13 (*let side_tag = None*)
18 | None -> "f27-build" (* see: https://pagure.io/koji/issue/485 *)
20 (* The name of the rebuild, and also the magic substring that must
21 * appear in the %changelog when the package has been rebuilt.
23 let rebuild_name = "OCaml 4.05.0"
25 (* Local repository that contains build dependencies. *)
26 let yum_repo = "koji-rawhide"
28 (* Packages that have problems. These block the packages and all
32 "coq"; (* https://github.com/ocaml/ocaml/pull/1268 *)
33 "ocaml-gsl"; (* unknown linking error, only happens in Koji, may
34 be related to binutils used to build gsl? *)
35 "ocaml-lacaml"; (* same as gsl *)
37 let blocked pkg = List.mem pkg blocked
39 (* These packages are treated as if they have been rebuilt. *)
41 "ocaml-srpm-macros"; (* don't need to build this *)
42 "ocaml"; (* rebuilt by hand *)
44 let ignored pkg = List.mem pkg ignored
46 (* List of OCaml-related source package names. *)
51 [ -f \"$f/master/$f.spec\" ] && echo \"$f\"
54 dirs @ [ "alt-ergo"; "apron"; "brltty"; "coccinelle"; "coq";
55 "cduce"; "frama-c"; "gappalib-coq"; "graphviz"; "hevea"; "hivex";
56 "plplot"; "virt-top"; "why3"; "z3";
57 "flocq" (* no OCaml code, but needs to be rebuilt after Coq *);
58 "guestfs-browser"; "libguestfs" ]
60 (* Dependencies of each package. (pkg, [deps ...]) *)
61 let pkg_deps = dependencies branch source_packages
63 (* Remove blocked packages and packages which have a blocked package
64 * as a dependency (recursively).
67 let rec is_blocked pkg =
68 if blocked pkg then true
70 let deps = List.assoc pkg pkg_deps in
71 List.exists is_blocked deps
74 List.filter (fun pkg -> not (is_blocked pkg)) source_packages
76 (* Short the dependencies lists so that the build order is stable
80 List.map (fun (pkg, deps) -> pkg, List.sort compare deps) pkg_deps
82 (* Sort the source packages so that the packages with the largest
83 * number of reverse dependencies [other packages that depend on it]
84 * appear earlier in the list, on the basis that building these
85 * packages first has the greatest advantage.
90 fun (rdep, deps) -> if List.mem pkg deps then Some rdep else None
94 let r1 = rdeps p1 and r2 = rdeps p2 in
95 let n1 = List.length r1 and n2 = List.length r2 in
96 if n1 <> n2 then compare n2 n1 else compare p1 p2
98 List.sort cmp source_packages
101 printf "final list of source packages = %s\n%!"
102 (String.concat " " source_packages)
105 (* We could make this a goal, but it's cheap enough to run it unconditionally. *)
106 let install_build_dependencies pkg =
107 sh "sudo yum clean all --disablerepo=\\* --enablerepo=%s"
109 sh "sudo yum-builddep -y --disablerepo=\\* --enablerepo=%s %s"
110 (quote yum_repo) (fedora_specfile pkg branch)
113 (* Unset MAKEFLAGS so it doesn't affect local builds. *)
114 let () = Unix.putenv "MAKEFLAGS" ""
116 (* Goal: rebuild all packages. *)
117 let rec goal all () =
118 let n = List.length source_packages in
121 require (rebuild_started pkg);
122 printf "*** *** rebuilt %d/%d packages *** ***\n%!" (i+1) n
125 (* Goal: That 'package' has been rebuilt and exists in Koji. *)
127 let specfile = fedora_specfile pkg branch in
129 (* Note: verrel may change as we go along, so don't assign it to
133 (* Note the target must be both of these because the old verrel
134 * could exist as a koji build without it having been part of the
137 target (ignored pkg ||
138 (file_contains_string specfile rebuild_name &&
139 koji_build_state (fedora_verrel pkg branch) == `Complete));
141 (* Ignored packages are treated as if they have been rebuilt. *)
142 if not (ignored pkg) then (
144 (* Start the rebuild. *)
145 require (rebuild_started pkg);
147 (* Wait for the build state to reach a conclusion. *)
149 match koji_build_state (fedora_verrel pkg branch) with
151 failwith (sprintf "rebuild of package %s: no build found" pkg)
158 failwith (sprintf "rebuild of package %s: deleted" pkg)
160 failwith (sprintf "rebuild of package %s: failed" pkg)
162 failwith (sprintf "rebuild of package %s: canceled" pkg)
166 (* Wait for the build to appear in Koji repo. *)
167 koji_wait_repo koji_target (fedora_verrel pkg branch)
170 (* Goal: The rebuild of the package has started, but we haven't waited
173 and rebuild_started pkg =
174 let deps = List.assoc pkg pkg_deps in
175 let specfile = fedora_specfile pkg branch in
177 (* Note the target must be both of these because the old verrel
178 * could exist as a koji build without it having been part of the
181 target (ignored pkg ||
182 (file_contains_string specfile rebuild_name &&
183 (match koji_build_state (fedora_verrel pkg branch) with
184 | `Building | `Complete -> true
185 | `Deleted | `Failed | `Canceled | `No_such_build -> false)));
187 (* All dependent packages must have been fully rebuilt and in the
190 List.iter (fun dep -> require (rebuilt dep)) deps;
192 (* Ignored packages are treated as if they have been rebuilt. *)
193 if not (ignored pkg) then (
195 (* A local test build must succeed. *)
196 require (local_build_succeeded pkg);
198 (* local_build_succeeded normally does this ... *)
199 require (specfile_updated pkg);
201 (* Rebuild the package in Koji. Don't wait ... *)
202 koji_build ~wait:false ?side_tag pkg branch;
204 (* ... but the build doesn't appear in Koji (eg. in 'koji
205 * buildinfo') until the SRPM has been built. This can take quite
206 * some time. Loop here until the build appears.
209 match koji_build_state (fedora_verrel pkg branch) with
213 | `Building | `Complete ->
216 failwith (sprintf "rebuild of package %s: deleted" pkg)
218 failwith (sprintf "rebuild of package %s: failed" pkg)
220 failwith (sprintf "rebuild of package %s: canceled" pkg)
226 and local_build_succeeded pkg =
227 (* The specfile must have been updated. *)
228 require (specfile_updated pkg);
231 sprintf "fedora_ocaml_local_build_%s_%s" pkg (fedora_verrel pkg branch) in
233 target (memory_exists key);
235 install_build_dependencies pkg;
237 (* Do a local test build to ensure the Koji build will work. *)
241 " (fedora_repo pkg branch);
246 and specfile_updated pkg =
247 let repodir = fedora_repo pkg branch in
248 let specfile = fedora_specfile pkg branch in
252 rm -rf x86_64 noarch *.src.rpm .build* clog
256 if not (git_has_local_changes repodir) then
262 (* - XXX why did we do this here?
263 install_build_dependencies pkg;
266 (* For rationale behind always bumping the spec file, see comment
270 if not (file_contains_string specfile rebuild_name) then
271 rebuild_name ^ " rebuild."
273 "Bump release and rebuild." in
274 sh "rpmdev-bumpspec -c %s %s" (quote title) specfile;
276 (* XXX Automate common specfile fixes. *)