Prepare for OCaml 4.10.0 beta 1 rebuild.
[fedora-ocaml-rebuild.git] / Goalfile
1 # See README.
2
3 let fedora-dir = "%HOME/d/fedora"
4
5 let branch = "master"
6 let side-tag = "f32-build-side-18015"
7 let koji = "koji"
8 #let koji = "koji -p riscv64"
9 let fedpkg = "fedpkg"
10 #let fedpkg = "fedpkg --user-config %HOME/d/fedora-ocaml-rebuild/fedpkg-user-config"
11
12 # The magic string that must appear in %changelog when the
13 # package has been rebuilt.
14 let rebuild-name = "OCaml 4.10.0+beta1 rebuild."
15
16 # Packages that are blocked.  Any dependent packages are also blocked
17 # automatically.
18 # XXX Not implemented, use ignore for now.
19 #let blocked = [ "ocaml-camlp4" ]
20
21 # Packages that are ignored, which means they are treated as if
22 # they have been rebuilt.
23 let ignored = [ "ocaml-srpm-macros", "ocaml",
24     # These ones are only needed because blocked is not working
25     "ocaml-camlp4",
26     "cduce",
27     "guestfs-browser",
28     "ocaml-bin-prot",
29     "ocaml-bisect",
30     "ocaml-bitstring",
31     "ocaml-deriving",
32     "ocaml-json-static",
33     "ocaml-mikmatch",
34     "ocaml-openin",
35     "ocaml-pa-monad",
36     "ocaml-pgocaml",
37     "ocaml-sexplib",
38     "ocaml-type-conv",
39     "ocamldsort",
40 ]
41
42 # All OCaml-related source package names
43 let other-packages = [
44     "alt-ergo", "apron", "brltty", "coccinelle", "coq",
45     "frama-c", "gappalib-coq", "graphviz", "hevea", "hivex",
46     "libguestfs", "libnbd", "nbdkit", "opam", "plplot",
47     "virt-top", "virt-v2v", "why3", "z3",
48     # no OCaml code, but needs to be rebuilt after Coq
49     "flocq"
50 ]
51 pure function get-source-packages () returning strings = {
52     cd %fedora-dir
53     for f in ocaml* %other-packages; do
54         [ -f $f/%branch/$f.spec ] && echo "$f"
55     done
56 }
57 let source-packages = wrap ("*koji-built", get-source-packages ())
58
59 # Main goal: Rebuild all packages.
60 goal all = : source-packages ;
61
62 # Check if the source package has been built in Koji.
63 tactic *koji-built (pkg) = {
64     cd %fedora-dir/%pkg/%branch
65     koji=%koji
66     specfile=%pkg.spec
67
68     # Packages which are ignored are treated as if they were rebuilt already.
69     for p in %ignored; do
70         if [ %pkg = "$p" ]; then exit 0; fi
71     done
72
73     # If the specfile doesn't have the magic string then the
74     # package definitely needs to be rebuilt.
75     grep -sq %rebuild-name $specfile || exit 99
76
77     # Else we must check Koji itself.
78     # Koji sends some messages to stderr.
79     nvr=$(fedpkg verrel)
80     buildinfo=$($koji buildinfo $nvr 2>&1 ||:)
81
82     # No build at all, needs rebuild.
83     echo "$buildinfo" | grep -sq "No such build" && exit 99
84
85     # Exists a build, find out what state it is in.
86     state=$(echo "$buildinfo" | grep ^State: | awk '{print $2}')
87     taskid=$(echo "$buildinfo" | grep ^Task: | awk '{print $2}')
88
89     case "$state" in
90     COMPLETE)
91         # Complete so we don't need to rebuild.
92         exit 0 ;;
93     FAILED)
94         # Failed builds must be examined and fixed manually.
95         exit 1 ;;
96     BUILDING)
97         # Cancel the build, we will resubmit it.
98         $koji cancel $taskid ||:
99         exit 99 ;;
100     CANCELED|DELETED)
101         # Do a rebuild.
102         exit 99 ;;
103     esac
104     # Don't know what happened there, so fail.
105     exit 1
106 }
107
108 goal rebuild (pkg) =
109 *koji-built ("%pkg") : wrap ("*koji-built", source-dependencies (pkg)) {
110     cd %fedora-dir/%pkg/%branch
111     fedpkg=%fedpkg
112     koji=%koji
113     specfile=%pkg.spec
114
115     # We have to wait for the dependencies to become available
116     # before we can start the new build.
117     for p in %<; do
118         nvr=$($koji --quiet latest-build %side-tag $p | awk '{print $1}')
119         $koji wait-repo %side-tag --build=$nvr
120     done
121
122     # Make sure the local directory is up to date.
123     # This should also fail if there are local changes, which
124     # would need to be corrected/integrated by hand.
125     git pull
126
127     # If the specfile doesn't have the magic string then add
128     # that now.
129     if ! grep -sq %rebuild-name $specfile; then
130         rpmdev-bumpspec -c "- "%rebuild-name *.spec
131     else
132         rpmdev-bumpspec -c "- Bump release and rebuild." *.spec
133     fi
134     $fedpkg commit -c
135     $fedpkg push
136     $fedpkg build --target %side-tag
137 }
138
139 # Get the source package names for a particular package.
140 # Note this is not merely the BuildRequires, since those are
141 # the binary packages.  Also this will only find packages
142 # which are in the list of source-packages.
143 pure function source-dependencies (pkg) returning strings = @{
144     specfile=%fedora-dir/%pkg/%branch/%pkg.spec
145
146     echo Calculating dependencies of %pkg >&2
147
148     for r in $(rpmspec -q --buildrequires $specfile 2>/dev/null |
149                awk '{print $1}'); do
150         # Now we examine each *other* source package to see
151         # if any will create this dependency when they build.
152         for p in %source-packages; do
153             if [ "$p" != %pkg ] && \
154                  rpmspec -q --provides %fedora-dir/$p/%branch/$p.spec 2>/dev/null |
155                  awk '{print $1}' |
156                  grep -sq "^$r\$"
157              then
158                  echo "$p"
159             fi
160         done
161     done
162 }