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