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