Use new wrap() function.
[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-ocaml"
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.09.0 for riscv64"
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", "opam", "plplot", "virt-top", "virt-v2v",
47     "why3", "z3",
48     "flocq" # no OCaml code, but needs to be rebuilt after Coq
49 ]
50 pure function get-source-packages () returning strings = {
51     cd %fedora-dir
52     for f in ocaml* %other-packages; do
53         [ -f $f/%branch/$f.spec ] && echo "$f"
54     done
55 }
56 let source-packages = wrap ("*built-in-koji", get-source-packages ())
57
58 # Main goal: Rebuild all packages.
59 goal all = : source-packages ;
60
61 # Check if the source package has been built in Koji.
62 tactic *built-in-koji (pkg) = {
63     cd %fedora-dir/%pkg/%branch
64     koji=%koji
65     specfile=%pkg.spec
66
67     # Packages which are ignored are treated as if they were rebuilt already.
68     for p in %ignored; do
69         if [ %pkg = "$p" ]; then exit 0; fi
70     done
71
72     # If the specfile doesn't have the magic string then the
73     # package definitely needs to be rebuilt.
74     grep -sq %rebuild-name $specfile || exit 99
75
76     # Else we must check Koji itself.
77     # Koji sends some messages to stderr.
78     nvr=$(fedpkg verrel)
79     buildinfo=$($koji buildinfo $nvr 2>&1 ||:)
80
81     # No build at all, needs rebuild.
82     echo "$buildinfo" | grep -sq "No such build" && exit 99
83
84     # Exists a build, find out what state it is in.
85     state=$(echo "$buildinfo" | grep ^State: | awk '{print $2}')
86     taskid=$(echo "$buildinfo" | grep ^Task: | awk '{print $2}')
87
88     case "$state" in
89     COMPLETE)
90         # Complete so we don't need to rebuild.
91         exit 0 ;;
92     FAILED)
93         # Failed builds must be examined and fixed manually.
94         exit 1 ;;
95     BUILDING)
96         # Cancel the build, we will resubmit it.
97         $koji cancel $taskid ||:
98         exit 99 ;;
99     CANCELED|DELETED)
100         # Do a rebuild.
101         exit 99 ;;
102     esac
103     # Don't know what happened there, so fail.
104     exit 1
105 }
106
107 goal rebuild (pkg) =
108 *built-in-koji ("%pkg") : wrap ("*built-in-koji", source-dependencies (pkg)) {
109     cd %fedora-dir/%pkg/%branch
110     fedpkg=%fedpkg
111     koji=%koji
112     specfile=%pkg.spec
113
114     # We have to wait for the dependencies to become available
115     # before we can start the new build.
116     for p in %<; do
117         nvr=$($koji --quiet latest-build %side-tag $p | awk '{print $1}')
118         $koji wait-repo %side-tag --build=$nvr
119     done
120
121     # Make sure the local directory is up to date.
122     # This should also fail if there are local changes, which
123     # would need to be corrected/integrated by hand.
124     git pull
125
126     # If the specfile doesn't have the magic string then add
127     # that now.
128     if ! grep -sq %rebuild-name $specfile; then
129         rpmdev-bumpspec -c "- "%rebuild-name *.spec
130     else
131         rpmdev-bumpspec -c "- Bump release and rebuild." *.spec
132     fi
133     $fedpkg commit -c
134     $fedpkg push
135     $fedpkg build --target %side-tag
136 }
137
138 # Get the source package names for a particular package.
139 # Note this is not merely the BuildRequires, since those are
140 # the binary packages.  Also this will only find packages
141 # which are in the list of source-packages.
142 pure function source-dependencies (pkg) returning strings = @{
143     specfile=%fedora-dir/%pkg/%branch/%pkg.spec
144
145     echo Calculating dependencies of %pkg >&2
146
147     for r in $(rpmspec -q --buildrequires $specfile 2>/dev/null |
148                awk '{print $1}'); do
149         # Now we examine each *other* source package to see
150         # if any will create this dependency when they build.
151         for p in %source-packages; do
152             if [ "$p" != %pkg ] && \
153                  rpmspec -q --provides %fedora-dir/$p/%branch/$p.spec 2>/dev/null |
154                  awk '{print $1}' |
155                  grep -sq "^$r\$"
156              then
157                  echo "$p"
158             fi
159         done
160     done
161 }