Fedora OCaml rebuild: More blocked and ignored packages.
[goaljobs-goals.git] / fedora_ocaml_rebuild.ml
1 (* Perform a complete Fedora OCaml rebuild, in build order. *)
2
3 open Unix
4 open Printf
5
6 open Goaljobs
7 open Config
8 open Git
9 open Fedora
10
11 let branch = "master"
12 let koji_target = "rawhide"
13
14 (* The name of the rebuild, and also the magic substring that must
15  * appear in the %changelog when the package has been rebuilt.
16  *)
17 let rebuild_name = "OCaml 4.02.0 beta"
18
19 (* Local repository that contains build dependencies. *)
20 let yum_repo = "koji-rawhide"
21
22 (* Packages that have problems.  These block the packages and all
23  * dependent packages.
24  *)
25 let blocked = [
26   "ocaml-bitstring";               (* needs upstream fix for 4.02.0 *)
27
28   (* ocaml-labltk needs to be packaged.  Unfortunately because there
29    * is no spec file, ocaml-labltk doesn't appear in the list of
30    * source packages, and so is filtered out of all the dependency
31    * checks as if it were a non-OCaml package.  Therefore we currently
32    * also have to list all packages that depend on it.
33    *)
34   "ocaml-labltk"; (* BRed by: *) "ocaml-lablgl"; "ocaml-ocamlnet"; "planets";
35
36   "ocaml-camlp5";                       (* not updated for 4.02.0 *)
37 ]
38 let blocked pkg = List.mem pkg blocked
39
40 (* These packages are treated as if they have been rebuilt. *)
41 let ignored = [
42   "ocaml-srpm-macros";             (* don't need to build this *)
43   "ocaml";                         (* rebuilt by hand *)
44   "ocaml-findlib";                 (* rebuilt by hand *)
45   "ocaml-lwt"; "ocaml-react";      (* loganjerry is handling *)
46   "ocaml-camlidl";                 (* rebuilt by orionp *)
47   "whenjobs";                      (* obsolete *)
48 ]
49 let ignored pkg = List.mem pkg ignored
50
51 (* List of OCaml-related source package names. *)
52 let source_packages =
53   let dirs = shlines "cd %s && ls -1d ocaml*" fedora_dir in
54   dirs @ [ "alt-ergo"; "apron"; "brltty"; "coccinelle"; "coq";
55            "cduce"; "frama-c"; "gappalib-coq"; "graphviz"; "hivex";
56            "js-of-ocaml"; "llvm"; "plplot"; "why3"; "xen" ]
57
58 (* Dependencies of each package.  (pkg, [deps ...]) *)
59 let pkg_deps = dependencies branch source_packages
60
61 (* Remove blocked packages and packages which have a blocked package
62  * as a dependency (recursively).
63  *)
64 let source_packages =
65   let rec is_blocked pkg =
66     if blocked pkg then true
67     else (
68       let deps = List.assoc pkg pkg_deps in
69       List.exists is_blocked deps
70     )
71   in
72   List.filter (fun pkg -> not (is_blocked pkg)) source_packages
73
74 let () =
75   printf "final list of source packages = %s\n%!"
76     (String.concat " " source_packages)
77
78 (* Goal: rebuild all packages. *)
79 let rec goal all () =
80   List.iter (fun pkg -> require (rebuild_started pkg)) source_packages
81
82 (* Goal: That 'package' has been rebuilt and exists in Koji. *)
83 and rebuilt pkg =
84   let specfile = fedora_specfile pkg branch in
85
86   (* Note: verrel may change as we go along, so don't assign it to
87    * variable.
88    *)
89
90   (* Note the target must be both of these because the old verrel
91    * could exist as a koji build without it having been part of the
92    * rebuild.
93    *)
94   target (ignored pkg ||
95             (file_contains_string specfile rebuild_name &&
96                koji_build_state (fedora_verrel pkg branch) == `Complete));
97
98   (* Ignored packages are treated as if they have been rebuilt. *)
99   if not (ignored pkg) then (
100
101     (* Start the rebuild. *)
102     require (rebuild_started pkg);
103
104     (* Wait for the build state to reach a conclusion. *)
105     let rec loop () =
106       match koji_build_state (fedora_verrel pkg branch) with
107       | `No_such_build ->
108         failwith (sprintf "rebuild of package %s: no build found" pkg)
109       | `Building ->
110         sleep 60;
111         loop ()
112       | `Complete ->
113         ()
114       | `Deleted ->
115         failwith (sprintf "rebuild of package %s: deleted" pkg)
116       | `Failed ->
117         failwith (sprintf "rebuild of package %s: failed" pkg)
118       | `Canceled ->
119         failwith (sprintf "rebuild of package %s: canceled" pkg)
120     in
121     loop ();
122
123     (* Wait for the build to appear in Koji repo. *)
124     koji_wait_repo koji_target (fedora_verrel pkg branch)
125   )
126
127 (* Goal: The rebuild of the package has started, but we haven't waited
128  * for it to finish.
129  *)
130 and rebuild_started pkg =
131   let deps = List.assoc pkg pkg_deps in
132   let specfile = fedora_specfile pkg branch in
133
134   (* Note the target must be both of these because the old verrel
135    * could exist as a koji build without it having been part of the
136    * rebuild.
137    *)
138   target (ignored pkg ||
139             (file_contains_string specfile rebuild_name &&
140                (match koji_build_state (fedora_verrel pkg branch) with
141                | `Building | `Complete -> true
142                | `Deleted | `Failed | `Canceled | `No_such_build -> false)));
143
144   (* All dependent packages must have been fully rebuilt and in the
145    * repo first.
146    *)
147   List.iter (fun dep -> require (rebuilt dep)) deps;
148
149   (* Ignored packages are treated as if they have been rebuilt. *)
150   if not (ignored pkg) then (
151     (* A local test build must succeed. *)
152     require (local_build_succeeded pkg);
153
154     (* Rebuild the package in Koji.  Don't wait ... *)
155     koji_build ~wait:false pkg branch;
156
157     (* ... but the build doesn't appear in Koji (eg. in 'koji
158      * buildinfo') until the SRPM has been built.  This can take quite
159      * some time.  Loop here until the build appears.
160      *)
161     let rec loop () =
162       match koji_build_state (fedora_verrel pkg branch) with
163       | `No_such_build ->
164         sleep 60;
165         loop ();
166       | `Building | `Complete ->
167         ()
168       | `Deleted ->
169         failwith (sprintf "rebuild of package %s: deleted" pkg)
170       | `Failed ->
171         failwith (sprintf "rebuild of package %s: failed" pkg)
172       | `Canceled ->
173         failwith (sprintf "rebuild of package %s: canceled" pkg)
174     in
175     loop ()
176   )
177
178 and local_build_succeeded pkg =
179   (* The specfile must have been updated. *)
180   require (specfile_updated pkg);
181
182   let key =
183     sprintf "fedora_ocaml_local_build_%s_%s" pkg (fedora_verrel pkg branch) in
184
185   target (memory_exists key);
186
187   (* Do a local test build to ensure the Koji build will work. *)
188   sh "
189     cd %s
190     sudo yum-builddep -y --disablerepo=\\* --enablerepo=%s %s
191     fedpkg local
192   " (fedora_repo pkg branch)
193     (quote yum_repo)
194     (fedora_specfile pkg branch);
195
196   memory_set key "1"
197
198 and specfile_updated pkg =
199   let repodir = fedora_repo pkg branch in
200   let specfile = fedora_specfile pkg branch in
201
202   sh "
203     cd %s
204     rm -rf x86_64 noarch *.src.rpm .build* clog
205     git fetch
206   " repodir;
207
208   if not (git_has_local_changes repodir) then
209     sh "
210       cd %s
211       git pull --rebase
212     " repodir;
213
214   sh "sudo yum-builddep -y --disablerepo=\\* --enablerepo=%s %s"
215     (quote yum_repo) specfile;
216
217   (* For rationale behind always bumping the spec file, see comment
218    * in 'fedora.ml'.
219    *)
220   let title =
221     if not (file_contains_string specfile rebuild_name) then
222       rebuild_name ^ " rebuild."
223     else
224       "Bump release and rebuild." in
225   sh "rpmdev-bumpspec -c %s %s" (quote title) specfile;
226
227   (* XXX Automate common specfile fixes. *)
228
229   sh "
230     cd %s
231     echo 'Please make further changes as required to the spec file %s.spec'
232     echo '(Press return key)'
233     read
234     emacs -nw %s
235     echo 'OK to commit this change? (press ^C if not)'
236     read
237     fedpkg commit -c
238     echo 'OK to push this change? (press ^C if not)'
239     read
240     fedpkg push
241   " repodir
242     pkg
243     specfile