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