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