Wait for dependencies to appear in the repo before building.
[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-999999"
7 let koji = "koji"
8
9 # The magic string that must appear in %changelog when the
10 # package has been rebuilt.
11 let rebuild-name = "OCaml 4.10.0 (beta 1)"
12
13 # Packages that are blocked.  Any dependent packages are also blocked
14 # automatically.
15 let blocked = [ "ocaml-camlp4" ]
16
17 # Packages that are ignored, which means they are treated as if
18 # they have been rebuilt.
19 let ignored = [ "ocaml-srpm-macros", "ocaml" ]
20
21 # All OCaml-related source package names
22 let other-packages = [
23     "alt-ergo", "apron", "brltty", "coccinelle", "coq",
24     "frama-c", "gappalib-coq", "graphviz", "hevea", "hivex",
25     "libguestfs", "opam", "plplot", "virt-top", "virt-v2v",
26     "why3", "z3",
27     "flocq" # no OCaml code, but needs to be rebuilt after Coq
28 ]
29 pure function get-source-packages () = {
30     cd %fedora-dir
31     echo '['
32     for f in ocaml* %other-packages; do
33         [ -f $f/%branch/$f.spec ] && echo "*built-in-koji(\"$f\"),"
34     done
35     echo ']'
36 }
37 let source-packages = get-source-packages ()
38
39 # Main goal: Rebuild all packages.
40 goal all = : source-packages ;
41
42 # Check if the source package has been built in Koji.
43 tactic *built-in-koji (pkg) = {
44     cd %fedora-dir/%pkg/%branch
45     specfile=%pkg.spec
46
47     # Packages which are ignored are treated as if they were rebuilt already.
48     for p in %ignored; do
49         if [ %pkg = "$p" ]; then exit 0; fi
50     done
51
52     # If the specfile doesn't have the magic string then the
53     # package definitely needs to be rebuilt.
54     grep -sq %rebuild-name $specfile || exit 99
55
56     # Else we must check Koji itself.
57     nvr=$(fedpkg verrel)
58     buildinfo=$(%koji buildinfo $nvr)
59
60     # No build at all, needs rebuild.
61     echo "$buildinfo" | grep -sq "No such build" && exit 99
62
63     # Exists a build, find out what state it is in.
64     state=$(echo "$buildinfo" | grep ^State: | awk '{print $2}')
65     taskid=$(echo "$buildinfo" | grep ^Task: | awk '{print $2}')
66
67     case "$state" in
68     COMPLETE)
69         # Complete so we don't need to rebuild.
70         exit 0 ;;
71     FAILED)
72         # Failed builds must be examined and fixed manually.
73         exit 1 ;;
74     BUILDING)
75         # Cancel the build, we will resubmit it.
76         %koji cancel $taskid
77         exit 99 ;;
78     CANCELED|DELETED)
79         # Do a rebuild.
80         exit 99 ;;
81     esac
82     # Don't know what happened there, so fail.
83     exit 1
84 }
85
86 goal rebuild (pkg) =
87 *built-in-koji ("%pkg") : source-dependencies (pkg) {
88     cd %fedora-dir/%pkg/%branch
89     specfile=%pkg.spec
90
91     # We have to wait for the dependencies to become available
92     # before we can start the new build.
93     for p in $(%koji latest-build %< | awk '{print $1}'); do
94         %koji --quiet wait-repo side-tag
95     done
96
97     # If the specfile doesn't have the magic string then add
98     # that now.
99     if ! grep -sq %rebuild-name $specfile; then
100         rpmdev-bumpspec -c "- "%rebuild-name *.spec
101     else
102         rpmdev-bumpspec -c "- Bump release and rebuild." *.spec
103     fi
104     fedpkg commit -c
105     fedpkg push
106     fedpkg build
107 }
108
109 # Get the source package names for a particular package.
110 # Note this is not merely the BuildRequires, since those are
111 # the binary packages.  Also this will only find packages
112 # which are in the list of source-packages.
113 pure function source-dependencies (pkg) = @{
114     specfile=%fedora-dir/%pkg/%branch/%pkg.spec
115
116     echo -n Dependencies of %pkg: >&2
117
118     echo '['
119     for r in $(rpmspec -q --buildrequires $specfile 2>/dev/null |
120                awk '{print $1}'); do
121         # Now we examine each *other* source package to see
122         # if any will create this dependency when they build.
123         for p in %source-packages; do
124             if [ "$p" != %pkg ] && \
125                  rpmspec -q --provides %fedora-dir/$p/%branch/$p.spec 2>/dev/null |
126                  awk '{print $1}' |
127                  grep -sq "^$r\$"
128              then
129                  echo "*built-in-koji(\"$p\"),"
130                  echo -n '' $p >&2
131             fi
132         done
133     done
134     echo ']'
135     echo >&2
136 }